header.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783
  1. /*!
  2. \file lib/vector/Vlib/header.c
  3. \brief Vector library - header manipulation
  4. Higher level functions for reading/writing/manipulating vectors.
  5. (C) 2001-2010 by the GRASS Development Team
  6. This program is free software under the GNU General Public License
  7. (>=v2). Read the file COPYING that comes with GRASS for details.
  8. \author Original author CERL, probably Dave Gerdes or Mike Higgins.
  9. \author Update to GRASS 5.7 Radim Blazek and David D. Gray.
  10. \author Update to GRASS 7 (OGR support) by Martin Landa <landa.martin gmail.com>
  11. */
  12. #include <stdlib.h>
  13. #include <string.h>
  14. #include <grass/vector.h>
  15. #include <grass/glocale.h>
  16. static int lookup(const char *file, const char *key, char *value, size_t len);
  17. /*!
  18. \brief Print vector map header to stdout
  19. \param Map pointer to Map_info structure
  20. \return 0 on success
  21. */
  22. int Vect_print_header(const struct Map_info *Map)
  23. {
  24. fprintf(stdout, "\nSelected information from dig header\n");
  25. fprintf(stdout, " Organization: %s\n", Vect_get_organization(Map));
  26. fprintf(stdout, " Map Name: %s\n", Vect_get_map_name(Map));
  27. fprintf(stdout, " Source Date: %s\n", Vect_get_map_date(Map));
  28. fprintf(stdout, " Orig. Scale: %d\n", Vect_get_scale(Map));
  29. return 0;
  30. }
  31. /*!
  32. \brief Read vector map header from map head file
  33. \param Map pointrt to Map_info structure
  34. \return 0
  35. */
  36. int Vect_read_header(struct Map_info *Map)
  37. {
  38. Vect__read_head(Map);
  39. return 0;
  40. }
  41. /*!
  42. \brief Write vector map header to map head file
  43. \param Map pointer to Map_info structure
  44. \return 0
  45. */
  46. int Vect_write_header(const struct Map_info *Map)
  47. {
  48. /* do some sanity checking here */
  49. Vect__write_head(Map);
  50. return 0;
  51. }
  52. /*!
  53. \brief Writes head information to text file (GV_HEAD_ELEMENT)
  54. \param Map pointer to Map_info structure
  55. \return 0 on success
  56. \return -1 on error
  57. */
  58. int Vect__write_head(const struct Map_info *Map)
  59. {
  60. char buf[GPATH_MAX];
  61. FILE *head_fp;
  62. sprintf(buf, "%s/%s", GV_DIRECTORY, Map->name);
  63. head_fp = G_fopen_new(buf, GV_HEAD_ELEMENT);
  64. if (head_fp == NULL) {
  65. G_warning(_("Unable to open header file of vector <%s>"),
  66. Vect_get_full_name(Map));
  67. return -1;
  68. }
  69. fprintf(head_fp, "ORGANIZATION: %s\n", Vect_get_organization(Map));
  70. fprintf(head_fp, "DIGIT DATE: %s\n", Vect_get_date(Map));
  71. fprintf(head_fp, "DIGIT NAME: %s\n", Vect_get_person(Map));
  72. fprintf(head_fp, "MAP NAME: %s\n", Vect_get_map_name(Map));
  73. fprintf(head_fp, "MAP DATE: %s\n", Vect_get_map_date(Map));
  74. fprintf(head_fp, "MAP SCALE: %d\n", Vect_get_scale(Map));
  75. fprintf(head_fp, "OTHER INFO: %s\n", Vect_get_comment(Map));
  76. if (Vect_get_proj(Map) > 0)
  77. fprintf(head_fp, "PROJ: %d\n", Vect_get_proj(Map));
  78. fprintf(head_fp, "ZONE: %d\n", Vect_get_zone(Map));
  79. fprintf(head_fp, "MAP THRESH: %f\n", Vect_get_thresh(Map));
  80. fclose(head_fp);
  81. return (0);
  82. }
  83. /*!
  84. \brief Reads head information from text file (GV_HEAD_ELEMENT) - for internal use only
  85. \param Map pointer to Map_info structure
  86. \return 0 on success
  87. \return -1 on error
  88. */
  89. int Vect__read_head(struct Map_info *Map)
  90. {
  91. FILE *head_fp;
  92. char buff[GPATH_MAX];
  93. char *ptr;
  94. /* Reset / init */
  95. Vect_set_organization(Map, "");
  96. Vect_set_date(Map, "");
  97. Vect_set_person(Map, "");
  98. Vect_set_map_name(Map, "");
  99. Vect_set_map_date(Map, "");
  100. Vect_set_scale(Map, 1);
  101. Vect_set_comment(Map, "");
  102. Vect_set_zone(Map, -1);
  103. Vect_set_thresh(Map, 0.);
  104. G_debug(1, "Vect__read_head(): vector = %s@%s", Map->name, Map->mapset);
  105. sprintf(buff, "%s/%s", GV_DIRECTORY, Map->name);
  106. head_fp = G_fopen_old(buff, GV_HEAD_ELEMENT, Map->mapset);
  107. if (head_fp == NULL) {
  108. G_warning(_("Unable to open header file of vector <%s>"),
  109. Vect_get_full_name(Map));
  110. return -1;
  111. }
  112. while (G_getl2(buff, 2000, head_fp)) {
  113. if (!(ptr = strchr(buff, ':'))) {
  114. G_warning(_("Corrupted row in head: %s"), buff);
  115. continue;
  116. }
  117. ptr++; /* Search for the start of text */
  118. while (*ptr == ' ')
  119. ptr++;
  120. if (strncmp(buff, "ORGANIZATION:", sizeof(char) * 12) == 0)
  121. Vect_set_organization(Map, ptr);
  122. else if (strncmp(buff, "DIGIT DATE:", sizeof(char) * 11) == 0)
  123. Vect_set_date(Map, ptr);
  124. else if (strncmp(buff, "DIGIT NAME:", sizeof(char) * 11) == 0)
  125. Vect_set_person(Map, ptr);
  126. else if (strncmp(buff, "MAP NAME:", sizeof(char) * 9) == 0)
  127. Vect_set_map_name(Map, ptr);
  128. else if (strncmp(buff, "MAP DATE:", sizeof(char) * 9) == 0)
  129. Vect_set_map_date(Map, ptr);
  130. else if (strncmp(buff, "MAP SCALE:", sizeof(char) * 10) == 0)
  131. Vect_set_scale(Map, atoi(ptr));
  132. else if (strncmp(buff, "OTHER INFO:", sizeof(char) * 11) == 0)
  133. Vect_set_comment(Map, ptr);
  134. else if (strncmp(buff, "PROJ:", sizeof(char) * 5) == 0)
  135. Vect_set_proj(Map, atoi(ptr));
  136. else if (strncmp(buff, "ZONE:", sizeof(char) * 5) == 0 ||
  137. strncmp(buff, "UTM ZONE:", sizeof(char) * 9) == 0)
  138. Vect_set_zone(Map, atoi(ptr));
  139. else if (strncmp(buff, "WEST EDGE:", sizeof(char) * 10) == 0) {
  140. }
  141. else if (strncmp(buff, "EAST EDGE:", sizeof(char) * 10) == 0) {
  142. }
  143. else if (strncmp(buff, "SOUTH EDGE:", sizeof(char) * 11) == 0) {
  144. }
  145. else if (strncmp(buff, "NORTH EDGE:", sizeof(char) * 11) == 0) {
  146. }
  147. else if (strncmp(buff, "MAP THRESH:", sizeof(char) * 11) == 0)
  148. Vect_set_thresh(Map, atof(ptr));
  149. else
  150. G_warning(_("Unknown keyword '%s' in vector head"), buff);
  151. }
  152. fclose(head_fp);
  153. return 0;
  154. }
  155. /*!
  156. \brief Get name of vector map
  157. \param Map pointer to Map_info structure
  158. \return string containing name
  159. */
  160. const char *Vect_get_name(const struct Map_info *Map)
  161. {
  162. return Map->name;
  163. }
  164. /*!
  165. \brief Get name of mapset where vector map lives
  166. \param Map pointer to Map_info structure
  167. \return string containing mapset name
  168. */
  169. const char *Vect_get_mapset(const struct Map_info *Map)
  170. {
  171. return Map->mapset;
  172. }
  173. /*!
  174. \brief Get fully qualified name of vector map
  175. - for GV_FORMAT_NATIVE and GV_FORMAT_OGR returns "map@mapset"
  176. - for GV_FORMAT_OGR_DIRECT returns "layer@datasourse"
  177. Allocated string should be freed by G_free().
  178. \param Map pointer to Map_info structure
  179. \return allocated string "name@mapset"
  180. */
  181. const char *Vect_get_full_name(const struct Map_info *Map)
  182. {
  183. char *ptr;
  184. if (Map->format == GV_FORMAT_OGR_DIRECT &&
  185. Map->fInfo.ogr.dsn &&
  186. Map->fInfo.ogr.layer_name) {
  187. ptr = (char *) G_malloc(strlen(Map->fInfo.ogr.layer_name) +
  188. strlen(Map->fInfo.ogr.dsn) + 2);
  189. sprintf(ptr, "%s@%s", Map->fInfo.ogr.layer_name,
  190. Map->fInfo.ogr.dsn);
  191. return ptr;
  192. }
  193. ptr = (char *) G_malloc(strlen(Map->name) + strlen(Map->mapset) + 2);
  194. if (strlen(Map->mapset) > 0) {
  195. sprintf(ptr, "%s@%s", Map->name, Map->mapset);
  196. }
  197. else {
  198. sprintf(ptr, "%s", Map->name);
  199. }
  200. return ptr;
  201. }
  202. /*!
  203. \brief Get datasource name (relevant only for non-native formats)
  204. Returns:
  205. - datasource name for OGR format (GV_FORMAT_OGR and GV_FORMAT_OGR_DIRECT)
  206. - database name for PostGIS format (GV_FORMAT_POSTGIS)
  207. \param Map pointer to Map_info structure
  208. \return string containing OGR/PostGIS datasource name
  209. \return NULL on error (map format is native)
  210. */
  211. const char *Vect_get_finfo_dsn_name(const struct Map_info *Map)
  212. {
  213. if (Map->format == GV_FORMAT_OGR ||
  214. Map->format == GV_FORMAT_OGR_DIRECT) {
  215. #ifndef HAVE_OGR
  216. G_warning(_("GRASS is not compiled with OGR support"));
  217. #endif
  218. return Map->fInfo.ogr.dsn;
  219. }
  220. else if (Map->format == GV_FORMAT_POSTGIS) {
  221. #ifndef HAVE_POSTGRES
  222. G_warning(_("GRASS is not compiled with PostgreSQL support"));
  223. #endif
  224. return Map->fInfo.pg.db_name;
  225. }
  226. G_warning(_("Native vector format detected for <%s>"),
  227. Vect_get_full_name(Map));
  228. return NULL;
  229. }
  230. /*!
  231. \brief Get layer name (relevant only for non-native formats)
  232. Returns:
  233. - layer name for OGR format (GV_FORMAT_OGR and GV_FORMAT_OGR_DIRECT)
  234. - table name for PostGIS format (GV_FORMAT_POSTGIS)
  235. \param Map pointer to Map_info structure
  236. \return string containing layer name
  237. \return NULL on error (map format is native)
  238. */
  239. const char *Vect_get_finfo_layer_name(const struct Map_info *Map)
  240. {
  241. if (Map->format == GV_FORMAT_OGR ||
  242. Map->format == GV_FORMAT_OGR_DIRECT) {
  243. #ifndef HAVE_OGR
  244. G_warning(_("GRASS is not compiled with OGR support"));
  245. #endif
  246. return Map->fInfo.ogr.layer_name;
  247. }
  248. else if (Map->format == GV_FORMAT_POSTGIS) {
  249. #ifndef HAVE_POSTGRES
  250. G_warning(_("GRASS is not compiled with PostgreSQL support"));
  251. #endif
  252. return Map->fInfo.pg.table_name;
  253. }
  254. G_warning(_("Native vector format detected for <%s>"),
  255. Vect_get_full_name(Map));
  256. return NULL;
  257. }
  258. /*!
  259. \brief Get format info (relevant only for non-native formats)
  260. Allocated space should be freed by G_free().
  261. Returns:
  262. - layer name for OGR format (GV_FORMAT_OGR and GV_FORMAT_OGR_DIRECT)
  263. \param Map pointer to Map_info structure
  264. \return string containing name of OGR format (allocated by G_store())
  265. \return NULL on error (or on missing OGR support)
  266. */
  267. const char *Vect_get_finfo_format_info(const struct Map_info *Map)
  268. {
  269. char format[GPATH_MAX];
  270. if (Map->format == GV_FORMAT_OGR ||
  271. Map->format == GV_FORMAT_OGR_DIRECT) {
  272. #ifndef HAVE_OGR
  273. G_warning(_("GRASS is not compiled with OGR support"));
  274. #else
  275. if (!Map->fInfo.ogr.ds)
  276. return NULL;
  277. sprintf(format, "%s/%s", "OGR",
  278. OGR_Dr_GetName(OGR_DS_GetDriver(Map->fInfo.ogr.ds)));
  279. return G_store(format);
  280. #endif
  281. }
  282. else if (Map->format == GV_FORMAT_POSTGIS) {
  283. #ifndef HAVE_OGR
  284. G_warning(_("GRASS is not compiled with PostgreSQL support"));
  285. #else
  286. return G_store("PostGIS");
  287. #endif
  288. }
  289. return NULL;
  290. }
  291. /*!
  292. \brief Get geometry type (relevant only for non-native formats)
  293. Note: All inner spaces are removed, function returns feature type in
  294. lowercase.
  295. \param Map pointer to Map_info structure
  296. \return allocated string containing geometry type info
  297. (point, linestring, polygon, ...)
  298. \return NULL on error (map format is native)
  299. */
  300. const char *Vect_get_finfo_geometry_type(const struct Map_info *Map)
  301. {
  302. char *ftype, *ftype_tmp;
  303. ftype_tmp = ftype = NULL;
  304. if (Map->format == GV_FORMAT_OGR ||
  305. Map->format == GV_FORMAT_OGR_DIRECT) {
  306. #ifndef HAVE_OGR
  307. G_warning(_("GRASS is not compiled with OGR support"));
  308. #else
  309. OGRwkbGeometryType Ogr_geom_type;
  310. OGRFeatureDefnH Ogr_feature_defn;
  311. if (!Map->fInfo.ogr.layer)
  312. return NULL;
  313. Ogr_feature_defn = OGR_L_GetLayerDefn(Map->fInfo.ogr.layer);
  314. Ogr_geom_type = wkbFlatten(OGR_FD_GetGeomType(Ogr_feature_defn));
  315. ftype_tmp = G_store(OGRGeometryTypeToName(Ogr_geom_type));
  316. #endif
  317. }
  318. else if (Map->format == GV_FORMAT_POSTGIS) {
  319. #ifndef HAVE_POSTGRES
  320. G_warning(_("GRASS is not compiled with PostgreSQL support"));
  321. #else
  322. char stmt[DB_SQL_MAX];
  323. const struct Format_info_pg *pg_info;
  324. PGresult *res;
  325. pg_info = &(Map->fInfo.pg);
  326. sprintf(stmt, "SELECT type FROM geometry_columns "
  327. "WHERE f_table_name = '%s'", pg_info->table_name);
  328. G_debug(2, "SQL: %s", stmt);
  329. res = PQexec(pg_info->conn, stmt);
  330. if (!res || PQresultStatus(res) != PGRES_TUPLES_OK ||
  331. PQntuples(res) != 1)
  332. G_warning("%s\n%s", _("Unable to get feature type."),
  333. PQresultErrorMessage(res));
  334. ftype_tmp = G_store(PQgetvalue(res, 0, 0));
  335. PQclear(res);
  336. #endif
  337. }
  338. if (!ftype_tmp)
  339. return NULL;
  340. ftype = G_str_replace(ftype_tmp, " ", "");
  341. G_free(ftype_tmp);
  342. G_str_to_lower(ftype);
  343. return ftype;
  344. }
  345. /*!
  346. \brief Check if vector map is 3D
  347. Check vector map header.
  348. \param Map pointer to Map_info structure
  349. \return TRUE vector map is 3D
  350. \return FALSE vector map is not 3D
  351. */
  352. int Vect_is_3d(const struct Map_info *Map)
  353. {
  354. return Map->head.with_z;
  355. }
  356. /*!
  357. \brief Set organization string in map header
  358. \param Map pointer to Map_info structure
  359. \param str organization name
  360. \return 0
  361. */
  362. int Vect_set_organization(struct Map_info *Map, const char *str)
  363. {
  364. G_free(Map->head.organization);
  365. Map->head.organization = G_store(str);
  366. return 0;
  367. }
  368. /*!
  369. \brief Get organization string from map header
  370. \param Map pointer to Map_info structure
  371. \return string containing organization name
  372. */
  373. const char *Vect_get_organization(const struct Map_info *Map)
  374. {
  375. return Map->head.organization;
  376. }
  377. /*!
  378. \brief Set date of digitization in map header
  379. \todo This should be coupled to DateTime functions to support
  380. time series
  381. \param Map pointer to Map_info structure
  382. \param str date given as string
  383. \return 0
  384. */
  385. int Vect_set_date(struct Map_info *Map, const char *str)
  386. {
  387. G_free(Map->head.date);
  388. Map->head.date = G_store(str);
  389. return 0;
  390. }
  391. /*!
  392. \brief Get date of digitization from map header
  393. \param Map pointer to Map_info structure
  394. \return date of digitization string
  395. */
  396. const char *Vect_get_date(const struct Map_info *Map)
  397. {
  398. return (Map->head.date);
  399. }
  400. /*!
  401. \brief Set name of user who digitized the map in map header
  402. \param Map pointer to Map_info structure
  403. \param str user name
  404. \return 0
  405. */
  406. int Vect_set_person(struct Map_info *Map, const char *str)
  407. {
  408. G_free(Map->head.user_name);
  409. Map->head.user_name = G_store(str);
  410. return 0;
  411. }
  412. /*!
  413. \brief Get user name string who digitized the map from map header
  414. \param Map pointer to Map_info structure
  415. \return string containing user name
  416. */
  417. const char *Vect_get_person(const struct Map_info *Map)
  418. {
  419. return (Map->head.user_name);
  420. }
  421. /*!
  422. \brief Set map name in map header
  423. \param Map pointer to Map_info structure
  424. \param str map name to be set
  425. \return 0
  426. */
  427. int Vect_set_map_name(struct Map_info *Map, const char *str)
  428. {
  429. G_free(Map->head.map_name);
  430. Map->head.map_name = G_store(str);
  431. return 0;
  432. }
  433. /*!
  434. \brief Get map name from map header
  435. \param Map pointer to Map_info structure
  436. \return string containing map name
  437. */
  438. const char *Vect_get_map_name(const struct Map_info *Map)
  439. {
  440. return Map->head.map_name;
  441. }
  442. /*!
  443. \brief Set date when the source map was originally produced in map header
  444. \param Map pointer to Map_info structure
  445. \param str date given as a string
  446. \return 0
  447. */
  448. int Vect_set_map_date(struct Map_info *Map, const char *str)
  449. {
  450. G_free(Map->head.source_date);
  451. Map->head.source_date = G_store(str);
  452. return 0;
  453. }
  454. /*!
  455. \brief Get date when the source map was originally produced from map header
  456. \param Map pointer to Map_info structure
  457. \return string containg a date
  458. */
  459. const char *Vect_get_map_date(const struct Map_info *Map)
  460. {
  461. return Map->head.source_date;
  462. }
  463. /*!
  464. \brief Set map scale in map header
  465. \param Map pointer to Map_info structure
  466. \param scale map scale
  467. \return 0
  468. */
  469. int Vect_set_scale(struct Map_info *Map, int scale)
  470. {
  471. Map->head.orig_scale = scale;
  472. return 0;
  473. }
  474. /*!
  475. \brief Get map scale from map header
  476. \param Map pointer to Map_info structure
  477. \return map scale
  478. */
  479. int Vect_get_scale(const struct Map_info *Map)
  480. {
  481. return (int) Map->head.orig_scale;
  482. }
  483. /*!
  484. \brief Set comment or other info string in map header
  485. \param Map pointer to Map_info structure
  486. \param str comment or other info string
  487. \return 0
  488. */
  489. int Vect_set_comment(struct Map_info *Map, const char *str)
  490. {
  491. G_free(Map->head.comment);
  492. Map->head.comment = G_store(str);
  493. return 0;
  494. }
  495. /*!
  496. \brief Get comment or other info string from map header
  497. \param Map pointer to Map_info structure
  498. \return comment or other info string
  499. */
  500. const char *Vect_get_comment(const struct Map_info *Map)
  501. {
  502. return (Map->head.comment);
  503. }
  504. /*!
  505. \brief Set projection zone in map header
  506. \param Map pointer to Map_info structure
  507. \param zone projection zone
  508. \return 0
  509. */
  510. int Vect_set_zone(struct Map_info *Map, int zone)
  511. {
  512. Map->head.plani_zone = zone;
  513. return 0;
  514. }
  515. /*!
  516. \brief Get projection zone from map header
  517. \param Map pointer to Map_info structure
  518. \return projection zone
  519. */
  520. int Vect_get_zone(const struct Map_info *Map)
  521. {
  522. return Map->head.plani_zone;
  523. }
  524. /*!
  525. \brief Set projection in map header
  526. Supported projections:
  527. - PROJECTION_XY 0 - x,y (Raw imagery),
  528. - PROJECTION_UTM 1 - UTM Universal Transverse Mercator,
  529. - PROJECTION_SP 2 - State Plane (in feet),
  530. - PROJECTION_LL 3 - Latitude-Longitude
  531. \param Map pointer to Map_info structure
  532. \param proj projection code
  533. \return 0
  534. */
  535. int Vect_set_proj(struct Map_info *Map, int proj)
  536. {
  537. Map->head.proj = proj;
  538. return 0;
  539. }
  540. /*!
  541. \brief Get projection from map header
  542. \param Map pointer to Map_info structure
  543. \return PROJECTION_XY 0 - x,y (Raw imagery),
  544. \return PROJECTION_UTM 1 - UTM Universal Transverse Mercator,
  545. \return PROJECTION_SP 2 - State Plane (in feet),
  546. \return PROJECTION_LL 3 - Latitude-Longitude
  547. */
  548. int Vect_get_proj(const struct Map_info *Map)
  549. {
  550. return (Map->head.proj);
  551. }
  552. /*!
  553. \brief Query cartographic projection name of pointer to Map_info structure
  554. Returns a pointer to a string which is a printable name for
  555. projection code <em>proj</em> (as returned by Vect_get_proj()).
  556. \param Map pointer to Map_info structure
  557. \return allocated string containing projection name
  558. \return NULL if <em>proj</em> is not a valid projection
  559. */
  560. const char *Vect_get_proj_name(const struct Map_info *Map)
  561. {
  562. char name[256];
  563. int n;
  564. switch (n = Vect_get_proj(Map)) {
  565. case PROJECTION_XY:
  566. case PROJECTION_UTM:
  567. case PROJECTION_LL:
  568. case PROJECTION_SP:
  569. return G__projection_name(n);
  570. case PROJECTION_OTHER:
  571. /* this won't protect against differing "other" projections, so
  572. better to just include P_OTHER in the above list so we return the
  573. strictly more correct, but less nice, string: "Other projection" ? */
  574. return G_database_projection_name();
  575. default:
  576. G_debug(1, "Vect_get_proj_name(): "
  577. "Vect_get_proj() returned an invalid result (%d)", n);
  578. break;
  579. }
  580. strcpy(name, _("Unknown projection"));
  581. return G_store(name);
  582. }
  583. /*!
  584. \brief Set threshold used for digitization in map header
  585. \param Map pointer to Map_info structure
  586. \param thresh threshold used for digitization
  587. \return 0
  588. */
  589. int Vect_set_thresh(struct Map_info *Map, double thresh)
  590. {
  591. G_debug(1, "Vect_set_thresh(): thresh = %f", thresh);
  592. Map->head.digit_thresh = thresh;
  593. return 0;
  594. }
  595. /*!
  596. \brief Get threshold used for digitization from map header
  597. \param Map pointer to Map_info structure
  598. \return threshold used for digitization
  599. */
  600. double Vect_get_thresh(const struct Map_info *Map)
  601. {
  602. G_debug(1, "Vect_get_thresh(): thresh = %f", Map->head.digit_thresh);
  603. return Map->head.digit_thresh;
  604. }
  605. /* from lib/gis/proj3.c */
  606. static int lookup(const char *file, const char *key, char *value, size_t len)
  607. {
  608. char path[GPATH_MAX];
  609. G_file_name(path, "", file, "PERMANENT");
  610. return G_lookup_key_value_from_file(path, key, value, (int) len) == 1;
  611. }