Skip to content

Commit

Permalink
build: Remove compatibility with GDAL 1 and <2.2 (OSGeo#2995)
Browse files Browse the repository at this point in the history
This basically remove "dead code" since most modern distribution/packaging have GDAL 3.

Version of GDAL no longer supported: 1 and <2.3. Remove compatibility macros and use GDAL functions directly.

Fixes OSGeo#2645.
  • Loading branch information
lbartoletti authored and tmszi committed Dec 20, 2023
1 parent a654c3e commit e570802
Show file tree
Hide file tree
Showing 19 changed files with 67 additions and 583 deletions.
9 changes: 1 addition & 8 deletions db/drivers/ogr/describe.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 1 addition & 4 deletions db/drivers/ogr/execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions db/drivers/ogr/fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 0 additions & 19 deletions include/grass/defs/gis.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <gdal_version.h>
#if GDAL_VERSION_NUM < 2030000
#include <cpl_config.h>
/* 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);
Expand Down
108 changes: 0 additions & 108 deletions lib/vector/Vlib/field.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 */
}
Expand Down
7 changes: 0 additions & 7 deletions raster/r.in.gdal/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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";
Expand Down
11 changes: 0 additions & 11 deletions vector/v.external/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,19 +293,14 @@ 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) {
if (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;
Expand All @@ -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++) {
Expand All @@ -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);
Expand Down
19 changes: 2 additions & 17 deletions vector/v.external/local_proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,6 @@
#include <gdal_version.h>
#include <ogr_api.h>

/* 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;
};
Expand All @@ -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
8 changes: 2 additions & 6 deletions vector/v.external/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand Down Expand Up @@ -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);
Expand All @@ -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");
Expand Down
Loading

0 comments on commit e570802

Please sign in to comment.