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;
51 OGRwkbGeometryType Ogr_geom_type;
58 G_debug(2,
"V1_open_old_ogr(): dsn = %s layer = %s", Map->fInfo.ogr.dsn,
59 Map->fInfo.ogr.layer_name);
64 Ogr_ds = OGROpen(Map->fInfo.ogr.dsn,
FALSE,
NULL);
68 Map->fInfo.ogr.ds = Ogr_ds;
72 nLayers = OGR_DS_GetLayerCount(Ogr_ds);
73 G_debug(2,
"%d layers found in data source", nLayers);
75 for (i = 0; i < nLayers; i++) {
76 Ogr_layer = OGR_DS_GetLayer(Ogr_ds, i);
77 Ogr_featuredefn = OGR_L_GetLayerDefn(Ogr_layer);
78 if (strcmp(OGR_FD_GetName(Ogr_featuredefn), Map->fInfo.ogr.layer_name) == 0) {
79 Ogr_geom_type = OGR_FD_GetGeomType(Ogr_featuredefn);
85 OGR_DS_Destroy(Ogr_ds);
87 Map->fInfo.ogr.layer_name);
89 G_debug(2,
"OGR layer %d opened", layer);
91 Map->fInfo.ogr.layer = Ogr_layer;
93 Map->fInfo.ogr.lines =
NULL;
94 Map->fInfo.ogr.lines_types =
NULL;
95 Map->fInfo.ogr.lines_alloc = 0;
96 Map->fInfo.ogr.lines_num = 0;
97 Map->fInfo.ogr.lines_next = 0;
99 switch(Ogr_geom_type) {
100 case wkbPoint25D:
case wkbLineString25D:
case wkbPolygon25D:
101 case wkbMultiPoint25D:
case wkbMultiLineString25D:
case wkbMultiPolygon25D:
102 case wkbGeometryCollection25D:
103 Map->head.with_z = WITH_Z;
106 Map->head.with_z = WITHOUT_Z;
110 Map->fInfo.ogr.feature_cache =
NULL;
111 Map->fInfo.ogr.feature_cache_id = -1;
126 char elem[GPATH_MAX];
130 struct Port_info port;
131 int Version_Major, Version_Minor, Back_Major, Back_Minor, byte_order;
133 G_debug(3,
"V2_open_old_ogr()");
135 sprintf(elem,
"%s/%s", GRASS_VECT_DIRECTORY, Map->name);
138 if (fp.file ==
NULL) {
139 G_warning(_(
"Unable to open fidx file for vector map <%s@%s>"),
140 Map->name, Map->mapset);
147 Version_Major = buf[0];
148 Version_Minor = buf[1];
155 if (Version_Major > 5 || Version_Minor > 0) {
156 if (Back_Major > 5 || Back_Minor > 0) {
157 G_fatal_error(_(
"Feature index format version %d.%d is not supported by this release."
158 " Try to rebuild topology or upgrade GRASS."),
159 Version_Major, Version_Minor);
162 G_warning(_(
"Your GRASS version does not fully support feature index format %d.%d of the vector."
163 " Consider to rebuild topology or upgrade GRASS."),
164 Version_Major, Version_Minor);
174 G_debug(3,
" header size %ld", length);
176 fseek(fp.file, length, SEEK_SET);
183 Map->fInfo.ogr.offset =
184 (
int *)G_malloc(Map->fInfo.ogr.offset_num *
sizeof(
int));
185 Map->fInfo.ogr.offset_alloc = Map->fInfo.ogr.offset_num;
189 Map->fInfo.ogr.offset_num, &fp))
194 G_debug(3,
"%d records read from fidx", Map->fInfo.ogr.offset_num);
197 Map->fInfo.ogr.next_line = 1;
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
int dig_set_cur_port(struct Port_info *port)
int V1_open_old_ogr(struct Map_info *Map, int update)
Open existing vector map.
void dig_init_portable(struct Port_info *port, int byte_order)
int dig__fread_port_L(long *buf, int cnt, GVFILE *fp)
int V2_open_old_ogr(struct Map_info *Map)
Open OGR specific level 2 files (feature index)
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
int dig__fread_port_C(char *buf, int cnt, GVFILE *fp)
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
int G_debug(int level, const char *msg,...)
Print debugging message.
void dig_file_init(GVFILE *file)
Initialize GVFILE.
FILE * G_fopen_old(const char *element, const char *name, const char *mapset)
Open a database file for reading.
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
int dig__fread_port_I(int *buf, int cnt, GVFILE *fp)