20 #include <sys/types.h> 46 int i, layer, nLayers;
50 OGRDataSourceH Ogr_ds;
52 OGRFeatureDefnH Ogr_featuredefn;
53 OGRwkbGeometryType Ogr_geom_type;
56 Ogr_geom_type = wkbUnknown;
69 G_debug(2,
"V1_open_old_ogr(): dsn = %s layer = %s", ogr_info->
dsn,
79 ogr_info->
ds = Ogr_ds;
83 nLayers = OGR_DS_GetLayerCount(Ogr_ds);
84 G_debug(2,
"%d layers found in data source", nLayers);
86 for (i = 0; i < nLayers; i++) {
87 Ogr_layer = OGR_DS_GetLayer(Ogr_ds, i);
88 Ogr_featuredefn = OGR_L_GetLayerDefn(Ogr_layer);
89 if (strcmp(OGR_FD_GetName(Ogr_featuredefn), ogr_info->
layer_name) == 0) {
90 Ogr_geom_type = OGR_FD_GetGeomType(Ogr_featuredefn);
96 OGR_DS_Destroy(Ogr_ds);
100 G_debug(2,
"OGR layer %d opened", layer);
102 ogr_info->
layer = Ogr_layer;
103 if (update && OGR_L_TestCapability(ogr_info->
layer, OLCTransactions) &&
104 (OGR_L_StartTransaction(ogr_info->
layer) != OGRERR_NONE)) {
105 OGR_DS_Destroy(Ogr_ds);
106 G_warning(
_(
"OGR transaction with layer <%s> failed to start"),
111 switch(Ogr_geom_type) {
112 case wkbPoint25D:
case wkbLineString25D:
case wkbPolygon25D:
113 case wkbMultiPoint25D:
case wkbMultiLineString25D:
case wkbMultiPolygon25D:
114 case wkbGeometryCollection25D:
146 G_debug(3,
"V2_open_old_ogr(): name = %s mapset = %s", Map->
name,
150 G_warning(
_(
"Unable to open feature index file for vector map <%s>"),
184 OGRSFDriverH Ogr_driver;
185 OGRDataSourceH Ogr_ds;
187 OGRFeatureDefnH Ogr_featuredefn;
193 G_debug(1,
"V1_open_new_ogr(): name = %s with_z = %d", name, with_z);
194 Ogr_driver = OGRGetDriverByName(ogr_info->
driver_name);
199 ogr_info->
driver = Ogr_driver;
202 Ogr_ds = OGR_Dr_CreateDataSource(Ogr_driver, ogr_info->
dsn,
NULL);
204 G_warning(
_(
"Unable to create OGR data source '%s'"),
208 ogr_info->
ds = Ogr_ds;
210 nlayers = OGR_DS_GetLayerCount(Ogr_ds);
211 for (i = 0; i < nlayers; i++) {
212 Ogr_layer = OGR_DS_GetLayer(Ogr_ds, i);
213 Ogr_featuredefn = OGR_L_GetLayerDefn(Ogr_layer);
214 if (strcmp(OGR_FD_GetName(Ogr_featuredefn), name) == 0) {
216 G_warning(
_(
"OGR layer <%s> already exists and will be overwritten"),
219 if (OGR_DS_DeleteLayer(Ogr_ds, i) != OGRERR_NONE) {
220 G_warning(
_(
"Unable to delete OGR layer <%s>"),
226 G_fatal_error(
_(
"OGR layer <%s> already exists in datasource '%s'"),
255 int Version_Major, Version_Minor, Back_Major, Back_Minor, byte_order;
260 G_debug(1,
"Vect_open_fidx(): name = %s mapset = %s format = %d",
267 G_debug(1,
"unable to open fidx file for vector map <%s>",
275 Version_Major = buf[0];
276 Version_Minor = buf[1];
282 if (Version_Major > 5 || Version_Minor > 0) {
283 if (Back_Major > 5 || Back_Minor > 0) {
284 G_fatal_error(
_(
"Feature index format version %d.%d is not supported by this release." 285 " Try to rebuild topology or upgrade GRASS."),
286 Version_Major, Version_Minor);
289 G_warning(
_(
"Your GRASS version does not fully support feature index format %d.%d of the vector." 290 " Consider to rebuild topology or upgrade GRASS."),
291 Version_Major, Version_Minor);
301 G_debug(4,
" header size %ld", length);
int Vect_open_fidx(struct Map_info *Map, struct Format_info_offset *offset)
Open feature index file.
char * name
Map name (for 4.0)
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void dig_init_portable(struct Port_info *, int)
Set Port_info structure to byte order of file.
#define GV_DIRECTORY
Name of vector directory.
int dig__fread_port_I(int *, size_t, struct gvfile *)
Read integers from the Portable Vector Format.
int dig__fread_port_C(char *, size_t, struct gvfile *)
Read chars from the Portable Vector Format.
int dig__fread_port_L(long *, size_t, struct gvfile *)
Read longs from the Portable Vector Format.
struct Format_info fInfo
Format info for non-native formats.
int V1_open_old_ogr(struct Map_info *Map, int update)
Open existing OGR layer on non-topological level.
int G_get_overwrite()
Get overwrite value.
int with_z
2D/3D vector data
int V2_open_old_ogr(struct Map_info *Map)
Open existing OGR layer on topological level.
void G_fseek(FILE *, off_t, int)
Change the file position of the stream.
void dig_file_init(struct gvfile *file)
Initialize gvfile strcuture.
FILE * G_fopen_old(const char *, const char *, const char *)
Open a database file for reading.
char * mapset
Mapset name.
#define WITHOUT_Z
2D/3D vector data
struct dig_head head
Header info.
FILE * file
File descriptor.
const char * Vect_get_full_name(const struct Map_info *)
Get fully qualified name of vector map.
void G_zero(void *, int)
Zero out a buffer, buf, of length i.
void G_warning(const char *,...) __attribute__((format(printf
int format
Map format (native, ogr, postgis)
int dig_set_cur_port(struct Port_info *)
Set current Port_info structure.
#define GV_FIDX_ELEMENT
External format (OGR), feature index.
int V1_open_new_ogr(struct Map_info *Map, const char *name, int with_z)
Prepare OGR datasource for creating new OGR layer (level 1)
int G_debug(int, const char *,...) __attribute__((format(printf