]> granicus.if.org Git - postgis/commitdiff
shp2pgsql: a switch to drop M from 4d imports (#900)
authorPaul Ramsey <pramsey@cleverelephant.ca>
Wed, 15 Feb 2012 21:37:41 +0000 (21:37 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Wed, 15 Feb 2012 21:37:41 +0000 (21:37 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@9204 b70326c6-7e19-0410-871a-916f4a2858ee

loader/shp2pgsql-cli.c
loader/shp2pgsql-core.c
loader/shp2pgsql-core.h

index 987288e3d08cfaa4bab0c10b7404cf89bb3324df..c61960d6904b97d92b49711902fc74d21d264213 100644 (file)
@@ -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 <dimensionality> 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 <encoding> 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;
index 118a72a8ac18eaaf4fadf0d8d4459c5bb5db54b0..96e7b3c4eded123f3b546f73dd1d4d25484bcf46 100644 (file)
@@ -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)
index e0d18fbab9cccc8c01f6d7eef31f5d2ccbd06a9f..c2cf008cfcc90d27e7c39510df5c768ee516f71a 100644 (file)
@@ -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;