]> granicus.if.org Git - postgis/commitdiff
Rework code from r9204 (bug #900: shp2pgsql: a switch to drop M from 4d imports)...
authorMark Cave-Ayland <mark.cave-ayland@siriusit.co.uk>
Mon, 26 Mar 2012 16:23:58 +0000 (16:23 +0000)
committerMark Cave-Ayland <mark.cave-ayland@siriusit.co.uk>
Mon, 26 Mar 2012 16:23:58 +0000 (16:23 +0000)
The original implementation set the has_z/has_m flags directly based upon the -t parameter; however this lost the information
as to how many dimensions were specified. Resolve this by specifying a new force_output configuration variable and setting
it to an enumerated constant, so that we can then implement a simple switch() to set both the output dimension and output
flags correctly.

git-svn-id: http://svn.osgeo.org/postgis/trunk@9548 b70326c6-7e19-0410-871a-916f4a2858ee

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

index 618d14f4e36df914c7ac488f57cf58897f3de040..d6021cb14b43b8d00ea83ec387463f08c49022ef 100644 (file)
@@ -197,23 +197,26 @@ main (int argc, char **argv)
                        break;
 
                case 't':
-                       if ( strcasecmp(pgis_optarg,"2D") == 0 )
+                       if (strcasecmp(pgis_optarg, "2D") == 0)
                        {
-                               config->want_z = config->want_m = 0;
+                               config->force_output = FORCE_OUTPUT_2D;
                        }
-                       else if ( strcasecmp(pgis_optarg,"3DZ") == 0 )
+                       else if (strcasecmp(pgis_optarg, "3DZ") == 0 )
                        {
-                               config->want_z = 1; 
-                               config->want_m = 0;
+                               config->force_output = FORCE_OUTPUT_3DZ;
                        }
-                       else if ( strcasecmp(pgis_optarg,"3DM") == 0 )
+                       else if (strcasecmp(pgis_optarg, "3DM") == 0 )
                        {
-                               config->want_z = 0; 
-                               config->want_m = 1;
+                               config->force_output = FORCE_OUTPUT_3DM;
                        }
-                       else if ( strcasecmp(pgis_optarg,"4D") == 0 )
+                       else if (strcasecmp(pgis_optarg, "4D") == 0 )
                        {
-                               config->want_z = config->want_m = 1;
+                               config->force_output = FORCE_OUTPUT_4D;
+                       }
+                       else
+                       {
+                               fprintf(stderr, "Unsupported output type: %s\nValid output types are 2D, 3DZ, 3DM and 4D\n", pgis_optarg);
+                               exit(1);
                        }
                        break;
 
index 9f8b1be84a26e62fafab2f8e0abbbc2fa54bb7a1..d563b82e122227df6c9d3603d42941be206c08ea 100644 (file)
@@ -762,8 +762,7 @@ set_loader_config_defaults(SHPLOADERCONFIG *config)
        config->forceint4 = 0;
        config->createindex = 0;
        config->readshape = 1;
-       config->want_m = -1;
-       config->want_z = -1;
+       config->force_output = FORCE_OUTPUT_DISABLE;
        config->encoding = strdup(ENCODING_DEFAULT);
        config->null_policy = POLICY_NULL_INSERT;
        config->sr_id = SRID_UNKNOWN;
@@ -1006,13 +1005,36 @@ 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/M-handling if configured to do so */
+               switch(state->config->force_output)
+               {
+               case FORCE_OUTPUT_2D:
+                       state->has_z = 0;
+                       state->has_m = 0;
+                       state->pgdims = 2;
+                       break;
+
+               case FORCE_OUTPUT_3DZ:
+                       state->has_z = 1;
+                       state->has_m = 0;
+                       state->pgdims = 3;
+                       break;
+
+               case FORCE_OUTPUT_3DM:
+                       state->has_z = 0;
+                       state->has_m = 1;
+                       state->pgdims = 3;
+                       break;
 
-               /* Force Z-handling if configured to do so */
-               if (state->config->want_z != -1)
-                       state->has_z = state->config->want_z;
+               case FORCE_OUTPUT_4D:
+                       state->has_z = 1;
+                       state->has_m = 1;
+                       state->pgdims = 4;
+                       break;
+               default:
+                       /* Simply use the auto-detected values above */
+                       break;
+               }
 
                /* If in simple geometry mode, alter names for CREATE TABLE by skipping MULTI */
                if (state->config->simple_geometries)
index 80621cb5a3861304dd3141555c714af88b2e3c62..34ae5b45160b4801fa342cb5b967d34591cdc8dc 100644 (file)
 #define POLICY_NULL_INSERT     0x1
 #define POLICY_NULL_SKIP       0x2
 
+/* Forced dimensionality constants */
+#define FORCE_OUTPUT_DISABLE   0x0
+#define FORCE_OUTPUT_2D                0x1
+#define FORCE_OUTPUT_3DZ       0x2
+#define FORCE_OUTPUT_3DM       0x3
+#define FORCE_OUTPUT_4D                0x4
 
 /* Error message handling */
 #define SHPLOADERMSGLEN                1024
@@ -112,9 +118,8 @@ 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;
+       /* Override the output geometry type (a FORCE_OUTPUT_* constant) */
+       int force_output;
 
        /* iconv encoding name */
        char *encoding;
@@ -188,10 +193,10 @@ typedef struct shp_loader_state
        /* String containing the PostGIS geometry type, e.g. POINT, POLYGON etc. */
        char *pgtype;
 
-       /* Flag for whether the geometry has Z coordinates or not. */
+       /* Flag for whether the output geometry has Z coordinates or not. */
        int has_z;
 
-       /* Flag for whether the geometry has M coordinates or not. */
+       /* Flag for whether the output geometry has M coordinates or not. */
        int has_m;
 
        /* Number of dimensions to output */