00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <stdlib.h>
00019 #include <string.h>
00020 #include "gis.h"
00021 #include "Vect.h"
00022
00029 int
00030 Vect_print_header (struct Map_info *Map)
00031 {
00032 fprintf (stdout, "\nSelected information from dig header\n");
00033 fprintf (stdout, " Organization: %s\n", Vect_get_organization(Map) );
00034 fprintf (stdout, " Map Name: %s\n", Vect_get_map_name(Map) );
00035 fprintf (stdout, " Source Date: %s\n", Vect_get_map_date(Map) );
00036 fprintf (stdout, " Orig. Scale: %d\n", Vect_get_scale(Map) );
00037
00038 return 0;
00039 }
00040
00041
00042
00043
00044
00045 int
00046 Vect__write_head (struct Map_info *Map)
00047 {
00048 char buf[200];
00049 FILE *head_fp;
00050
00051 sprintf (buf, "%s/%s", GRASS_VECT_DIRECTORY, Map->name);
00052
00053 head_fp = G_fopen_new (buf, GRASS_VECT_HEAD_ELEMENT);
00054 if ( head_fp == NULL)
00055 {
00056 G_warning ("Cannot Open Vector %s@%s Head File\n", Map->name, Map->mapset);
00057 return (GRASS_ERR);
00058 }
00059
00060 fprintf (head_fp, "ORGANIZATION: %s\n", Vect_get_organization(Map) );
00061 fprintf (head_fp, "DIGIT DATE: %s\n", Vect_get_date(Map) );
00062 fprintf (head_fp, "DIGIT NAME: %s\n", Vect_get_person(Map) );
00063 fprintf (head_fp, "MAP NAME: %s\n", Vect_get_map_name(Map) );
00064 fprintf (head_fp, "MAP DATE: %s\n", Vect_get_map_date(Map) );
00065 fprintf (head_fp, "MAP SCALE: %d\n", Vect_get_scale(Map) );
00066 fprintf (head_fp, "OTHER INFO: %s\n", Vect_get_comment(Map) );
00067 fprintf (head_fp, "ZONE: %d\n", Vect_get_zone(Map) );
00068 fprintf (head_fp, "MAP THRESH: %f\n", Vect_get_thresh(Map) );
00069
00070 fclose (head_fp);
00071 return (GRASS_OK);
00072 }
00073
00074
00075
00076
00077
00078 int
00079 Vect__read_head (struct Map_info *Map)
00080 {
00081 FILE *head_fp;
00082 char buff[2001];
00083 char *ptr;
00084
00085 G_debug (1, "Vect__read_head(): vector = %s@%s", Map->name, Map->mapset);
00086 sprintf (buff, "%s/%s", GRASS_VECT_DIRECTORY, Map->name);
00087 head_fp = G_fopen_old (buff, GRASS_VECT_HEAD_ELEMENT, Map->mapset);
00088 if ( head_fp == NULL)
00089 {
00090 G_warning ("Cannot Open Vector %s Head File\n", Map->name);
00091 return (GRASS_ERR);
00092 }
00093
00094 while ( G_getl2 (buff, 2000, head_fp) ) {
00095
00096 if (!(ptr = G_index (buff, ':')))
00097 return (-1);
00098 ptr++;
00099 while (*ptr == ' ')
00100 ptr++;
00101
00102 if (strncmp (buff, "ORGANIZATION:", 12) == 0)
00103 Vect_set_organization ( Map, ptr );
00104 else if (strncmp (buff, "DIGIT DATE:", 11) == 0)
00105 Vect_set_date ( Map, ptr );
00106 else if (strncmp (buff, "DIGIT NAME:", 11) == 0)
00107 Vect_set_person ( Map, ptr );
00108 else if (strncmp (buff, "MAP NAME:", 9) == 0)
00109 Vect_set_map_name ( Map, ptr );
00110 else if (strncmp (buff, "MAP DATE:", 9) == 0)
00111 Vect_set_map_date ( Map, ptr );
00112 else if (strncmp (buff, "MAP SCALE:", 10) == 0)
00113 Vect_set_scale ( Map, atoi (ptr) );
00114 else if (strncmp (buff, "OTHER INFO:", 11) == 0)
00115 Vect_set_comment ( Map, ptr );
00116 else if (strncmp (buff, "ZONE:", 5) == 0 || strncmp (buff, "UTM ZONE:", 9) == 0)
00117 Vect_set_zone ( Map, atoi (ptr) );
00118 else if (strncmp (buff, "WEST EDGE:", 10) == 0) {}
00119 else if (strncmp (buff, "EAST EDGE:", 10) == 0) {}
00120 else if (strncmp (buff, "SOUTH EDGE:", 11) == 0) {}
00121 else if (strncmp (buff, "NORTH EDGE:", 11) == 0) {}
00122 else if (strncmp (buff, "MAP THRESH:", 11) == 0)
00123 Vect_set_thresh ( Map, atof (ptr) );
00124 else
00125 G_warning("Unknown keyword %s in vector head\n", buff);
00126 }
00127
00128 fclose (head_fp);
00129 return (GRASS_OK);
00130 }
00131
00132
00133
00134 char *
00135 Vect_get_name (struct Map_info *Map)
00136 {
00137 return (Map->name);
00138 }
00139
00140 char *
00141 Vect_get_mapset (struct Map_info *Map)
00142 {
00143 return (Map->mapset);
00144 }
00145
00146 char *
00147 Vect_get_full_name (struct Map_info *Map)
00148 {
00149 char *ptr;
00150
00151 ptr = G_malloc ( strlen(Map->name) + strlen(Map->mapset) + 2 );
00152 sprintf (ptr, "%s@%s", Map->name, Map->mapset);
00153 return (ptr);
00154 }
00155
00162 int
00163 Vect_is_3d (struct Map_info *Map )
00164 {
00165 return ( Map->head.with_z );
00166 }
00167
00174 int
00175 Vect_set_organization (struct Map_info *Map, char *str )
00176 {
00177 G_free ( Map->head.organization );
00178 Map->head.organization = G_store ( str );
00179 return (0);
00180 }
00181
00188 char *
00189 Vect_get_organization (struct Map_info *Map)
00190 {
00191 return (Map->head.organization);
00192 }
00193
00200
00201 int
00202 Vect_set_date (struct Map_info *Map, char *str )
00203 {
00204 G_free ( Map->head.date );
00205 Map->head.date = G_store ( str );
00206 return (0);
00207 }
00208
00215
00216 char *
00217 Vect_get_date (struct Map_info *Map)
00218 {
00219 return (Map->head.date);
00220 }
00221
00228 int
00229 Vect_set_person (struct Map_info *Map, char *str )
00230 {
00231 G_free ( Map->head.your_name );
00232 Map->head.your_name = G_store ( str );
00233 return (0);
00234 }
00235
00242 char *
00243 Vect_get_person (struct Map_info *Map)
00244 {
00245 return (Map->head.your_name);
00246 }
00247
00254 int
00255 Vect_set_map_name (struct Map_info *Map, char *str )
00256 {
00257 G_free ( Map->head.map_name );
00258 Map->head.map_name = G_store ( str );
00259 return (0);
00260 }
00261
00268 char *
00269 Vect_get_map_name (struct Map_info *Map)
00270 {
00271 return (Map->head.map_name);
00272 }
00273
00280 int
00281 Vect_set_map_date (struct Map_info *Map, char *str )
00282 {
00283 G_free ( Map->head.source_date );
00284 Map->head.source_date = G_store ( str );
00285 return (0);
00286 }
00287
00294 char *
00295 Vect_get_map_date (struct Map_info *Map)
00296 {
00297 return (Map->head.source_date);
00298 }
00299
00306 int
00307 Vect_set_scale (struct Map_info *Map, int scale )
00308 {
00309 Map->head.orig_scale = scale;
00310 return (0);
00311 }
00312
00319 int
00320 Vect_get_scale (struct Map_info *Map)
00321 {
00322 return ((int) Map->head.orig_scale);
00323 }
00324
00331 int
00332 Vect_set_comment (struct Map_info *Map, char *str )
00333 {
00334 G_free ( Map->head.line_3 );
00335 Map->head.line_3 = G_store ( str );
00336 return (0);
00337 }
00338
00345 char *
00346 Vect_get_comment (struct Map_info *Map)
00347 {
00348 return (Map->head.line_3);
00349 }
00350
00357 int
00358 Vect_set_zone (struct Map_info *Map, int zone )
00359 {
00360 Map->head.plani_zone = zone;
00361 return (0);
00362 }
00363
00370 int
00371 Vect_get_zone (struct Map_info *Map)
00372 {
00373 return (Map->head.plani_zone);
00374 }
00375
00382 int
00383 Vect_set_thresh (struct Map_info *Map, double thresh )
00384 {
00385 G_debug ( 1, "Vect_set_thresh(): thresh = %f", thresh );
00386 Map->head.digit_thresh = thresh;
00387 return (0);
00388 }
00389
00396 double
00397 Vect_get_thresh (struct Map_info *Map)
00398 {
00399 G_debug ( 1, "Vect_get_thresh(): thresh = %f", Map->head.digit_thresh );
00400 return (Map->head.digit_thresh);
00401 }
00402
00403