main.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. /***************************************************************************
  2. *
  3. * MODULE: r.proj
  4. *
  5. * AUTHOR(S): Martin Schroeder
  6. * University of Heidelberg
  7. * Dept. of Geography
  8. * emes@geo0.geog.uni-heidelberg.de
  9. *
  10. * (With the help of a lot of existing GRASS sources, in
  11. * particular v.proj)
  12. *
  13. * PURPOSE: r.proj converts a map to a new geographic projection. It reads a
  14. * map from a different location, projects it and write it out
  15. * to the current location. The projected data is resampled with
  16. * one of three different methods: nearest neighbor, bilinear and
  17. * cubic convolution.
  18. *
  19. * COPYRIGHT: (C) 2001, 2011 by the GRASS Development Team
  20. *
  21. * This program is free software under the GNU General Public
  22. * License (>=v2). Read the file COPYING that comes with GRASS
  23. * for details.
  24. *
  25. * Changes
  26. * Morten Hulden <morten@untamo.net>, Aug 2000:
  27. * - aborts if input map is outside current location.
  28. * - can handle projections (conic, azimuthal etc) where
  29. * part of the map may fall into areas where south is
  30. * upward and east is leftward.
  31. * - avoids passing location edge coordinates to PROJ
  32. * (they may be invalid in some projections).
  33. * - output map will be clipped to borders of the current region.
  34. * - output map cell edges and centers will coinside with those
  35. * of the current region.
  36. * - output map resolution (unless changed explicitly) will
  37. * match (exactly) the resolution of the current region.
  38. * - if the input map is smaller than the current region, the
  39. * output map will only cover the overlapping area.
  40. * - if the input map is larger than the current region, only the
  41. * needed amount of memory will be allocated for the projection
  42. *
  43. * Bugfixes 20050328: added floor() before (int) typecasts to in avoid
  44. * assymetrical rounding errors. Added missing offset outcellhd.ew_res/2
  45. * to initial xcoord for each row in main projection loop (we want to project
  46. * center of cell, not border).
  47. *
  48. * Glynn Clements 2006: Use G_interp_* functions, modified
  49. * version of r.proj which uses a tile cache instead of loading the
  50. * entire map into memory.
  51. * Markus Metz 2010: lanczos and lanczos fallback interpolation methods
  52. *****************************************************************************/
  53. #include <stdio.h>
  54. #include <stdlib.h>
  55. #include <string.h>
  56. #include <unistd.h>
  57. #include <grass/gis.h>
  58. #include <grass/raster.h>
  59. #include <grass/gprojects.h>
  60. #include <grass/glocale.h>
  61. #include "r.proj.h"
  62. /* modify this table to add new methods */
  63. struct menu menu[] = {
  64. {p_nearest, "nearest", "nearest neighbor"},
  65. {p_bilinear, "linear", "linear interpolation"},
  66. {p_cubic, "cubic", "cubic convolution"},
  67. {p_lanczos, "lanczos", "lanczos filter"},
  68. {p_bilinear_f, "linear_f", "linear interpolation with fallback"},
  69. {p_cubic_f, "cubic_f", "cubic convolution with fallback"},
  70. {p_lanczos_f, "lanczos_f", "lanczos filter with fallback"},
  71. {NULL, NULL, NULL}
  72. };
  73. static char *make_ipol_list(void);
  74. static char *make_ipol_desc(void);
  75. int main(int argc, char **argv)
  76. {
  77. char *mapname, /* ptr to name of output layer */
  78. *setname, /* ptr to name of input mapset */
  79. *ipolname; /* name of interpolation method */
  80. int fdi, /* input map file descriptor */
  81. fdo, /* output map file descriptor */
  82. method, /* position of method in table */
  83. permissions, /* mapset permissions */
  84. cell_type, /* output celltype */
  85. cell_size, /* size of a cell in bytes */
  86. row, col, /* counters */
  87. irows, icols, /* original rows, cols */
  88. orows, ocols, have_colors, /* Input map has a colour table */
  89. overwrite, /* Overwrite */
  90. curr_proj; /* output projection (see gis.h) */
  91. void *obuffer; /* buffer that holds one output row */
  92. struct cache *ibuffer; /* buffer that holds the input map */
  93. func interpolate; /* interpolation routine */
  94. double xcoord2, /* temporary x coordinates */
  95. ycoord2, /* temporary y coordinates */
  96. onorth, osouth, /* save original border coords */
  97. oeast, owest, inorth, isouth, ieast, iwest;
  98. char north_str[30], south_str[30], east_str[30], west_str[30];
  99. struct Colors colr; /* Input map colour table */
  100. struct History history;
  101. struct pj_info iproj, /* input map proj parameters */
  102. oproj; /* output map proj parameters */
  103. struct Key_Value *in_proj_info, /* projection information of */
  104. *in_unit_info, /* input and output mapsets */
  105. *out_proj_info, *out_unit_info;
  106. struct GModule *module;
  107. struct Flag *list, /* list files in source location */
  108. *nocrop, /* don't crop output map */
  109. *print_bounds, /* print output bounds and exit */
  110. *gprint_bounds; /* same but print shell style */
  111. struct Option *imapset, /* name of input mapset */
  112. *inmap, /* name of input layer */
  113. *inlocation, /* name of input location */
  114. *outmap, /* name of output layer */
  115. *indbase, /* name of input database */
  116. *interpol, /* interpolation method:
  117. nearest neighbor, bilinear, cubic */
  118. *memory, /* amount of memory for cache */
  119. *res; /* resolution of target map */
  120. struct Cell_head incellhd, /* cell header of input map */
  121. outcellhd; /* and output map */
  122. G_gisinit(argv[0]);
  123. module = G_define_module();
  124. G_add_keyword(_("raster"));
  125. G_add_keyword(_("projection"));
  126. G_add_keyword(_("transformation"));
  127. module->description =
  128. _("Re-projects a raster map from given location to the current location.");
  129. inmap = G_define_standard_option(G_OPT_R_INPUT);
  130. inmap->description = _("Name of input raster map to re-project");
  131. inmap->required = NO;
  132. inmap->guisection = _("Source");
  133. inlocation = G_define_option();
  134. inlocation->key = "location";
  135. inlocation->type = TYPE_STRING;
  136. inlocation->required = YES;
  137. inlocation->description = _("Location containing input raster map");
  138. inlocation->gisprompt = "old,location,location";
  139. inlocation->key_desc = "name";
  140. imapset = G_define_standard_option(G_OPT_M_MAPSET);
  141. imapset->label = _("Mapset containing input raster map");
  142. imapset->description = _("default: name of current mapset");
  143. imapset->guisection = _("Source");
  144. indbase = G_define_option();
  145. indbase->key = "dbase";
  146. indbase->type = TYPE_STRING;
  147. indbase->required = NO;
  148. indbase->description = _("Path to GRASS database of input location");
  149. indbase->gisprompt = "old,dbase,dbase";
  150. indbase->key_desc = "path";
  151. indbase->guisection = _("Source");
  152. outmap = G_define_standard_option(G_OPT_R_OUTPUT);
  153. outmap->required = NO;
  154. outmap->description = _("Name for output raster map (default: same as 'input')");
  155. outmap->guisection = _("Target");
  156. ipolname = make_ipol_list();
  157. interpol = G_define_option();
  158. interpol->key = "method";
  159. interpol->type = TYPE_STRING;
  160. interpol->required = NO;
  161. interpol->answer = "nearest";
  162. interpol->options = ipolname;
  163. interpol->description = _("Interpolation method to use");
  164. interpol->guisection = _("Target");
  165. interpol->descriptions = make_ipol_desc();
  166. memory = G_define_option();
  167. memory->key = "memory";
  168. memory->type = TYPE_INTEGER;
  169. memory->required = NO;
  170. memory->description = _("Cache size (MiB)");
  171. res = G_define_option();
  172. res->key = "resolution";
  173. res->type = TYPE_DOUBLE;
  174. res->required = NO;
  175. res->description = _("Resolution of output raster map");
  176. res->guisection = _("Target");
  177. list = G_define_flag();
  178. list->key = 'l';
  179. list->description = _("List raster maps in input mapset and exit");
  180. list->guisection = _("Print");
  181. nocrop = G_define_flag();
  182. nocrop->key = 'n';
  183. nocrop->description = _("Do not perform region cropping optimization");
  184. print_bounds = G_define_flag();
  185. print_bounds->key = 'p';
  186. print_bounds->description =
  187. _("Print input map's bounds in the current projection and exit");
  188. print_bounds->guisection = _("Print");
  189. gprint_bounds = G_define_flag();
  190. gprint_bounds->key = 'g';
  191. gprint_bounds->description =
  192. _("Print input map's bounds in the current projection and exit (shell style)");
  193. gprint_bounds->guisection = _("Print");
  194. /* The parser checks if the map already exists in current mapset,
  195. we switch out the check and do it
  196. in the module after the parser */
  197. overwrite = G_check_overwrite(argc, argv);
  198. if (G_parser(argc, argv))
  199. exit(EXIT_FAILURE);
  200. /* get the method */
  201. for (method = 0; (ipolname = menu[method].name); method++)
  202. if (strcmp(ipolname, interpol->answer) == 0)
  203. break;
  204. if (!ipolname)
  205. G_fatal_error(_("<%s=%s> unknown %s"),
  206. interpol->key, interpol->answer, interpol->key);
  207. interpolate = menu[method].method;
  208. mapname = outmap->answer ? outmap->answer : inmap->answer;
  209. if (mapname && !list->answer && !overwrite &&
  210. !print_bounds->answer && !gprint_bounds->answer &&
  211. G_find_raster(mapname, G_mapset()))
  212. G_fatal_error(_("option <%s>: <%s> exists."), "output", mapname);
  213. setname = imapset->answer ? imapset->answer : G_store(G_mapset());
  214. if (strcmp(inlocation->answer, G_location()) == 0 &&
  215. (!indbase->answer || strcmp(indbase->answer, G_gisdbase()) == 0))
  216. #if 0
  217. G_fatal_error(_("Input and output locations can not be the same"));
  218. #else
  219. G_warning(_("Input and output locations are the same"));
  220. #endif
  221. G_get_window(&outcellhd);
  222. if(gprint_bounds->answer && !print_bounds->answer)
  223. print_bounds->answer = gprint_bounds->answer;
  224. curr_proj = G_projection();
  225. /* Get projection info for output mapset */
  226. if ((out_proj_info = G_get_projinfo()) == NULL)
  227. G_fatal_error(_("Unable to get projection info of output raster map"));
  228. if ((out_unit_info = G_get_projunits()) == NULL)
  229. G_fatal_error(_("Unable to get projection units of output raster map"));
  230. if (pj_get_kv(&oproj, out_proj_info, out_unit_info) < 0)
  231. G_fatal_error(_("Unable to get projection key values of output raster map"));
  232. /* Change the location */
  233. G__create_alt_env();
  234. G__setenv("GISDBASE", indbase->answer ? indbase->answer : G_gisdbase());
  235. G__setenv("LOCATION_NAME", inlocation->answer);
  236. permissions = G__mapset_permissions(setname);
  237. if (permissions < 0) /* can't access mapset */
  238. G_fatal_error(_("Mapset <%s> in input location <%s> - %s"),
  239. setname, inlocation->answer,
  240. permissions == 0 ? _("permission denied")
  241. : _("not found"));
  242. /* if requested, list the raster maps in source location - MN 5/2001 */
  243. if (list->answer) {
  244. int i;
  245. char **list;
  246. G_verbose_message(_("Checking location <%s> mapset <%s>"),
  247. inlocation->answer, setname);
  248. list = G_list(G_ELEMENT_RASTER, G__getenv("GISDBASE"),
  249. G__getenv("LOCATION_NAME"), setname);
  250. for (i = 0; list[i]; i++) {
  251. fprintf(stdout, "%s\n", list[i]);
  252. }
  253. fflush(stdout);
  254. exit(EXIT_SUCCESS); /* leave r.proj after listing */
  255. }
  256. if (!inmap->answer)
  257. G_fatal_error(_("Required parameter <%s> not set"), inmap->key);
  258. if (!G_find_raster(inmap->answer, setname))
  259. G_fatal_error(_("Raster map <%s> in location <%s> in mapset <%s> not found"),
  260. inmap->answer, inlocation->answer, setname);
  261. /* Read input map colour table */
  262. have_colors = Rast_read_colors(inmap->answer, setname, &colr);
  263. /* Get projection info for input mapset */
  264. if ((in_proj_info = G_get_projinfo()) == NULL)
  265. G_fatal_error(_("Unable to get projection info of input map"));
  266. if ((in_unit_info = G_get_projunits()) == NULL)
  267. G_fatal_error(_("Unable to get projection units of input map"));
  268. if (pj_get_kv(&iproj, in_proj_info, in_unit_info) < 0)
  269. G_fatal_error(_("Unable to get projection key values of input map"));
  270. G_free_key_value(in_proj_info);
  271. G_free_key_value(in_unit_info);
  272. G_free_key_value(out_proj_info);
  273. G_free_key_value(out_unit_info);
  274. if (G_verbose() > G_verbose_std())
  275. pj_print_proj_params(&iproj, &oproj);
  276. /* this call causes r.proj to read the entire map into memeory */
  277. Rast_get_cellhd(inmap->answer, setname, &incellhd);
  278. Rast_set_input_window(&incellhd);
  279. if (G_projection() == PROJECTION_XY)
  280. G_fatal_error(_("Unable to work with unprojected data (xy location)"));
  281. /* Save default borders so we can show them later */
  282. inorth = incellhd.north;
  283. isouth = incellhd.south;
  284. ieast = incellhd.east;
  285. iwest = incellhd.west;
  286. irows = incellhd.rows;
  287. icols = incellhd.cols;
  288. onorth = outcellhd.north;
  289. osouth = outcellhd.south;
  290. oeast = outcellhd.east;
  291. owest = outcellhd.west;
  292. orows = outcellhd.rows;
  293. ocols = outcellhd.cols;
  294. if (print_bounds->answer) {
  295. G_message(_("Input map <%s@%s> in location <%s>:"),
  296. inmap->answer, setname, inlocation->answer);
  297. outcellhd.north = -1e9;
  298. outcellhd.south = 1e9;
  299. outcellhd.east = -1e9;
  300. outcellhd.west = 1e9;
  301. bordwalk2(&incellhd, &outcellhd, &iproj, &oproj);
  302. inorth = outcellhd.north;
  303. isouth = outcellhd.south;
  304. ieast = outcellhd.east;
  305. iwest = outcellhd.west;
  306. G_format_northing(inorth, north_str, curr_proj);
  307. G_format_northing(isouth, south_str, curr_proj);
  308. G_format_easting(ieast, east_str, curr_proj);
  309. G_format_easting(iwest, west_str, curr_proj);
  310. if(gprint_bounds->answer) {
  311. fprintf(stdout, "n=%s s=%s w=%s e=%s rows=%d cols=%d\n",
  312. north_str, south_str, west_str, east_str, irows, icols);
  313. }
  314. else {
  315. fprintf(stdout, "Source cols: %d\n", icols);
  316. fprintf(stdout, "Source rows: %d\n", irows);
  317. fprintf(stdout, "Local north: %s\n", north_str);
  318. fprintf(stdout, "Local south: %s\n", south_str);
  319. fprintf(stdout, "Local west: %s\n", west_str);
  320. fprintf(stdout, "Local east: %s\n", east_str);
  321. }
  322. /* somehow approximate local ewres, nsres ?? (use 'g.region -m' on lat/lon side) */
  323. exit(EXIT_SUCCESS);
  324. }
  325. /* Cut non-overlapping parts of input map */
  326. if (!nocrop->answer)
  327. bordwalk(&outcellhd, &incellhd, &oproj, &iproj);
  328. /* Add 2 cells on each side for bilinear/cubic & future interpolation methods */
  329. /* (should probably be a factor based on input and output resolution) */
  330. incellhd.north += 2 * incellhd.ns_res;
  331. incellhd.east += 2 * incellhd.ew_res;
  332. incellhd.south -= 2 * incellhd.ns_res;
  333. incellhd.west -= 2 * incellhd.ew_res;
  334. if (incellhd.north > inorth)
  335. incellhd.north = inorth;
  336. if (incellhd.east > ieast)
  337. incellhd.east = ieast;
  338. if (incellhd.south < isouth)
  339. incellhd.south = isouth;
  340. if (incellhd.west < iwest)
  341. incellhd.west = iwest;
  342. Rast_set_input_window(&incellhd);
  343. /* And switch back to original location */
  344. G__switch_env();
  345. /* Adjust borders of output map */
  346. if (!nocrop->answer)
  347. bordwalk(&incellhd, &outcellhd, &iproj, &oproj);
  348. #if 0
  349. outcellhd.west = outcellhd.south = HUGE_VAL;
  350. outcellhd.east = outcellhd.north = -HUGE_VAL;
  351. for (row = 0; row < incellhd.rows; row++) {
  352. ycoord1 = Rast_row_to_northing((double)(row + 0.5), &incellhd);
  353. for (col = 0; col < incellhd.cols; col++) {
  354. xcoord1 = Rast_col_to_easting((double)(col + 0.5), &incellhd);
  355. pj_do_proj(&xcoord1, &ycoord1, &iproj, &oproj);
  356. if (xcoord1 > outcellhd.east)
  357. outcellhd.east = xcoord1;
  358. if (ycoord1 > outcellhd.north)
  359. outcellhd.north = ycoord1;
  360. if (xcoord1 < outcellhd.west)
  361. outcellhd.west = xcoord1;
  362. if (ycoord1 < outcellhd.south)
  363. outcellhd.south = ycoord1;
  364. }
  365. }
  366. #endif
  367. if (res->answer != NULL) /* set user defined resolution */
  368. outcellhd.ns_res = outcellhd.ew_res = atof(res->answer);
  369. G_adjust_Cell_head(&outcellhd, 0, 0);
  370. Rast_set_output_window(&outcellhd);
  371. G_message(" ");
  372. G_message(_("Input:"));
  373. G_message(_("Cols: %d (%d)"), incellhd.cols, icols);
  374. G_message(_("Rows: %d (%d)"), incellhd.rows, irows);
  375. G_message(_("North: %f (%f)"), incellhd.north, inorth);
  376. G_message(_("South: %f (%f)"), incellhd.south, isouth);
  377. G_message(_("West: %f (%f)"), incellhd.west, iwest);
  378. G_message(_("East: %f (%f)"), incellhd.east, ieast);
  379. G_message(_("EW-res: %f"), incellhd.ew_res);
  380. G_message(_("NS-res: %f"), incellhd.ns_res);
  381. G_message(" ");
  382. G_message(_("Output:"));
  383. G_message(_("Cols: %d (%d)"), outcellhd.cols, ocols);
  384. G_message(_("Rows: %d (%d)"), outcellhd.rows, orows);
  385. G_message(_("North: %f (%f)"), outcellhd.north, onorth);
  386. G_message(_("South: %f (%f)"), outcellhd.south, osouth);
  387. G_message(_("West: %f (%f)"), outcellhd.west, owest);
  388. G_message(_("East: %f (%f)"), outcellhd.east, oeast);
  389. G_message(_("EW-res: %f"), outcellhd.ew_res);
  390. G_message(_("NS-res: %f"), outcellhd.ns_res);
  391. G_message(" ");
  392. /* open and read the relevant parts of the input map and close it */
  393. G__switch_env();
  394. Rast_set_input_window(&incellhd);
  395. fdi = Rast_open_old(inmap->answer, setname);
  396. cell_type = Rast_get_map_type(fdi);
  397. ibuffer = readcell(fdi, memory->answer);
  398. Rast_close(fdi);
  399. G__switch_env();
  400. Rast_set_output_window(&outcellhd);
  401. if (strcmp(interpol->answer, "nearest") == 0) {
  402. fdo = Rast_open_new(mapname, cell_type);
  403. obuffer = (CELL *) Rast_allocate_output_buf(cell_type);
  404. }
  405. else {
  406. fdo = Rast_open_fp_new(mapname);
  407. cell_type = FCELL_TYPE;
  408. obuffer = (FCELL *) Rast_allocate_output_buf(cell_type);
  409. }
  410. cell_size = Rast_cell_size(cell_type);
  411. xcoord2 = outcellhd.west + (outcellhd.ew_res / 2);
  412. ycoord2 = outcellhd.north - (outcellhd.ns_res / 2);
  413. G_important_message(_("Projecting..."));
  414. G_percent(0, outcellhd.rows, 2);
  415. for (row = 0; row < outcellhd.rows; row++) {
  416. /* obufptr = obuffer */;
  417. #if 0
  418. /* parallelization does not always work,
  419. * segfaults in the interpolation functions
  420. * can happen */
  421. #pragma omp parallel for schedule (static)
  422. #endif
  423. for (col = 0; col < outcellhd.cols; col++) {
  424. void *obufptr = (void *)((const unsigned char *)obuffer + col * cell_size);
  425. double xcoord1 = xcoord2 + (col) * outcellhd.ew_res;
  426. double ycoord1 = ycoord2;
  427. /* project coordinates in output matrix to */
  428. /* coordinates in input matrix */
  429. if (pj_do_proj(&xcoord1, &ycoord1, &oproj, &iproj) < 0)
  430. Rast_set_null_value(obufptr, 1, cell_type);
  431. else {
  432. /* convert to row/column indices of input matrix */
  433. /* column index in input matrix */
  434. double col_idx = (xcoord1 - incellhd.west) / incellhd.ew_res;
  435. /* row index in input matrix */
  436. double row_idx = (incellhd.north - ycoord1) / incellhd.ns_res;
  437. /* and resample data point */
  438. interpolate(ibuffer, obufptr, cell_type,
  439. col_idx, row_idx, &incellhd);
  440. }
  441. /* obufptr = G_incr_void_ptr(obufptr, cell_size); */
  442. }
  443. Rast_put_row(fdo, obuffer, cell_type);
  444. xcoord2 = outcellhd.west + (outcellhd.ew_res / 2);
  445. ycoord2 -= outcellhd.ns_res;
  446. G_percent(row, outcellhd.rows - 1, 2);
  447. }
  448. Rast_close(fdo);
  449. release_cache(ibuffer);
  450. if (have_colors > 0) {
  451. Rast_write_colors(mapname, G_mapset(), &colr);
  452. Rast_free_colors(&colr);
  453. }
  454. Rast_short_history(mapname, "raster", &history);
  455. Rast_command_history(&history);
  456. Rast_write_history(mapname, &history);
  457. G_done_msg(NULL);
  458. exit(EXIT_SUCCESS);
  459. }
  460. char *make_ipol_list(void)
  461. {
  462. int size = 0;
  463. int i;
  464. char *buf;
  465. for (i = 0; menu[i].name; i++)
  466. size += strlen(menu[i].name) + 1;
  467. buf = G_malloc(size);
  468. *buf = '\0';
  469. for (i = 0; menu[i].name; i++) {
  470. if (i)
  471. strcat(buf, ",");
  472. strcat(buf, menu[i].name);
  473. }
  474. return buf;
  475. }
  476. char *make_ipol_desc(void)
  477. {
  478. int size = 0;
  479. int i;
  480. char *buf;
  481. for (i = 0; menu[i].name; i++)
  482. size += strlen(menu[i].name) + strlen(menu[i].text) + 2;
  483. buf = G_malloc(size);
  484. *buf = '\0';
  485. for (i = 0; menu[i].name; i++) {
  486. if (i)
  487. strcat(buf, ";");
  488. strcat(buf, menu[i].name);
  489. strcat(buf, ";");
  490. strcat(buf, menu[i].text);
  491. }
  492. return buf;
  493. }