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,
78 ogr_info->
ds = Ogr_ds;
82 nLayers = OGR_DS_GetLayerCount(Ogr_ds);
83 G_debug(2,
"%d layers found in data source", nLayers);
85 for (i = 0; i < nLayers; i++) {
86 Ogr_layer = OGR_DS_GetLayer(Ogr_ds, i);
87 Ogr_featuredefn = OGR_L_GetLayerDefn(Ogr_layer);
88 if (strcmp(OGR_FD_GetName(Ogr_featuredefn), ogr_info->
layer_name) ==
90 Ogr_geom_type = OGR_FD_GetGeomType(Ogr_featuredefn);
96 OGR_DS_Destroy(Ogr_ds);
101 ogr_info->
layer = Ogr_layer;
102 if (update && OGR_L_TestCapability(ogr_info->
layer, OLCTransactions) &&
103 (OGR_L_StartTransaction(ogr_info->
layer) != OGRERR_NONE)) {
104 OGR_DS_Destroy(Ogr_ds);
105 G_warning(
_(
"OGR transaction with layer <%s> failed to start"),
110 switch (Ogr_geom_type) {
112 case wkbLineString25D:
114 case wkbMultiPoint25D:
115 case wkbMultiLineString25D:
116 case wkbMultiPolygon25D:
117 case wkbGeometryCollection25D:
149 G_debug(3,
"V2_open_old_ogr(): name = %s mapset = %s", Map->
name,
153 G_warning(
_(
"Unable to open feature index file for vector map <%s>"),
187 OGRSFDriverH Ogr_driver;
188 OGRDataSourceH Ogr_ds;
190 OGRFeatureDefnH Ogr_featuredefn;
196 G_debug(1,
"V1_open_new_ogr(): name = %s with_z = %d",
name, with_z);
197 Ogr_driver = OGRGetDriverByName(ogr_info->
driver_name);
202 ogr_info->
driver = Ogr_driver;
205 Ogr_ds = OGR_Dr_CreateDataSource(Ogr_driver, ogr_info->
dsn,
NULL);
207 G_warning(
_(
"Unable to create OGR data source '%s'"), ogr_info->
dsn);
210 ogr_info->
ds = Ogr_ds;
212 nlayers = OGR_DS_GetLayerCount(Ogr_ds);
213 for (i = 0; i < nlayers; i++) {
214 Ogr_layer = OGR_DS_GetLayer(Ogr_ds, i);
215 Ogr_featuredefn = OGR_L_GetLayerDefn(Ogr_layer);
216 if (strcmp(OGR_FD_GetName(Ogr_featuredefn),
name) == 0) {
219 _(
"OGR layer <%s> already exists and will be overwritten"),
222 if (OGR_DS_DeleteLayer(Ogr_ds, i) != OGRERR_NONE) {
223 G_warning(
_(
"Unable to delete OGR layer <%s>"),
230 _(
"OGR layer <%s> already exists in datasource '%s'"),
259 int Version_Major, Version_Minor, Back_Major, Back_Minor, byte_order;
264 G_debug(1,
"Vect_open_fidx(): name = %s mapset = %s format = %d", Map->
name,
271 G_debug(1,
"unable to open fidx file for vector map <%s>",
279 Version_Major = buf[0];
280 Version_Minor = buf[1];
286 if (Version_Major > 5 || Version_Minor > 0) {
287 if (Back_Major > 5 || Back_Minor > 0) {
289 "supported by this release."
290 " Try to rebuild topology or upgrade GRASS."),
291 Version_Major, Version_Minor);
294 G_warning(
_(
"Your GRASS version does not fully support feature index "
295 "format %d.%d of the vector."
296 " Consider to rebuild topology or upgrade GRASS."),
297 Version_Major, Version_Minor);
307 G_debug(4,
" header size %ld", length);
FILE * G_fopen_old(const char *, const char *, const char *)
Open a database file for reading.
void G_zero(void *, int)
Zero out a buffer, buf, of length i.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void G_warning(const char *,...) __attribute__((format(printf
void G_fseek(FILE *, off_t, int)
Change the file position of the stream.
int G_get_overwrite(void)
Get overwrite value.
int G_debug(int, const char *,...) __attribute__((format(printf
const char * Vect_get_full_name(struct Map_info *)
Get fully qualified name of vector map.
#define GV_DIRECTORY
Name of vector directory.
#define GV_FIDX_ELEMENT
External format (OGR), feature index.
#define WITHOUT_Z
2D/3D vector data
void dig_init_portable(struct Port_info *, int)
Set Port_info structure to byte order of file.
int dig__fread_port_L(long *, size_t, struct gvfile *)
Read longs from the Portable Vector Format.
int dig_set_cur_port(struct Port_info *)
Set current Port_info structure.
int dig__fread_port_C(char *, size_t, struct gvfile *)
Read chars from the Portable Vector Format.
int dig__fread_port_I(int *, size_t, struct gvfile *)
Read integers from the Portable Vector Format.
void dig_file_init(struct gvfile *file)
Initialize gvfile structure.
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 Vect_open_fidx(struct Map_info *Map, struct Format_info_offset *offset)
Open feature index file.
int V2_open_old_ogr(struct Map_info *Map)
Open existing OGR layer on topological level.
int V1_open_old_ogr(struct Map_info *Map, int update)
Open existing OGR layer on non-topological level.
char * mapset
Mapset name.
struct dig_head head
Header info.
char * name
Map name (for 4.0)
int format
Map format (native, ogr, postgis)
struct Format_info fInfo
Format info for non-native formats.
int byte_order
File byte order.
int with_z
2D/3D vector data
FILE * file
File descriptor.