23 #include <sys/types.h>
26 #include <grass/Vect.h>
27 #include <grass/gis.h>
28 #include <grass/glocale.h>
47 int i, layer, nLayers;
48 OGRDataSourceH Ogr_ds;
49 OGRLayerH Ogr_layer =
NULL;
50 OGRFeatureDefnH Ogr_featuredefn;
53 G_warning(_(
"OGR format cannot be updated"));
57 G_debug(2,
"V1_open_old_ogr(): dsn = %s layer = %s", Map->fInfo.ogr.dsn,
58 Map->fInfo.ogr.layer_name);
63 Ogr_ds = OGROpen(Map->fInfo.ogr.dsn,
FALSE,
NULL);
67 Map->fInfo.ogr.ds = Ogr_ds;
71 nLayers = OGR_DS_GetLayerCount(Ogr_ds);
72 G_debug(2,
"%d layers found in data source", nLayers);
74 for (i = 0; i < nLayers; i++) {
75 Ogr_layer = OGR_DS_GetLayer(Ogr_ds, i);
76 Ogr_featuredefn = OGR_L_GetLayerDefn(Ogr_layer);
77 if (strcmp(OGR_FD_GetName(Ogr_featuredefn), Map->fInfo.ogr.layer_name)
84 OGR_DS_Destroy(Ogr_ds);
86 Map->fInfo.ogr.layer_name);
88 G_debug(2,
"OGR layer %d opened", layer);
90 Map->fInfo.ogr.layer = Ogr_layer;
92 Map->fInfo.ogr.lines =
NULL;
93 Map->fInfo.ogr.lines_types =
NULL;
94 Map->fInfo.ogr.lines_alloc = 0;
95 Map->fInfo.ogr.lines_num = 0;
96 Map->fInfo.ogr.lines_next = 0;
98 Map->head.with_z = WITHOUT_Z;
100 Map->fInfo.ogr.feature_cache =
NULL;
101 Map->fInfo.ogr.feature_cache_id = -1;
116 char elem[GPATH_MAX];
120 struct Port_info port;
121 int Version_Major, Version_Minor, Back_Major, Back_Minor, byte_order;
123 G_debug(3,
"V2_open_old_ogr()");
125 sprintf(elem,
"%s/%s", GRASS_VECT_DIRECTORY, Map->name);
128 if (fp.file ==
NULL) {
129 G_warning(_(
"Unable to open fidx file for vector map <%s@%s>"),
130 Map->name, Map->mapset);
137 Version_Major = buf[0];
138 Version_Minor = buf[1];
145 if (Version_Major > 5 || Version_Minor > 0) {
146 if (Back_Major > 5 || Back_Minor > 0) {
147 G_fatal_error(_(
"Feature index format version %d.%d is not supported by this release."
148 " Try to rebuild topology or upgrade GRASS."),
149 Version_Major, Version_Minor);
152 G_warning(_(
"Your GRASS version does not fully support feature index format %d.%d of the vector."
153 " Consider to rebuild topology or upgrade GRASS."),
154 Version_Major, Version_Minor);
164 G_debug(3,
" header size %ld", length);
166 fseek(fp.file, length, SEEK_SET);
173 Map->fInfo.ogr.offset =
174 (
int *)G_malloc(Map->fInfo.ogr.offset_num *
sizeof(
int));
175 Map->fInfo.ogr.offset_alloc = Map->fInfo.ogr.offset_num;
179 Map->fInfo.ogr.offset_num, &fp))
184 G_debug(3,
"%d records read from fidx", Map->fInfo.ogr.offset_num);
187 Map->fInfo.ogr.next_line = 1;