Skip to content

Commit

Permalink
remove obsolete macros and use GDAL functions
Browse files Browse the repository at this point in the history
  • Loading branch information
lbartoletti committed Dec 7, 2023
1 parent 0c85778 commit 7ad2aff
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 66 deletions.
7 changes: 1 addition & 6 deletions vector/v.external/local_proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
#include <gdal_version.h>
#include <ogr_api.h>

typedef GDALDatasetH ds_t;

#define ds_getlayerbyindex(ds, i) GDALDatasetGetLayer((ds), (i))
#define ds_close(ds) GDALClose(ds)

struct _options {
struct Option *dsn, *output, *layer, *where;
};
Expand All @@ -30,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,
void check_projection(struct Cell_head *, GDALDatasetH, int, char *, char *, int, int,
int);
#endif
4 changes: 2 additions & 2 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 @@ -169,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
12 changes: 6 additions & 6 deletions vector/v.external/proj.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,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)
{
Expand All @@ -140,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. */
Expand Down Expand Up @@ -179,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);
}
}
Expand All @@ -201,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) {
Expand Down Expand Up @@ -370,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);
}
}
Expand All @@ -382,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);
}
}
Expand Down
4 changes: 0 additions & 4 deletions vector/v.in.ogr/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@
#include <gdal_version.h>
#include <ogr_api.h>

typedef GDALDatasetH ds_t;
#define ds_getlayerbyindex(ds, i) GDALDatasetGetLayer((ds), (i))
#define ds_close(ds) GDALClose(ds)

extern int n_polygons;
extern int n_polygon_boundaries;
extern double split_distance;
Expand Down
46 changes: 23 additions & 23 deletions vector/v.in.ogr/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 **,
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;
Expand All @@ -72,7 +72,7 @@ struct OGR_iterator {
int done;
};

void OGR_iterator_init(struct OGR_iterator *OGR_iter, ds_t Ogr_ds, char *dsn,
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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -598,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));

Expand All @@ -607,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);
}

Expand Down Expand Up @@ -645,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."));
}
Expand Down Expand Up @@ -684,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);
}

Expand Down Expand Up @@ -730,7 +730,7 @@ int main(int argc, char *argv[])
attr_filter) {

for (layer = 0; layer < nlayers; layer++) {
Ogr_layer = ds_getlayerbyindex(Ogr_ds, layers[layer]);
Ogr_layer = GDALDatasetGetLayer(Ogr_ds, layers[layer]);
if (param.geom->answer) {
Ogr_featuredefn = OGR_L_GetLayerDefn(Ogr_layer);
igeom = OGR_FD_GetGeomFieldIndex(Ogr_featuredefn,
Expand Down Expand Up @@ -780,7 +780,7 @@ 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 (param.geom->answer) {
Expand Down Expand Up @@ -908,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) {
Expand Down Expand Up @@ -1214,7 +1214,7 @@ 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;
Expand Down Expand Up @@ -1553,7 +1553,7 @@ 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;
Expand Down Expand Up @@ -1692,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) {
Expand Down Expand Up @@ -1986,7 +1986,7 @@ int main(int argc, char *argv[])
exit(EXIT_SUCCESS);
}

void OGR_iterator_init(struct OGR_iterator *OGR_iter, ds_t Ogr_ds, char *dsn,
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;
Expand Down Expand Up @@ -2027,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);
}
Expand All @@ -2036,13 +2036,13 @@ 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);
}

GDALDatasetResetReading(OGR_iter->Ogr_ds);
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) !=
Expand Down Expand Up @@ -2099,7 +2099,7 @@ OGRFeatureH ogr_getnextfeature(struct OGR_iterator *OGR_iter, int layer,
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)
Expand All @@ -2121,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;
Expand Down
18 changes: 9 additions & 9 deletions vector/v.in.ogr/proj.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ 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,
int cmp_layer_srs(GDALDatasetH Ogr_ds, int nlayers, int *layers, char **layer_names,
char *geom_col)
{
int layer;
Expand All @@ -152,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) {
Expand Down Expand Up @@ -197,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) {
Expand Down Expand Up @@ -261,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)
{
Expand All @@ -274,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. */
Expand Down Expand Up @@ -313,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);
}
}
Expand All @@ -335,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) {
Expand Down Expand Up @@ -502,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);
}
}
Expand All @@ -514,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);
}
}
Expand Down
Loading

0 comments on commit 7ad2aff

Please sign in to comment.