diff --git a/db/drivers/ogr/describe.c b/db/drivers/ogr/describe.c index ba8aa9f848f..ad93339659e 100644 --- a/db/drivers/ogr/describe.c +++ b/db/drivers/ogr/describe.c @@ -105,10 +105,7 @@ int describe_table(OGRLayerH hLayer, dbTable **table, cursor *c) ogrType = OGR_Fld_GetType(hFieldDefn); fieldName = OGR_Fld_GetNameRef(hFieldDefn); - if (ogrType != OFTInteger && -#if GDAL_VERSION_NUM >= 2000000 - ogrType != OFTInteger64 && -#endif + if (ogrType != OFTInteger && ogrType != OFTInteger64 && ogrType != OFTReal && ogrType != OFTString && ogrType != OFTDate && ogrType != OFTTime && ogrType != OFTDateTime) { G_warning( @@ -174,19 +171,15 @@ int describe_table(OGRLayerH hLayer, dbTable **table, cursor *c) switch (ogrType) { case OFTInteger: -#if GDAL_VERSION_NUM >= 2000000 case OFTInteger64: -#endif sqlType = DB_SQL_TYPE_INTEGER; size = OGR_Fld_GetWidth(hFieldDefn); /* OK ? */ precision = 0; -#if GDAL_VERSION_NUM >= 2000000 if (ogrType == OFTInteger64) G_warning(_("Column '%s' : type int8 (bigint) is stored as " "integer (4 bytes) " "some data may be damaged"), fieldName); -#endif break; case OFTReal: diff --git a/db/drivers/ogr/execute.c b/db/drivers/ogr/execute.c index b47d18eb93a..71379aea8e9 100644 --- a/db/drivers/ogr/execute.c +++ b/db/drivers/ogr/execute.c @@ -98,10 +98,7 @@ int db__driver_execute_immediate(dbString *sql) } else { if ((cols[i].type != OFTInteger || -#if GDAL_VERSION_NUM >= 2000000 - cols[i].type != OFTInteger64 || -#endif - cols[i].type != OFTReal) && + cols[i].type != OFTInteger64 || cols[i].type != OFTReal) && *(cols[i].value) == '\'') { value = G_strchg(cols[i].value, '\'', ' '); G_strip(value); diff --git a/db/drivers/ogr/fetch.c b/db/drivers/ogr/fetch.c index caf9e9063af..5fb954fbafd 100644 --- a/db/drivers/ogr/fetch.c +++ b/db/drivers/ogr/fetch.c @@ -143,12 +143,10 @@ int db__driver_fetch(dbCursor *cn, int position, int *more) value->i = OGR_F_GetFieldAsInteger(c->hFeature, i); break; -#if GDAL_VERSION_NUM >= 2000000 case OFTInteger64: /* test for integer overflow ? */ value->i = OGR_F_GetFieldAsInteger64(c->hFeature, i); break; -#endif case OFTReal: value->d = OGR_F_GetFieldAsDouble(c->hFeature, i); diff --git a/include/grass/defs/gis.h b/include/grass/defs/gis.h index 341a4f9a1a7..4339fad72d1 100644 --- a/include/grass/defs/gis.h +++ b/include/grass/defs/gis.h @@ -72,25 +72,6 @@ #define RELDIR "?" #endif -/* GDAL < 2.3 does not define HAVE_LONG_LONG when compiled with - * Visual Studio as for OSGeo4W, even though long long is available, - * and GIntBig falls back to long which is on Windows always 4 bytes. - * This patch ensures that GIntBig is defined as long long (8 bytes) - * if GDAL is compiled with Visual Studio and GRASS is compiled with - * MinGW. This patch must be applied before other GDAL/OGR headers are - * included, as done by gprojects.h and vector.h */ -#if defined(__MINGW32__) && HAVE_GDAL -#include -#if GDAL_VERSION_NUM < 2030000 -#include -/* HAVE_LONG_LONG_INT comes from GRASS - * HAVE_LONG_LONG comes from GDAL */ -#if HAVE_LONG_LONG_INT && !defined(HAVE_LONG_LONG) -#define HAVE_LONG_LONG 1 -#endif -#endif -#endif - /* adj_cellhd.c */ void G_adjust_Cell_head(struct Cell_head *, int, int); void G_adjust_Cell_head3(struct Cell_head *, int, int, int); diff --git a/lib/vector/Vlib/field.c b/lib/vector/Vlib/field.c index 8ee4855d925..8a5b180ae2a 100644 --- a/lib/vector/Vlib/field.c +++ b/lib/vector/Vlib/field.c @@ -731,8 +731,6 @@ static int read_dblinks_ogr(struct Map_info *Map) #ifndef HAVE_OGR G_warning(_("GRASS is not compiled with OGR support")); #else -#if GDAL_VERSION_NUM > 1320 && \ - HAVE_OGR /* seems to be fixed after 1320 release */ int nLayers; char *ogr_fid_col; @@ -777,112 +775,6 @@ static int read_dblinks_ogr(struct Map_info *Map) Vect_add_dblink(dbl, 1, Map->fInfo.ogr.layer_name, Map->fInfo.ogr.layer_name, ogr_fid_col, Map->fInfo.ogr.dsn, "ogr"); -#else - dbDriver *driver; - dbCursor cursor; - dbString sql; - int FID = 0, OGC_FID = 0, OGR_FID = 0, GID = 0; - - G_debug(3, "GDAL_VERSION_NUM: %d", GDAL_VERSION_NUM); - - /* FID is not available for all OGR drivers */ - db_init_string(&sql); - - driver = db_start_driver_open_database("ogr", Map->fInfo.ogr.dsn); - - if (driver == NULL) { - G_warning(_("Unable to open OGR DBMI driver")); - return -1; - } - - /* this is a bit stupid, but above FID auto-detection doesn't work yet...: - */ - db_auto_print_errors(0); - sprintf(buf, "select FID from %s where FID > 0", Map->fInfo.ogr.layer_name); - db_set_string(&sql, buf); - - if (db_open_select_cursor(driver, &sql, &cursor, DB_SEQUENTIAL) != DB_OK) { - /* FID not available, so we try ogc_fid */ - G_debug(3, "Failed. Now searching for ogc_fid column in OGR DB"); - sprintf(buf, "select ogc_fid from %s where ogc_fid > 0", - Map->fInfo.ogr.layer_name); - db_set_string(&sql, buf); - - if (db_open_select_cursor(driver, &sql, &cursor, DB_SEQUENTIAL) != - DB_OK) { - /* Neither FID nor ogc_fid available, so we try ogr_fid */ - G_debug(3, "Failed. Now searching for ogr_fid column in OGR DB"); - sprintf(buf, "select ogr_fid from %s where ogr_fid > 0", - Map->fInfo.ogr.layer_name); - db_set_string(&sql, buf); - - if (db_open_select_cursor(driver, &sql, &cursor, DB_SEQUENTIAL) != - DB_OK) { - /* Neither FID nor ogc_fid available, so we try gid */ - G_debug(3, "Failed. Now searching for gid column in OGR DB"); - sprintf(buf, "select gid from %s where gid > 0", - Map->fInfo.ogr.layer_name); - db_set_string(&sql, buf); - - if (db_open_select_cursor(driver, &sql, &cursor, - DB_SEQUENTIAL) != DB_OK) { - /* neither FID nor ogc_fid nor ogr_fid nor gid available */ - G_warning( - _("All FID tests failed. Neither 'FID' nor 'ogc_fid' " - "nor 'ogr_fid' nor 'gid' available in OGR DB table")); - db_close_database_shutdown_driver(driver); - return 0; - } - else - GID = 1; - } - else - OGR_FID = 1; - } - else - OGC_FID = 1; - } - else - FID = 1; - - G_debug(3, "FID: %d, OGC_FID: %d, OGR_FID: %d, GID: %d", FID, OGC_FID, - OGR_FID, GID); - - db_close_cursor(&cursor); - db_close_database_shutdown_driver(driver); - db_auto_print_errors(1); - - if (FID) { - G_debug(3, "Using FID column in OGR DB"); - Vect_add_dblink(dbl, 1, Map->fInfo.ogr.layer_name, - Map->fInfo.ogr.layer_name, "FID", Map->fInfo.ogr.dsn, - "ogr"); - } - else { - if (OGC_FID) { - G_debug(3, "Using ogc_fid column in OGR DB"); - Vect_add_dblink(dbl, 1, Map->fInfo.ogr.layer_name, - Map->fInfo.ogr.layer_name, "ogc_fid", - Map->fInfo.ogr.dsn, "ogr"); - } - else { - if (OGR_FID) { - G_debug(3, "Using ogr_fid column in OGR DB"); - Vect_add_dblink(dbl, 1, Map->fInfo.ogr.layer_name, - Map->fInfo.ogr.layer_name, "ogr_fid", - Map->fInfo.ogr.dsn, "ogr"); - } - else { - if (GID) { - G_debug(3, "Using gid column in OGR DB"); - Vect_add_dblink(dbl, 1, Map->fInfo.ogr.layer_name, - Map->fInfo.ogr.layer_name, "gid", - Map->fInfo.ogr.dsn, "ogr"); - } - } - } - } -#endif /* GDAL_VERSION_NUM > 1320 && HAVE_OGR */ return 1; #endif /* HAVE_GDAL */ } diff --git a/raster/r.in.gdal/main.c b/raster/r.in.gdal/main.c index 3fc96e5ee46..372bda483e2 100644 --- a/raster/r.in.gdal/main.c +++ b/raster/r.in.gdal/main.c @@ -48,12 +48,8 @@ static GDALDatasetH opends(char *dsname, const char **doo, GDALDriverH *hDriver) { GDALDatasetH hDS = NULL; -#if GDAL_VERSION_NUM >= 2000000 hDS = GDALOpenEx(dsname, GDAL_OF_RASTER | GDAL_OF_READONLY, NULL, doo, NULL); -#else - hDS = GDALOpen(dsname, GA_ReadOnly); -#endif if (hDS == NULL) G_fatal_error(_("Unable to open datasource <%s>"), dsname); G_add_error_handler(error_handler_ds, hDS); @@ -138,9 +134,6 @@ int main(int argc, char *argv[]) parm.band->guisection = _("Bands"); parm.memory = G_define_standard_option(G_OPT_MEMORYMB); -#if GDAL_VERSION_NUM < 1800 - parm.memory->options = "0-2047"; -#endif parm.target = G_define_option(); parm.target->key = "target"; diff --git a/vector/v.external/list.c b/vector/v.external/list.c index 5dd15e869a5..900aede55ab 100644 --- a/vector/v.external/list.c +++ b/vector/v.external/list.c @@ -293,9 +293,6 @@ int list_layers_ogr(FILE *fd, const char *dsn, char **layer, int print_types) for (i = 0; i < nlayers; i++) { Ogr_layer = OGR_DS_GetLayer(Ogr_ds, i); Ogr_featuredefn = OGR_L_GetLayerDefn(Ogr_layer); -#if GDAL_VERSION_NUM < 1110000 - Ogr_geom_type = OGR_FD_GetGeomType(Ogr_featuredefn); -#endif layer_name = (char *)OGR_FD_GetName(Ogr_featuredefn); if (fd) { @@ -303,9 +300,7 @@ int list_layers_ogr(FILE *fd, const char *dsn, char **layer, int print_types) int proj_same, igeom; OGRSpatialReferenceH Ogr_projection; -#if GDAL_VERSION_NUM >= 1110000 OGRGeomFieldDefnH Ogr_geomdefn; -#endif /* projection check */ Ogr_projection = OGR_L_GetSpatialRef(Ogr_layer); proj_same = 0; @@ -327,7 +322,6 @@ int list_layers_ogr(FILE *fd, const char *dsn, char **layer, int print_types) proj_same = 0; } G_suppress_warnings(FALSE); -#if GDAL_VERSION_NUM >= 1110000 for (igeom = 0; igeom < OGR_FD_GetGeomFieldCount(Ogr_featuredefn); igeom++) { @@ -343,11 +337,6 @@ int list_layers_ogr(FILE *fd, const char *dsn, char **layer, int print_types) feature_type(OGRGeometryTypeToName(Ogr_geom_type)), proj_same, OGR_GFld_GetNameRef(Ogr_geomdefn)); } -#else - fprintf(fd, "%s,%s,%d,\n", layer_name, - feature_type(OGRGeometryTypeToName(Ogr_geom_type)), - proj_same); -#endif } else { fprintf(fd, "%s\n", layer_name); diff --git a/vector/v.external/local_proto.h b/vector/v.external/local_proto.h index 3c8d02808fa..04fa7bff3f2 100644 --- a/vector/v.external/local_proto.h +++ b/vector/v.external/local_proto.h @@ -5,21 +5,6 @@ #include #include -/* define type of input datasource - * as of GDAL 2.2, all functions having as argument a GDAL/OGR dataset - * must use the GDAL version, not the OGR version */ -#if GDAL_VERSION_NUM >= 2020000 -typedef GDALDatasetH ds_t; - -#define ds_getlayerbyindex(ds, i) GDALDatasetGetLayer((ds), (i)) -#define ds_close(ds) GDALClose(ds) -#else -typedef OGRDataSourceH ds_t; - -#define ds_getlayerbyindex(ds, i) OGR_DS_GetLayer((ds), (i)) -#define ds_close(ds) OGR_DS_Destroy(ds) -#endif - struct _options { struct Option *dsn, *output, *layer, *where; }; @@ -40,6 +25,6 @@ int list_layers(FILE *, const char *, char **, int, int); void get_table_name(const char *, char **, char **); /* proj.c */ -void check_projection(struct Cell_head *, ds_t, int, char *, char *, int, int, - int); +void check_projection(struct Cell_head *, GDALDatasetH, int, char *, char *, + int, int, int); #endif diff --git a/vector/v.external/main.c b/vector/v.external/main.c index 7d72d421174..686b1359eaa 100644 --- a/vector/v.external/main.c +++ b/vector/v.external/main.c @@ -43,7 +43,7 @@ int main(int argc, char *argv[]) char buf[GPATH_MAX], *dsn, *layer; const char *output; struct Cell_head cellhd; - ds_t Ogr_ds; + GDALDatasetH Ogr_ds; G_gisinit(argv[0]); @@ -141,12 +141,8 @@ int main(int argc, char *argv[]) /* open OGR DSN */ Ogr_ds = NULL; if (strlen(options.dsn->answer) > 0) { -#if GDAL_VERSION_NUM >= 2020000 Ogr_ds = GDALOpenEx(options.dsn->answer, GDAL_OF_VECTOR, NULL, NULL, NULL); -#else - Ogr_ds = OGROpen(dsn, FALSE, NULL); -#endif } if (Ogr_ds == NULL) G_fatal_error(_("Unable to open data source <%s>"), dsn); @@ -173,7 +169,7 @@ int main(int argc, char *argv[]) /* check projection match */ check_projection(&cellhd, Ogr_ds, ilayer, NULL, NULL, 0, flags.override->answer, flags.proj->answer); - ds_close(Ogr_ds); + GDALClose(Ogr_ds); /* create new vector map */ putenv("GRASS_VECTOR_EXTERNAL_IGNORE=1"); diff --git a/vector/v.external/proj.c b/vector/v.external/proj.c index 901baf31e92..b1eae407c35 100644 --- a/vector/v.external/proj.c +++ b/vector/v.external/proj.c @@ -23,7 +23,6 @@ int get_layer_proj(OGRLayerH Ogr_layer, struct Cell_head *cellhd, *proj_wkt = NULL; /* Fetch input layer projection in GRASS form. */ -#if GDAL_VERSION_NUM >= 1110000 if (geom_col) { int igeom; OGRGeomFieldDefnH Ogr_geomdefn; @@ -41,9 +40,6 @@ int get_layer_proj(OGRLayerH Ogr_layer, struct Cell_head *cellhd, else { hSRS = OGR_L_GetSpatialRef(Ogr_layer); } -#else - hSRS = OGR_L_GetSpatialRef(Ogr_layer); /* should not be freed later */ -#endif /* verbose is used only when comparing input SRS to GRASS projection, * not when comparing SRS's of several input layers */ @@ -131,7 +127,7 @@ int get_layer_proj(OGRLayerH Ogr_layer, struct Cell_head *cellhd, } /* keep in sync with r.in.gdal, r.external, v.in.ogr */ -void check_projection(struct Cell_head *cellhd, ds_t hDS, int layer, +void check_projection(struct Cell_head *cellhd, GDALDatasetH hDS, int layer, char *geom_col, char *outloc, int create_only, int override, int check_only) { @@ -144,7 +140,7 @@ void check_projection(struct Cell_head *cellhd, ds_t hDS, int layer, OGRLayerH Ogr_layer; /* Get first layer to be imported to use for projection check */ - Ogr_layer = ds_getlayerbyindex(hDS, layer); + Ogr_layer = GDALDatasetGetLayer(hDS, layer); /* -------------------------------------------------------------------- */ /* Fetch the projection in GRASS form, SRID, and WKT. */ @@ -183,7 +179,7 @@ void check_projection(struct Cell_head *cellhd, ds_t hDS, int layer, /* If create only, clean up and exit here */ if (create_only) { - ds_close(hDS); + GDALClose(hDS); exit(EXIT_SUCCESS); } } @@ -205,7 +201,7 @@ void check_projection(struct Cell_head *cellhd, ds_t hDS, int layer, } else { msg_fn = G_fatal_error; - ds_close(hDS); + GDALClose(hDS); } msg_fn(error_msg); if (!override) { @@ -374,7 +370,7 @@ void check_projection(struct Cell_head *cellhd, ds_t hDS, int layer, msg_fn = G_fatal_error; msg_fn("%s", error_msg); if (check_only) { - ds_close(hDS); + GDALClose(hDS); exit(EXIT_FAILURE); } } @@ -386,7 +382,7 @@ void check_projection(struct Cell_head *cellhd, ds_t hDS, int layer, msg_fn(_("Projection of input dataset and current location " "appear to match")); if (check_only) { - ds_close(hDS); + GDALClose(hDS); exit(EXIT_SUCCESS); } } diff --git a/vector/v.in.ogr/geom.c b/vector/v.in.ogr/geom.c index 8fa0018fea3..afb37636b63 100644 --- a/vector/v.in.ogr/geom.c +++ b/vector/v.in.ogr/geom.c @@ -61,7 +61,6 @@ int centroid(OGRGeometryH hGeomAny, CENTR *Centr, struct spatial_index *Sindex, hGeom = hGeomAny; -#if GDAL_VERSION_NUM >= 2000000 if (OGR_G_HasCurveGeometry(hGeom, 0)) { G_debug(2, "Approximating curves in a '%s'", OGR_G_GetGeometryName(hGeom)); @@ -69,7 +68,6 @@ int centroid(OGRGeometryH hGeomAny, CENTR *Centr, struct spatial_index *Sindex, /* The ownership of the returned geometry belongs to the caller. */ hGeom = OGR_G_GetLinearGeometry(hGeom, 0, NULL); } -#endif eType = wkbFlatten(OGR_G_GetGeometryType(hGeom)); @@ -196,7 +194,6 @@ int poly_count(OGRGeometryH hGeomAny, int line2boundary) hGeom = hGeomAny; -#if GDAL_VERSION_NUM >= 2000000 if (OGR_G_HasCurveGeometry(hGeom, 0)) { G_debug(2, "Approximating curves in a '%s'", OGR_G_GetGeometryName(hGeom)); @@ -204,7 +201,6 @@ int poly_count(OGRGeometryH hGeomAny, int line2boundary) /* The ownership of the returned geometry belongs to the caller. */ hGeom = OGR_G_GetLinearGeometry(hGeom, 0, NULL); } -#endif eType = wkbFlatten(OGR_G_GetGeometryType(hGeom)); @@ -290,7 +286,6 @@ int geom(OGRGeometryH hGeomAny, struct Map_info *Map, int field, int cat, hGeom = hGeomAny; -#if GDAL_VERSION_NUM >= 2000000 if (OGR_G_HasCurveGeometry(hGeom, 0)) { G_debug(2, "Approximating curves in a '%s'", OGR_G_GetGeometryName(hGeom)); @@ -298,7 +293,6 @@ int geom(OGRGeometryH hGeomAny, struct Map_info *Map, int field, int cat, /* The ownership of the returned geometry belongs to the caller. */ hGeom = OGR_G_GetLinearGeometry(hGeom, 0, NULL); } -#endif eType = wkbFlatten(OGR_G_GetGeometryType(hGeom)); diff --git a/vector/v.in.ogr/global.h b/vector/v.in.ogr/global.h index 8e3b36998b5..de7984de341 100644 --- a/vector/v.in.ogr/global.h +++ b/vector/v.in.ogr/global.h @@ -26,19 +26,6 @@ #include #include -/* define type of input datasource - * as of GDAL 2.2, all functions having as argument a GDAL/OGR dataset - * must use the GDAL version, not the OGR version */ -#if GDAL_VERSION_NUM >= 2020000 -typedef GDALDatasetH ds_t; -#define ds_getlayerbyindex(ds, i) GDALDatasetGetLayer((ds), (i)) -#define ds_close(ds) GDALClose(ds) -#else -typedef OGRDataSourceH ds_t; -#define ds_getlayerbyindex(ds, i) OGR_DS_GetLayer((ds), (i)) -#define ds_close(ds) OGR_DS_Destroy(ds) -#endif - extern int n_polygons; extern int n_polygon_boundaries; extern double split_distance; diff --git a/vector/v.in.ogr/main.c b/vector/v.in.ogr/main.c index a5de8fa8cff..730d8fa64cd 100644 --- a/vector/v.in.ogr/main.c +++ b/vector/v.in.ogr/main.c @@ -50,17 +50,17 @@ char *get_datasource_name(const char *, int); void convert_osm_lines(struct Map_info *Map, double snap); -int cmp_layer_srs(ds_t, int, int *, char **, char *); -void check_projection(struct Cell_head *cellhd, ds_t hDS, int layer, +int cmp_layer_srs(GDALDatasetH, int, int *, char **, char *); +void check_projection(struct Cell_head *cellhd, GDALDatasetH hDS, int layer, char *geom_col, char *outloc, int create_only, int override, int check_only); -int create_spatial_filter(ds_t Ogr_ds, OGRGeometryH *, int, int *, char **, - double *, double *, double *, double *, int, +int create_spatial_filter(GDALDatasetH Ogr_ds, OGRGeometryH *, int, int *, + char **, double *, double *, double *, double *, int, struct Option *); struct OGR_iterator { - ds_t Ogr_ds; + GDALDatasetH Ogr_ds; char *dsn; int nlayers; int has_nonempty_layers; @@ -72,8 +72,8 @@ struct OGR_iterator { int done; }; -void OGR_iterator_init(struct OGR_iterator *OGR_iter, ds_t Ogr_ds, char *dsn, - int nlayers, int ogr_interleaved_reading); +void OGR_iterator_init(struct OGR_iterator *OGR_iter, GDALDatasetH Ogr_ds, + char *dsn, int nlayers, int ogr_interleaved_reading); void OGR_iterator_reset(struct OGR_iterator *OGR_iter); OGRFeatureH ogr_getnextfeature(struct OGR_iterator *, int, char *, OGRGeometryH, @@ -160,7 +160,7 @@ int main(int argc, char *argv[]) int *key_idx; /* OGR */ - ds_t Ogr_ds; + GDALDatasetH Ogr_ds; const char *ogr_driver_name; int ogr_interleaved_reading; OGRLayerH Ogr_layer; @@ -419,11 +419,7 @@ int main(int argc, char *argv[]) if (G_parser(argc, argv)) exit(EXIT_FAILURE); -#if GDAL_VERSION_NUM >= 2000000 GDALAllRegister(); -#else - OGRRegisterAll(); -#endif G_debug(1, "GDAL version %d", GDAL_VERSION_NUM); @@ -433,7 +429,6 @@ int main(int argc, char *argv[]) G_message(_("Supported formats:")); -#if GDAL_VERSION_NUM >= 2000000 for (iDriver = 0; iDriver < GDALGetDriverCount(); iDriver++) { GDALDriverH hDriver = GDALGetDriver(iDriver); const char *pszRWFlag; @@ -451,21 +446,6 @@ int main(int argc, char *argv[]) fprintf(stdout, " %s (%s): %s\n", GDALGetDriverShortName(hDriver), pszRWFlag, GDALGetDriverLongName(hDriver)); } - -#else - for (iDriver = 0; iDriver < OGRGetDriverCount(); iDriver++) { - OGRSFDriverH poDriver = OGRGetDriver(iDriver); - const char *pszRWFlag; - - if (OGR_Dr_TestCapability(poDriver, ODrCCreateDataSource)) - pszRWFlag = "rw"; - else - pszRWFlag = "ro"; - - fprintf(stdout, " %s (%s): %s\n", OGR_Dr_GetName(poDriver), - pszRWFlag, OGR_Dr_GetName(poDriver)); - } -#endif exit(EXIT_SUCCESS); } @@ -563,36 +543,22 @@ int main(int argc, char *argv[]) /* open OGR DSN */ Ogr_ds = NULL; if (strlen(dsn) > 0) { -#if GDAL_VERSION_NUM >= 2020000 Ogr_ds = GDALOpenEx(dsn, GDAL_OF_VECTOR, NULL, (const char **)doo, NULL); -#else - Ogr_ds = OGROpen(dsn, FALSE, NULL); -#endif } if (Ogr_ds == NULL) G_fatal_error(_("Unable to open data source <%s>"), dsn); - /* driver name */ -#if GDAL_VERSION_NUM >= 2020000 + /* driver name */ ogr_driver_name = GDALGetDriverShortName(GDALGetDatasetDriver(Ogr_ds)); G_verbose_message(_("Using OGR driver '%s/%s'"), ogr_driver_name, GDALGetDriverLongName(GDALGetDatasetDriver(Ogr_ds))); -#else - ogr_driver_name = OGR_Dr_GetName(OGR_DS_GetDriver(Ogr_ds)); - G_verbose_message(_("Using OGR driver '%s'"), ogr_driver_name); -#endif /* OGR interleaved reading */ ogr_interleaved_reading = 0; if (strcmp(ogr_driver_name, "OSM") == 0) { /* re-open OGR DSN */ -#if GDAL_VERSION_NUM < 2020000 - CPLSetConfigOption("OGR_INTERLEAVED_READING", "YES"); - OGR_DS_Destroy(Ogr_ds); - Ogr_ds = OGROpen(dsn, FALSE, NULL); -#endif ogr_interleaved_reading = 1; } if (strcmp(ogr_driver_name, "GMLAS") == 0) @@ -601,28 +567,13 @@ int main(int argc, char *argv[]) G_verbose_message(_("Using interleaved reading mode")); if (param.geom->answer) { -#if GDAL_VERSION_NUM >= 1110000 -#if GDAL_VERSION_NUM >= 2020000 if (!GDALDatasetTestCapability(Ogr_ds, ODsCCreateGeomFieldAfterCreateLayer)) { G_warning(_("Option <%s> will be ignored. OGR doesn't support it " "for selected format (%s)."), param.geom->key, ogr_driver_name); -#else - if (!OGR_DS_TestCapability(Ogr_ds, - ODsCCreateGeomFieldAfterCreateLayer)) { - G_warning(_("Option <%s> will be ignored. OGR doesn't support it " - "for selected format (%s)."), - param.geom->key, ogr_driver_name); -#endif param.geom->answer = NULL; } -#else - G_warning(_("Option <%s> will be ignored. Multiple geometry fields are " - "supported by GDAL >= 1.11"), - param.geom->key); - param.geom->answer = NULL; -#endif } /* check encoding for given driver */ @@ -633,11 +584,7 @@ int main(int argc, char *argv[]) ogr_driver_name); } -#if GDAL_VERSION_NUM >= 2020000 navailable_layers = GDALDatasetGetLayerCount(Ogr_ds); -#else - navailable_layers = OGR_DS_GetLayerCount(Ogr_ds); -#endif if (navailable_layers < 1) G_fatal_error(_("No OGR layers available")); @@ -651,7 +598,7 @@ int main(int argc, char *argv[]) ogr_driver_name, navailable_layers); } for (i = 0; i < navailable_layers; i++) { - Ogr_layer = ds_getlayerbyindex(Ogr_ds, i); + Ogr_layer = GDALDatasetGetLayer(Ogr_ds, i); available_layer_names[i] = G_store((char *)OGR_L_GetName(Ogr_layer)); @@ -660,7 +607,7 @@ int main(int argc, char *argv[]) } if (flag.list->answer) { fflush(stdout); - ds_close(Ogr_ds); + GDALClose(Ogr_ds); exit(EXIT_SUCCESS); } @@ -698,7 +645,7 @@ int main(int argc, char *argv[]) /* compare SRS of the different layers to be imported */ if (cmp_layer_srs(Ogr_ds, nlayers, layers, layer_names, param.geom->answer)) { - ds_close(Ogr_ds); + GDALClose(Ogr_ds); G_fatal_error(_("Detected different projections of input layers. " "Input layers must be imported separately.")); } @@ -737,13 +684,13 @@ int main(int argc, char *argv[]) /* check output name */ if (Vect_legal_filename(output) != 1) { - ds_close(Ogr_ds); + GDALClose(Ogr_ds); G_fatal_error(_("Illegal output name <%s>"), output); } /* Check if the output map exists */ if (G_find_vector2(output, G_mapset()) && !overwrite) { - ds_close(Ogr_ds); + GDALClose(Ogr_ds); G_fatal_error(_("Vector map <%s> already exists"), output); } @@ -783,8 +730,7 @@ int main(int argc, char *argv[]) attr_filter) { for (layer = 0; layer < nlayers; layer++) { - Ogr_layer = ds_getlayerbyindex(Ogr_ds, layers[layer]); -#if GDAL_VERSION_NUM >= 1110000 + Ogr_layer = GDALDatasetGetLayer(Ogr_ds, layers[layer]); if (param.geom->answer) { Ogr_featuredefn = OGR_L_GetLayerDefn(Ogr_layer); igeom = OGR_FD_GetGeomFieldIndex(Ogr_featuredefn, @@ -800,9 +746,6 @@ int main(int argc, char *argv[]) else { OGR_L_SetSpatialFilter(Ogr_layer, poSpatialFilter[layer]); } -#else - OGR_L_SetSpatialFilter(Ogr_layer, poSpatialFilter[layer]); -#endif if (OGR_L_SetAttributeFilter(Ogr_layer, attr_filter) != OGRERR_NONE) G_fatal_error(_("Error setting attribute filter '%s'"), attr_filter); @@ -837,10 +780,9 @@ int main(int argc, char *argv[]) n_features[layer] = 0; layer_id = layers[layer]; - Ogr_layer = ds_getlayerbyindex(Ogr_ds, layer_id); + Ogr_layer = GDALDatasetGetLayer(Ogr_ds, layer_id); Ogr_featuredefn = OGR_L_GetLayerDefn(Ogr_layer); igeom = -1; -#if GDAL_VERSION_NUM >= 1110000 if (param.geom->answer) { igeom = OGR_FD_GetGeomFieldIndex(Ogr_featuredefn, param.geom->answer); @@ -849,7 +791,6 @@ int main(int argc, char *argv[]) _("Geometry column <%s> not found in OGR layer <%s>"), param.geom->answer, OGR_L_GetName(Ogr_layer)); } -#endif feature_count = 0; ogr_feature_count = 0; @@ -871,35 +812,25 @@ int main(int argc, char *argv[]) if (ogr_feature_count <= 0) n_features[layer]++; - /* Geometry */ -#if GDAL_VERSION_NUM >= 1110000 + /* Geometry */ Ogr_featuredefn = OGR_iter.Ogr_featuredefn; for (i = 0; i < OGR_FD_GetGeomFieldCount(Ogr_featuredefn); i++) { if (igeom > -1 && i != igeom) continue; /* use only geometry defined via param.geom */ Ogr_geometry = OGR_F_GetGeomFieldRef(Ogr_feature, i); -#else - Ogr_geometry = OGR_F_GetGeometryRef(Ogr_feature); -#endif if (Ogr_geometry != NULL) { -#if GDAL_VERSION_NUM >= 2000000 Ogr_geometry = OGR_G_GetLinearGeometry(Ogr_geometry, 0, NULL); } if (Ogr_geometry != NULL) { -#endif if (!flag.no_clean->answer) poly_count(Ogr_geometry, (type & GV_BOUNDARY)); if (OGR_G_GetCoordinateDimension(Ogr_geometry) > 2) input3d = 1; -#if GDAL_VERSION_NUM >= 2000000 OGR_G_DestroyGeometry(Ogr_geometry); -#endif } -#if GDAL_VERSION_NUM >= 1110000 } -#endif OGR_F_Destroy(Ogr_feature); } G_percent(1, 1, 1); @@ -977,7 +908,7 @@ int main(int argc, char *argv[]) key_column[layer] = GV_KEY_COLUMN; key_idx[layer] = -2; /* -1 for fid column */ layer_id = layers[layer]; - Ogr_layer = ds_getlayerbyindex(Ogr_ds, layer_id); + Ogr_layer = GDALDatasetGetLayer(Ogr_ds, layer_id); Ogr_featuredefn = OGR_L_GetLayerDefn(Ogr_layer); if (param.key->answer) { @@ -1003,11 +934,7 @@ int main(int argc, char *argv[]) Ogr_field = OGR_FD_GetFieldDefn(Ogr_featuredefn, key_idx[layer]); Ogr_ftype = OGR_Fld_GetType(Ogr_field); - if (!(Ogr_ftype == OFTInteger -#if GDAL_VERSION_NUM >= 2000000 - || Ogr_ftype == OFTInteger64 -#endif - )) { + if (!(Ogr_ftype == OFTInteger || Ogr_ftype == OFTInteger64)) { G_fatal_error( _("Key column '%s' in input layer <%s> is not integer"), param.key->answer, layer_names[layer]); @@ -1114,7 +1041,6 @@ int main(int argc, char *argv[]) if (Ogr_ftype == OFTInteger) { col_info[i_out].type = "integer"; } -#if GDAL_VERSION_NUM >= 2000000 else if (Ogr_ftype == OFTInteger64) { if (strcmp(Fi->driver, "pg") == 0) col_info[i_out].type = "bigint"; @@ -1126,12 +1052,8 @@ int main(int argc, char *argv[]) Ogr_fieldname); } } -#endif - else if (Ogr_ftype == OFTIntegerList -#if GDAL_VERSION_NUM >= 2000000 - || Ogr_ftype == OFTInteger64List -#endif - ) { + else if (Ogr_ftype == OFTIntegerList || + Ogr_ftype == OFTInteger64List) { /* hack: treat as string */ sprintf(buf, "varchar ( %d )", OFTIntegerListlength); col_info[i_out].type = G_store(buf); @@ -1141,7 +1063,6 @@ int main(int argc, char *argv[]) } else if (Ogr_ftype == OFTReal) { col_info[i_out].type = "double precision"; -#if GDAL_VERSION_NUM >= 1320 } else if (Ogr_ftype == OFTDate) { col_info[i_out].type = "date"; @@ -1152,7 +1073,6 @@ int main(int argc, char *argv[]) else if (Ogr_ftype == OFTDateTime) { sprintf(buf, "%s", datetime_type); col_info[i_out].type = G_store(buf); -#endif } else if (Ogr_ftype == OFTString) { int fwidth; @@ -1294,15 +1214,13 @@ int main(int argc, char *argv[]) db_begin_transaction(driver); } - Ogr_layer = ds_getlayerbyindex(Ogr_ds, layer_id); + Ogr_layer = GDALDatasetGetLayer(Ogr_ds, layer_id); Ogr_featuredefn = OGR_L_GetLayerDefn(Ogr_layer); igeom = -1; -#if GDAL_VERSION_NUM >= 1110000 if (param.geom->answer) igeom = OGR_FD_GetGeomFieldIndex(Ogr_featuredefn, param.geom->answer); -#endif while ((Ogr_feature = ogr_getnextfeature( &OGR_iter, layer_id, layer_names[layer], @@ -1324,7 +1242,6 @@ int main(int argc, char *argv[]) /* Geometry */ Ogr_featuredefn = OGR_iter.Ogr_featuredefn; -#if GDAL_VERSION_NUM >= 1110000 for (i = 0; i < OGR_FD_GetGeomFieldCount(Ogr_featuredefn); i++) { if (igeom > -1 && i != igeom) continue; /* use only geometry defined via param.geom */ @@ -1332,9 +1249,6 @@ int main(int argc, char *argv[]) /* Ogr_geometry from OGR_F_GetGeomFieldRef() should not be * modified. */ Ogr_geometry = OGR_F_GetGeomFieldRef(Ogr_feature, i); -#else - Ogr_geometry = OGR_F_GetGeometryRef(Ogr_feature); -#endif if (Ogr_geometry == NULL) { nogeom++; } @@ -1348,9 +1262,7 @@ int main(int argc, char *argv[]) geom(Ogr_geometry, Out, layer + 1, cat, min_area, type, flag.no_clean->answer); } -#if GDAL_VERSION_NUM >= 1110000 } -#endif /* Attributes */ ncols = OGR_FD_GetFieldCount(Ogr_featuredefn); if (!flag.notab->answer) { @@ -1369,14 +1281,10 @@ int main(int argc, char *argv[]) Ogr_fstring = OGR_F_GetFieldAsString(Ogr_feature, i); if (Ogr_fstring && *Ogr_fstring) { if (Ogr_ftype == OFTInteger || -#if GDAL_VERSION_NUM >= 2000000 - Ogr_ftype == OFTInteger64 || -#endif - Ogr_ftype == OFTReal) { + Ogr_ftype == OFTInteger64 || Ogr_ftype == OFTReal) { G_rasprintf(&sqlbuf, &sqlbufsize, ", %s", Ogr_fstring); } -#if GDAL_VERSION_NUM >= 1320 /* should we use OGR_F_GetFieldAsDateTime() here ? */ else if (Ogr_ftype == OFTDate || Ogr_ftype == OFTTime || Ogr_ftype == OFTDateTime) { @@ -1392,14 +1300,10 @@ int main(int argc, char *argv[]) G_rasprintf(&sqlbuf, &sqlbufsize, "%s", newbuf); G_free(newbuf); } -#endif else if (Ogr_ftype == OFTString || Ogr_ftype == OFTStringList || - Ogr_ftype == OFTIntegerList -#if GDAL_VERSION_NUM >= 2000000 - || Ogr_ftype == OFTInteger64List -#endif - ) { + Ogr_ftype == OFTIntegerList || + Ogr_ftype == OFTInteger64List) { db_set_string(&strval, (char *)Ogr_fstring); db_double_quote_string(&strval); G_rasprintf(&sqlbuf, &sqlbufsize, ", '%s'", @@ -1414,25 +1318,17 @@ int main(int argc, char *argv[]) else { /* G_warning (_("Column value not set" )); */ if (Ogr_ftype == OFTInteger || -#if GDAL_VERSION_NUM >= 2000000 - Ogr_ftype == OFTInteger64 || -#endif - Ogr_ftype == OFTReal) { + Ogr_ftype == OFTInteger64 || Ogr_ftype == OFTReal) { G_rasprintf(&sqlbuf, &sqlbufsize, ", NULL"); } -#if GDAL_VERSION_NUM >= 1320 else if (Ogr_ftype == OFTDate || Ogr_ftype == OFTTime || Ogr_ftype == OFTDateTime) { G_rasprintf(&sqlbuf, &sqlbufsize, ", NULL"); } -#endif else if (Ogr_ftype == OFTString || Ogr_ftype == OFTStringList || - Ogr_ftype == OFTIntegerList -#if GDAL_VERSION_NUM >= 2000000 - || Ogr_ftype == OFTInteger64List -#endif - ) { + Ogr_ftype == OFTIntegerList || + Ogr_ftype == OFTInteger64List) { G_rasprintf(&sqlbuf, &sqlbufsize, ", NULL"); } else { @@ -1657,15 +1553,13 @@ int main(int argc, char *argv[]) G_message(_("Finding centroids for OGR layer <%s>..."), layer_names[layer]); layer_id = layers[layer]; - Ogr_layer = ds_getlayerbyindex(Ogr_ds, layer_id); + Ogr_layer = GDALDatasetGetLayer(Ogr_ds, layer_id); Ogr_featuredefn = OGR_L_GetLayerDefn(Ogr_layer); igeom = -1; -#if GDAL_VERSION_NUM >= 1110000 if (param.geom->answer) igeom = OGR_FD_GetGeomFieldIndex(Ogr_featuredefn, param.geom->answer); -#endif cat = 0; /* field = layer + 1 */ feature_count = 0; @@ -1705,7 +1599,6 @@ int main(int argc, char *argv[]) } /* Geometry */ -#if GDAL_VERSION_NUM >= 1110000 Ogr_featuredefn = OGR_iter.Ogr_featuredefn; for (i = 0; i < OGR_FD_GetGeomFieldCount(Ogr_featuredefn); i++) { @@ -1713,16 +1606,11 @@ int main(int argc, char *argv[]) continue; /* use only geometry defined via param.geom */ Ogr_geometry = OGR_F_GetGeomFieldRef(Ogr_feature, i); -#else - Ogr_geometry = OGR_F_GetGeometryRef(Ogr_feature); -#endif if (Ogr_geometry != NULL) { centroid(Ogr_geometry, Centr, &si, layer + 1, area_cat, min_area, type); } -#if GDAL_VERSION_NUM >= 1110000 } -#endif OGR_F_Destroy(Ogr_feature); } /* search tree is no longer needed */ @@ -1804,7 +1692,7 @@ int main(int argc, char *argv[]) G_message("%s", separator); } - ds_close(Ogr_ds); + GDALClose(Ogr_ds); G_free(fid_cat_tree); if (use_tmp_vect) { @@ -2098,8 +1986,8 @@ int main(int argc, char *argv[]) exit(EXIT_SUCCESS); } -void OGR_iterator_init(struct OGR_iterator *OGR_iter, ds_t Ogr_ds, char *dsn, - int nlayers, int ogr_interleaved_reading) +void OGR_iterator_init(struct OGR_iterator *OGR_iter, GDALDatasetH Ogr_ds, + char *dsn, int nlayers, int ogr_interleaved_reading) { OGR_iter->Ogr_ds = Ogr_ds; OGR_iter->dsn = dsn; @@ -2112,25 +2000,16 @@ void OGR_iterator_init(struct OGR_iterator *OGR_iter, ds_t Ogr_ds, char *dsn, OGR_iter->done = 0; if (OGR_iter->ogr_interleaved_reading) { -#if GDAL_VERSION_NUM >= 2020000 G_verbose_message(_("Using GDAL 2.2+ style interleaved reading for " "GDAL version %d.%d.%d"), GDAL_VERSION_MAJOR, GDAL_VERSION_MINOR, GDAL_VERSION_REV); -#else - G_verbose_message(_("Using GDAL 1.x style interleaved reading for GDAL " - "version %d.%d.%d"), - GDAL_VERSION_MAJOR, GDAL_VERSION_MINOR, - GDAL_VERSION_REV); -#endif } } void OGR_iterator_reset(struct OGR_iterator *OGR_iter) { -#if GDAL_VERSION_NUM >= 2020000 GDALDatasetResetReading(OGR_iter->Ogr_ds); -#endif OGR_iter->requested_layer = -1; OGR_iter->curr_layer = -1; OGR_iter->Ogr_layer = NULL; @@ -2148,7 +2027,7 @@ OGRFeatureH ogr_getnextfeature(struct OGR_iterator *OGR_iter, int layer, if (!OGR_iter->ogr_interleaved_reading) { OGR_iter->curr_layer = layer; OGR_iter->Ogr_layer = - ds_getlayerbyindex(OGR_iter->Ogr_ds, OGR_iter->curr_layer); + GDALDatasetGetLayer(OGR_iter->Ogr_ds, OGR_iter->curr_layer); OGR_iter->Ogr_featuredefn = OGR_L_GetLayerDefn(OGR_iter->Ogr_layer); OGR_L_ResetReading(OGR_iter->Ogr_layer); } @@ -2157,36 +2036,19 @@ OGRFeatureH ogr_getnextfeature(struct OGR_iterator *OGR_iter, int layer, /* clear filters */ for (i = 0; i < OGR_iter->nlayers; i++) { - OGR_iter->Ogr_layer = ds_getlayerbyindex(OGR_iter->Ogr_ds, i); + OGR_iter->Ogr_layer = GDALDatasetGetLayer(OGR_iter->Ogr_ds, i); OGR_L_SetSpatialFilter(OGR_iter->Ogr_layer, NULL); OGR_L_SetAttributeFilter(OGR_iter->Ogr_layer, NULL); } -#if GDAL_VERSION_NUM >= 2020000 GDALDatasetResetReading(OGR_iter->Ogr_ds); -#else - /* need to re-open OGR DSN in order to start reading from the - * beginning NOTE: any constraints are lost */ - OGR_DS_Destroy(OGR_iter->Ogr_ds); - OGR_iter->Ogr_ds = OGROpen(OGR_iter->dsn, FALSE, NULL); - if (OGR_iter->Ogr_ds == NULL) - G_fatal_error(_("Unable to re-open data source <%s>"), - OGR_iter->dsn); - OGR_iter->Ogr_layer = OGR_DS_GetLayer(OGR_iter->Ogr_ds, layer); - OGR_iter->curr_layer = 0; - OGR_iter->has_nonempty_layers = 0; -#endif - OGR_iter->Ogr_layer = ds_getlayerbyindex(OGR_iter->Ogr_ds, layer); + OGR_iter->Ogr_layer = GDALDatasetGetLayer(OGR_iter->Ogr_ds, layer); OGR_iter->Ogr_featuredefn = OGR_L_GetLayerDefn(OGR_iter->Ogr_layer); OGR_L_SetSpatialFilter(OGR_iter->Ogr_layer, poSpatialFilter); if (OGR_L_SetAttributeFilter(OGR_iter->Ogr_layer, attr_filter) != OGRERR_NONE) G_fatal_error(_("Error setting attribute filter '%s'"), attr_filter); -#if GDAL_VERSION_NUM < 2020000 - OGR_iter->Ogr_layer = - OGR_DS_GetLayer(OGR_iter->Ogr_ds, OGR_iter->curr_layer); -#endif } OGR_iter->requested_layer = layer; OGR_iter->done = 0; @@ -2210,7 +2072,6 @@ OGRFeatureH ogr_getnextfeature(struct OGR_iterator *OGR_iter, int layer, OGRFeatureH Ogr_feature = NULL; /* fetch next feature */ -#if GDAL_VERSION_NUM >= 2020000 while (1) { OGR_iter->Ogr_layer = NULL; Ogr_feature = GDALDatasetGetNextFeature( @@ -2233,44 +2094,12 @@ OGRFeatureH ogr_getnextfeature(struct OGR_iterator *OGR_iter, int layer, OGR_F_Destroy(Ogr_feature); OGR_iter->Ogr_layer = NULL; } -#else - while (1) { - Ogr_feature = OGR_L_GetNextFeature(OGR_iter->Ogr_layer); - if (Ogr_feature != NULL) { - OGR_iter->has_nonempty_layers = 1; - if (OGR_iter->curr_layer != layer) - OGR_F_Destroy(Ogr_feature); - else - return Ogr_feature; - } - else { - OGR_iter->curr_layer++; - if (OGR_iter->curr_layer == OGR_iter->nlayers) { - if (!OGR_iter->has_nonempty_layers) { - OGR_iter->Ogr_layer = NULL; - OGR_iter->done = 1; - - return NULL; - } - else { - OGR_iter->curr_layer = 0; - OGR_iter->has_nonempty_layers = 0; - } - } - G_debug(3, "advancing to layer %d ...", OGR_iter->curr_layer); - OGR_iter->Ogr_layer = - OGR_DS_GetLayer(OGR_iter->Ogr_ds, OGR_iter->curr_layer); - OGR_iter->Ogr_featuredefn = - OGR_L_GetLayerDefn(OGR_iter->Ogr_layer); - } - } -#endif } return NULL; } -int create_spatial_filter(ds_t Ogr_ds, OGRGeometryH *poSpatialFilter, +int create_spatial_filter(GDALDatasetH Ogr_ds, OGRGeometryH *poSpatialFilter, int nlayers, int *layers, char **layer_names, double *xmin, double *ymin, double *xmax, double *ymax, int use_region, struct Option *spat) @@ -2292,7 +2121,7 @@ int create_spatial_filter(ds_t Ogr_ds, OGRGeometryH *poSpatialFilter, ymaxl = (double *)G_malloc(nlayers * sizeof(double)); for (layer = 0; layer < nlayers; layer++) { - Ogr_layer = ds_getlayerbyindex(Ogr_ds, layers[layer]); + Ogr_layer = GDALDatasetGetLayer(Ogr_ds, layers[layer]); have_ogr_extent[layer] = 0; if ((OGR_L_GetExtent(Ogr_layer, &oExt, 1)) == OGRERR_NONE) { xminl[layer] = oExt.MinX; @@ -2327,11 +2156,7 @@ int create_spatial_filter(ds_t Ogr_ds, OGRGeometryH *poSpatialFilter, /* OGR_L_GetExtent(): * Note that some implementations of this method may alter * the read cursor of the layer. */ -#if GDAL_VERSION_NUM >= 2020000 GDALDatasetResetReading(Ogr_ds); -#else - OGR_L_ResetReading(Ogr_layer); -#endif } /* set spatial filter */ diff --git a/vector/v.in.ogr/proj.c b/vector/v.in.ogr/proj.c index 4ddbe546384..ad7b6363c4f 100644 --- a/vector/v.in.ogr/proj.c +++ b/vector/v.in.ogr/proj.c @@ -24,7 +24,6 @@ int get_layer_proj(OGRLayerH Ogr_layer, struct Cell_head *cellhd, *proj_wkt = NULL; /* Fetch input layer projection in GRASS form. */ -#if GDAL_VERSION_NUM >= 1110000 if (geom_col) { int igeom; OGRGeomFieldDefnH Ogr_geomdefn; @@ -42,9 +41,6 @@ int get_layer_proj(OGRLayerH Ogr_layer, struct Cell_head *cellhd, else { hSRS = OGR_L_GetSpatialRef(Ogr_layer); } -#else - hSRS = OGR_L_GetSpatialRef(Ogr_layer); /* should not be freed later */ -#endif /* verbose is used only when comparing input SRS to GRASS projection, * not when comparing SRS's of several input layers */ @@ -133,8 +129,8 @@ int get_layer_proj(OGRLayerH Ogr_layer, struct Cell_head *cellhd, /* compare projections of all OGR layers * return 0 if all layers have the same projection * return 1 if layer projections differ */ -int cmp_layer_srs(ds_t Ogr_ds, int nlayers, int *layers, char **layer_names, - char *geom_col) +int cmp_layer_srs(GDALDatasetH Ogr_ds, int nlayers, int *layers, + char **layer_names, char *geom_col) { int layer; struct Key_Value *proj_info1, *proj_units1; @@ -156,7 +152,7 @@ int cmp_layer_srs(ds_t Ogr_ds, int nlayers, int *layers, char **layer_names, layer = 0; do { /* Get first SRS */ - Ogr_layer = ds_getlayerbyindex(Ogr_ds, layers[layer]); + Ogr_layer = GDALDatasetGetLayer(Ogr_ds, layers[layer]); if (get_layer_proj(Ogr_layer, &cellhd1, &proj_info1, &proj_units1, &proj_srid1, &proj_wkt1, geom_col, 0) == 0) { @@ -201,7 +197,7 @@ int cmp_layer_srs(ds_t Ogr_ds, int nlayers, int *layers, char **layer_names, for (layer = 1; layer < nlayers; layer++) { /* Get SRS of other layer(s) */ - Ogr_layer = ds_getlayerbyindex(Ogr_ds, layers[layer]); + Ogr_layer = GDALDatasetGetLayer(Ogr_ds, layers[layer]); G_get_window(&cellhd2); if (get_layer_proj(Ogr_layer, &cellhd2, &proj_info2, &proj_units2, &proj_srid2, &proj_wkt2, geom_col, 0) != 0) { @@ -265,7 +261,7 @@ int cmp_layer_srs(ds_t Ogr_ds, int nlayers, int *layers, char **layer_names, } /* keep in sync with r.in.gdal, r.external, v.external */ -void check_projection(struct Cell_head *cellhd, ds_t hDS, int layer, +void check_projection(struct Cell_head *cellhd, GDALDatasetH hDS, int layer, char *geom_col, char *outloc, int create_only, int override, int check_only) { @@ -278,7 +274,7 @@ void check_projection(struct Cell_head *cellhd, ds_t hDS, int layer, OGRLayerH Ogr_layer; /* Get first layer to be imported to use for projection check */ - Ogr_layer = ds_getlayerbyindex(hDS, layer); + Ogr_layer = GDALDatasetGetLayer(hDS, layer); /* -------------------------------------------------------------------- */ /* Fetch the projection in GRASS form, SRID, and WKT. */ @@ -317,7 +313,7 @@ void check_projection(struct Cell_head *cellhd, ds_t hDS, int layer, /* If create only, clean up and exit here */ if (create_only) { - ds_close(hDS); + GDALClose(hDS); exit(EXIT_SUCCESS); } } @@ -339,7 +335,7 @@ void check_projection(struct Cell_head *cellhd, ds_t hDS, int layer, } else { msg_fn = G_fatal_error; - ds_close(hDS); + GDALClose(hDS); } msg_fn(error_msg); if (!override) { @@ -506,7 +502,7 @@ void check_projection(struct Cell_head *cellhd, ds_t hDS, int layer, msg_fn = G_fatal_error; msg_fn("%s", error_msg); if (check_only) { - ds_close(hDS); + GDALClose(hDS); exit(EXIT_FAILURE); } } @@ -518,7 +514,7 @@ void check_projection(struct Cell_head *cellhd, ds_t hDS, int layer, msg_fn(_("Projection of input dataset and current location " "appear to match")); if (check_only) { - ds_close(hDS); + GDALClose(hDS); exit(EXIT_SUCCESS); } } diff --git a/vector/v.out.ogr/attrb.c b/vector/v.out.ogr/attrb.c index fdcdf72c6b7..4992018eb95 100644 --- a/vector/v.out.ogr/attrb.c +++ b/vector/v.out.ogr/attrb.c @@ -98,11 +98,7 @@ int mk_att(int cat, struct field_info *Fi, dbDriver *driver, int ncol, if ((nocat && strcmp(Fi->key, colname[j]) == 0) == 0) { /* if this is 'cat', then execute the following only if * the '-s' flag was NOT given */ -#if GDAL_VERSION_NUM >= 2020000 OGR_F_SetFieldNull(Ogr_feature, ogrfieldnum); -#else - OGR_F_UnsetField(Ogr_feature, ogrfieldnum); -#endif } /* prevent writing NULL values */ @@ -135,10 +131,8 @@ int mk_att(int cat, struct field_info *Fi, dbDriver *driver, int ncol, } } } -#if GDAL_VERSION_NUM >= 2020000 else OGR_F_SetFieldNull(Ogr_feature, ogrfieldnum); -#endif } } db_close_cursor(&cursor); diff --git a/vector/v.out.ogr/create.c b/vector/v.out.ogr/create.c index d6adfdec474..fa0bbe10f52 100644 --- a/vector/v.out.ogr/create.c +++ b/vector/v.out.ogr/create.c @@ -6,25 +6,21 @@ void create_ogr_layer(const char *dsn, const char *format, const char *layer, unsigned int wkbtype, char **papszDSCO, char **papszLCO) { char *pszDriverName; - dr_t hDriver; - ds_t hDS; + GDALDriverH hDriver; + GDALDatasetH hDS; OGRLayerH hLayer; pszDriverName = G_store(format); G_strchg(pszDriverName, '_', ' '); /* '_' -> ' ' */ /* start driver */ - hDriver = get_driver_by_name(pszDriverName); + hDriver = GDALGetDriverByName(pszDriverName); if (hDriver == NULL) { G_fatal_error(_("OGR driver <%s> not available"), pszDriverName); } /* create datasource */ -#if GDAL_VERSION_NUM >= 2020000 hDS = GDALCreate(hDriver, dsn, 0, 0, 0, GDT_Unknown, papszDSCO); -#else - hDS = OGR_Dr_CreateDataSource(hDriver, dsn, papszDSCO); -#endif if (hDS == NULL) { G_fatal_error(_("Creation of output OGR datasource <%s> failed"), dsn); } @@ -33,16 +29,12 @@ void create_ogr_layer(const char *dsn, const char *format, const char *layer, /* create layer */ /* todo: SRS */ -#if GDAL_VERSION_NUM >= 2020000 hLayer = GDALDatasetCreateLayer(hDS, layer, NULL, wkbtype, papszLCO); -#else - hLayer = OGR_DS_CreateLayer(hDS, layer, NULL, wkbtype, papszLCO); -#endif if (hLayer == NULL) { G_fatal_error(_("Creation of OGR layer <%s> failed"), layer); } - ds_close(hDS); + GDALClose(hDS); } OGRwkbGeometryType get_multi_wkbtype(OGRwkbGeometryType wkbtype) diff --git a/vector/v.out.ogr/list.c b/vector/v.out.ogr/list.c index 6ced3ba4f19..0df74cf5dac 100644 --- a/vector/v.out.ogr/list.c +++ b/vector/v.out.ogr/list.c @@ -10,11 +10,7 @@ char *OGR_list_write_drivers(void) int i, count; size_t len; -#if GDAL_VERSION_NUM >= 2000000 GDALDriverH hDriver; -#else - OGRSFDriverH Ogr_driver; -#endif char buf[2000]; char **list, *ret; @@ -22,7 +18,6 @@ char *OGR_list_write_drivers(void) list = NULL; count = len = 0; -#if GDAL_VERSION_NUM >= 2000000 /* get GDAL driver names */ GDALAllRegister(); G_debug(2, "driver count = %d", GDALGetDriverCount()); @@ -47,28 +42,6 @@ char *OGR_list_write_drivers(void) list[count++] = G_store(buf); len += strlen(buf) + 1; /* + ',' */ } -#else - /* get OGR driver names */ - OGRRegisterAll(); - G_debug(2, "driver count = %d", OGRGetDriverCount()); - for (i = 0; i < OGRGetDriverCount(); i++) { - /* only fetch read/write drivers */ - if (!OGR_Dr_TestCapability(OGRGetDriver(i), ODrCCreateDataSource)) - continue; - - Ogr_driver = OGRGetDriver(i); - G_debug(2, "driver %d/%d : %s", i, OGRGetDriverCount(), - OGR_Dr_GetName(Ogr_driver)); - - list = G_realloc(list, (count + 1) * sizeof(char *)); - - /* chg white space to underscore in OGR driver names */ - sprintf(buf, "%s", OGR_Dr_GetName(Ogr_driver)); - G_strchg(buf, ' ', '_'); - list[count++] = G_store(buf); - len += strlen(buf) + 1; /* + ',' */ - } -#endif qsort(list, count, sizeof(char *), cmp); @@ -99,11 +72,7 @@ int cmp(const void *a, const void *b) char *default_driver(void) { -#if GDAL_VERSION_NUM >= 2000000 if (GDALGetDriverByName("GPKG")) { -#else - if (OGRGetDriverByName("GPKG")) { -#endif return G_store("GPKG"); } @@ -116,7 +85,6 @@ void list_formats(void) G_message(_("Supported formats:")); -#if GDAL_VERSION_NUM >= 2000000 for (iDriver = 0; iDriver < GDALGetDriverCount(); iDriver++) { GDALDriverH hDriver = GDALGetDriver(iDriver); const char *pszRWFlag; @@ -134,19 +102,4 @@ void list_formats(void) fprintf(stdout, " %s (%s): %s\n", GDALGetDriverShortName(hDriver), pszRWFlag, GDALGetDriverLongName(hDriver)); } - -#else - for (iDriver = 0; iDriver < OGRGetDriverCount(); iDriver++) { - OGRSFDriverH poDriver = OGRGetDriver(iDriver); - const char *pszRWFlag; - - if (OGR_Dr_TestCapability(poDriver, ODrCCreateDataSource)) - pszRWFlag = "rw"; - else - continue; - - fprintf(stdout, " %s (%s): %s\n", OGR_Dr_GetName(poDriver), pszRWFlag, - OGR_Dr_GetName(poDriver)); - } -#endif } diff --git a/vector/v.out.ogr/local_proto.h b/vector/v.out.ogr/local_proto.h index 7ed25a5170c..a0406a350a1 100644 --- a/vector/v.out.ogr/local_proto.h +++ b/vector/v.out.ogr/local_proto.h @@ -7,25 +7,6 @@ #include #include -/* switch to new GDAL API with GDAL 2.2+ */ -#if GDAL_VERSION_NUM >= 2020000 -typedef GDALDatasetH ds_t; -typedef GDALDriverH dr_t; - -#define get_driver_by_name GDALGetDriverByName -#define get_driver GDALGetDriver -#define ds_getlayerbyindex(ds, i) GDALDatasetGetLayer((ds), (i)) -#define ds_close(ds) GDALClose(ds) -#else -typedef OGRDataSourceH ds_t; -typedef OGRSFDriverH dr_t; - -#define get_driver_by_name OGRGetDriverByName -#define get_driver OGRGetDriver -#define ds_getlayerbyindex(ds, i) OGR_DS_GetLayer((ds), (i)) -#define ds_close(ds) OGR_DS_Destroy(ds) -#endif - /* some hard limits */ #define SQL_BUFFER_SIZE 2000 diff --git a/vector/v.out.ogr/main.c b/vector/v.out.ogr/main.c index 1c4c554ab51..613463c8d84 100644 --- a/vector/v.out.ogr/main.c +++ b/vector/v.out.ogr/main.c @@ -64,8 +64,8 @@ int main(int argc, char *argv[]) /* OGR */ int drn; OGRFieldType ogr_ftype = OFTInteger; - ds_t hDS; - dr_t hDriver; + GDALDatasetH hDS; + GDALDriverH hDriver; OGRLayerH Ogr_layer; OGRFieldDefnH Ogr_field; OGRFeatureDefnH Ogr_featuredefn; @@ -514,7 +514,6 @@ int main(int argc, char *argv[]) G_debug(1, "Requested to export %d features", num_to_export); /* Open OGR DSN */ -#if GDAL_VERSION_NUM >= 2020000 G_debug(2, "driver count = %d", GDALGetDriverCount()); drn = -1; for (i = 0; i < GDALGetDriverCount(); i++) { @@ -528,28 +527,12 @@ int main(int argc, char *argv[]) G_debug(2, " -> driver = %d", drn); } } -#else - G_debug(2, "driver count = %d", OGRGetDriverCount()); - drn = -1; - for (i = 0; i < OGRGetDriverCount(); i++) { - hDriver = OGRGetDriver(i); - G_debug(2, "driver %d : %s", i, OGR_Dr_GetName(hDriver)); - /* chg white space to underscore in OGR driver names */ - sprintf(buf, "%s", OGR_Dr_GetName(hDriver)); - G_strchg(buf, ' ', '_'); - if (strcmp(buf, options.format->answer) == 0) { - drn = i; - G_debug(2, " -> driver = %d", drn); - } - } -#endif if (drn == -1) G_fatal_error(_("OGR driver <%s> not found"), options.format->answer); - hDriver = get_driver(drn); + hDriver = GDALGetDriver(drn); if (flags.append->answer) { G_debug(1, "Append to OGR layer"); -#if GDAL_VERSION_NUM >= 2020000 hDS = GDALOpenEx(dsn, GDAL_OF_VECTOR | GDAL_OF_UPDATE, NULL, NULL, NULL); @@ -557,17 +540,8 @@ int main(int argc, char *argv[]) G_debug(1, "Create OGR data source"); hDS = GDALCreate(hDriver, dsn, 0, 0, 0, GDT_Unknown, papszDSCO); } -#else - hDS = OGR_Dr_Open(hDriver, dsn, TRUE); - - if (hDS == NULL) { - G_debug(1, "Create OGR data source"); - hDS = OGR_Dr_CreateDataSource(hDriver, dsn, papszDSCO); - } -#endif } else { -#if GDAL_VERSION_NUM >= 2020000 if (flags.update->answer) { G_debug(1, "Update OGR data source"); hDS = GDALOpenEx(dsn, GDAL_OF_VECTOR | GDAL_OF_UPDATE, NULL, NULL, @@ -577,16 +551,6 @@ int main(int argc, char *argv[]) G_debug(1, "Create OGR data source"); hDS = GDALCreate(hDriver, dsn, 0, 0, 0, GDT_Unknown, papszDSCO); } -#else - if (flags.update->answer) { - G_debug(1, "Update OGR data source"); - hDS = OGR_Dr_Open(hDriver, dsn, TRUE); - } - else { - G_debug(1, "Create OGR data source"); - hDS = OGR_Dr_CreateDataSource(hDriver, dsn, papszDSCO); - } -#endif } CSLDestroy(papszDSCO); @@ -597,14 +561,8 @@ int main(int argc, char *argv[]) /* check if OGR layer exists */ overwrite = G_check_overwrite(argc, argv); found = FALSE; -#if GDAL_VERSION_NUM >= 2020000 for (i = 0; i < GDALDatasetGetLayerCount(hDS); i++) { Ogr_layer = GDALDatasetGetLayer(hDS, i); -#else - for (i = 0; i < OGR_DS_GetLayerCount(hDS); i++) { - Ogr_layer = OGR_DS_GetLayer(hDS, i); - -#endif Ogr_field = OGR_L_GetLayerDefn(Ogr_layer); if (G_strcasecmp(OGR_FD_GetName(Ogr_field), options.layer->answer)) continue; @@ -619,11 +577,7 @@ int main(int argc, char *argv[]) G_warning( _("OGR layer <%s> already exists and will be overwritten"), options.layer->answer); -#if GDAL_VERSION_NUM >= 2020000 GDALDatasetDeleteLayer(hDS, i); -#else - OGR_DS_DeleteLayer(hDS, i); -#endif break; } } @@ -704,19 +658,11 @@ int main(int argc, char *argv[]) } G_debug(1, "Create OGR layer"); -#if GDAL_VERSION_NUM >= 2020000 if (flags.append->answer) Ogr_layer = GDALDatasetGetLayerByName(hDS, options.layer->answer); else Ogr_layer = GDALDatasetCreateLayer(hDS, options.layer->answer, Ogr_projection, wkbtype, papszLCO); -#else - if (flags.append->answer) - Ogr_layer = OGR_DS_GetLayerByName(hDS, options.layer->answer); - else - Ogr_layer = OGR_DS_CreateLayer(hDS, options.layer->answer, - Ogr_projection, wkbtype, papszLCO); -#endif CSLDestroy(papszLCO); if (Ogr_layer == NULL) { @@ -800,11 +746,7 @@ int main(int argc, char *argv[]) ogr_ftype = OFTString; break; case DB_C_TYPE_DATETIME: -#if GDAL_VERSION_NUM >= 1320 ogr_ftype = OFTDateTime; -#else - ogr_ftype = OFTString; -#endif break; } G_debug(2, "ogr_ftype = %d", ogr_ftype); @@ -918,7 +860,7 @@ int main(int argc, char *argv[]) } } - ds_close(hDS); + GDALClose(hDS); Vect_close(&In);