From 64b48284cb945c144ff389be9c660c8ec6bab0e3 Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Wed, 15 Feb 2012 21:37:41 +0000 Subject: [PATCH] shp2pgsql: a switch to drop M from 4d imports (#900) git-svn-id: http://svn.osgeo.org/postgis/trunk@9204 b70326c6-7e19-0410-871a-916f4a2858ee --- loader/shp2pgsql-cli.c | 24 +++++++++++++++++++++++- loader/shp2pgsql-core.c | 10 ++++++++++ loader/shp2pgsql-core.h | 4 ++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/loader/shp2pgsql-cli.c b/loader/shp2pgsql-cli.c index 987288e3d..c61960d69 100644 --- a/loader/shp2pgsql-cli.c +++ b/loader/shp2pgsql-cli.c @@ -45,6 +45,7 @@ usage() printf(_( " -i Use int4 type for all integer dbf fields.\n" )); printf(_( " -I Create a spatial index on the geocolumn.\n" )); printf(_( " -S Generate simple geometries instead of MULTI geometries.\n" )); + printf(_( " -t Force geometry to be one of '2D', '3DZ', '3DM', or '4D'\n" )); printf(_( " -w Output WKT instead of WKB. Note that this can result in\n" " coordinate drift.\n" )); printf(_( " -W Specify the character encoding of Shape's\n" @@ -88,7 +89,7 @@ main (int argc, char **argv) set_loader_config_defaults(config); /* Keep the flag list alphabetic so it's easy to see what's left. */ - while ((c = pgis_getopt(argc, argv, "acdeg:iknps:wDGIN:ST:W:X:")) != EOF) + while ((c = pgis_getopt(argc, argv, "acdeg:iknps:t:wDGIN:ST:W:X:")) != EOF) { switch (c) { @@ -195,6 +196,27 @@ main (int argc, char **argv) } break; + case 't': + if ( strcasecmp(pgis_optarg,"2D") == 0 ) + { + config->want_z = config->want_m = 0; + } + else if ( strcasecmp(pgis_optarg,"3DZ") == 0 ) + { + config->want_z = 1; + config->want_m = 0; + } + else if ( strcasecmp(pgis_optarg,"3DM") == 0 ) + { + config->want_z = 0; + config->want_m = 1; + } + else if ( strcasecmp(pgis_optarg,"4D") == 0 ) + { + config->want_z = config->want_m = 1; + } + break; + case 'T': config->tablespace = pgis_optarg; break; diff --git a/loader/shp2pgsql-core.c b/loader/shp2pgsql-core.c index 118a72a8a..96e7b3c4e 100644 --- a/loader/shp2pgsql-core.c +++ b/loader/shp2pgsql-core.c @@ -762,6 +762,8 @@ set_loader_config_defaults(SHPLOADERCONFIG *config) config->forceint4 = 0; config->createindex = 0; config->readshape = 1; + config->want_m = -1; + config->want_z = -1; config->encoding = strdup(ENCODING_DEFAULT); config->null_policy = POLICY_NULL_INSERT; config->sr_id = SRID_UNKNOWN; @@ -1004,6 +1006,14 @@ ShpLoaderOpenShape(SHPLOADERSTATE *state) break; } + + /* Force M-handling if configured to do so */ + if (state->config->want_m != -1) + state->has_m = state->config->want_m; + + /* Force Z-handling if configured to do so */ + if (state->config->want_z != -1) + state->has_z = state->config->want_z; /* If in simple geometry mode, alter names for CREATE TABLE by skipping MULTI */ if (state->config->simple_geometries) diff --git a/loader/shp2pgsql-core.h b/loader/shp2pgsql-core.h index e0d18fbab..c2cf008cf 100644 --- a/loader/shp2pgsql-core.h +++ b/loader/shp2pgsql-core.h @@ -112,6 +112,10 @@ typedef struct shp_loader_config /* 0 = load DBF file only, 1 = load everything */ int readshape; + /* 0 = load all coordinates, 1 = skip M dimension */ + int want_m; + int want_z; + /* iconv encoding name */ char *encoding; -- 2.40.0