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
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;
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;
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)
#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
/* 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;
/* 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 */