printf("RCSID: %s RELEASE: %s\n", RCSID, POSTGIS_VERSION);
printf("USAGE: shp2pgsql [<options>] <shapefile> [<schema>.]<table>\n");
printf("OPTIONS:\n");
- printf(" -s <srid> Set the SRID field. If not specified it defaults to -1.\n");
+ printf(" -s <srid> Set the SRID field. Defaults to -1.\n");
printf(" (-d|a|c|p) These are mutually exclusive options:\n");
printf(" -d Drops the table, then recreates it and populates\n");
printf(" it with current shape file data.\n");
printf(" -c Creates a new table and populates it, this is the\n");
printf(" default if you do not specify any options.\n");
printf(" -p Prepare mode, only creates the table.\n");
- printf(" -g <geometry_column> Specify the name of the geometry column\n");
+ printf(" -g <geocolumn> Specify the name of the geometry/geography column\n");
printf(" (mostly useful in append mode).\n");
- printf(" -D Use postgresql dump format (defaults to sql insert statments.\n");
+ printf(" -D Use postgresql dump format (defaults to SQL insert statments.\n");
+ printf(" -G Use geography type (requires lon/lat data).\n");
printf(" -k Keep postgresql identifiers case.\n");
printf(" -i Use int4 type for all integer dbf fields.\n");
- printf(" -I Create a GiST index on the geometry column.\n");
+ printf(" -I Create a spatial index on the geocolumn.\n");
printf(" -S Generate simple geometries instead of MULTI geometries.\n");
#ifdef HAVE_ICONV
printf(" -W <encoding> Specify the character encoding of Shape's\n");
printf(" attribute column. (default : \"ASCII\")\n");
#endif
- printf(" -N <policy> Specify NULL geometries handling policy (insert,skip,abort)\n");
+ printf(" -N <policy> NULL geometries handling policy (insert*,skip,abort)\n");
printf(" -n Only import DBF file.\n");
- printf(" -? Display this help screen\n");
+ printf(" -? Display this help screen.\n");
}
config = malloc(sizeof(SHPLOADERCONFIG));
set_config_defaults(config);
- while ((c = pgis_getopt(argc, argv, "kcdapDs:Sg:iW:wIN:n")) != EOF)
+ while ((c = pgis_getopt(argc, argv, "kcdapGDs:Sg:iW:wIN:n")) != EOF)
{
switch (c)
{
config->dump_format = 1;
break;
+ case 'G':
+ config->geography = 1;
+ break;
+
case 'S':
config->simple_geometries = 1;
break;
strtolower(config->schema);
}
+ /* Make the geocolumn name consistent with the load type (geometry or geography) */
+ if( config->geography )
+ {
+ if(config->geom) free(config->geom);
+ config->geom = strdup(GEOGRAPHY_DEFAULT);
+ }
+
+
/* Create the shapefile state object */
state = ShpLoaderCreate(config);
config->opt = 'c';
config->schema = NULL;
config->table = NULL;
- config->geom = strdup("the_geom");
+ config->geom = strdup(GEOMETRY_DEFAULT);
config->readshape = 1;
config->sr_id = -1;
config->hwgeom = 0;
return ret;
}
-
/* Return a pointer to an allocated string containing the header for the specified loader state */
int
ShpLoaderGetSQLHeader(SHPLOADERSTATE *state, char **strheader)
*/
if (state->config->schema)
{
- if (state->config->readshape == 1)
+ if (state->config->readshape == 1 && (! state->config->geography) )
{
vasbappend(sb, "SELECT DropGeometryColumn('%s','%s','%s');\n",
state->config->schema, state->config->table, state->config->geom);
}
else
{
- if (state->config->readshape == 1)
+ if (state->config->readshape == 1 && (! state->config->geography) )
{
vasbappend(sb, "SELECT DropGeometryColumn('','%s','%s');\n",
state->config->table, state->config->geom);
return SHPLOADERERR;
}
}
+
+ /* Add the geography column directly to the table definition, we don't
+ need to do an AddGeometryColumn() call. */
+ if(state->config->readshape == 1 && state->config->geography)
+ {
+ char *dimschar;
+ if( state->pgdims == 4 )
+ dimschar = "ZM";
+ else
+ dimschar = "";
+ if(state->config->sr_id != -1 && state->config->sr_id != 4326)
+ {
+ snprintf(state->message, SHPLOADERMSGLEN, "Invalid SRID for geography type: %x", state->config->sr_id);
+ stringbuffer_destroy(sb);
+ return SHPLOADERERR;
+ }
+ vasbappend(sb, ",\n\"%s\" geography(%s%s,%d)", state->config->geom, state->pgtype, dimschar, 4326);
+ }
+
vasbappend(sb, ");\n");
/* Create the geometry column with an addgeometry call */
- if (state->config->readshape == 1)
+ if (state->config->readshape == 1 && (!state->config->geography))
{
if (state->config->schema)
{
* Default geometry column name
*/
#define GEOMETRY_DEFAULT "the_geom"
-#define GEOGRAPHY_DEFAULT "the_geog"
+#define GEOGRAPHY_DEFAULT "geog"
/*
* Structure to hold the loader configuration options
/* 0 = MULTIPOLYGON/MULTILINESTRING, 1 = force to POLYGON/LINESTRING */
int simple_geometries;
+
+ /* 0 = geometry, 1 = geography */
+ int geography;
/* 0 = columnname, 1 = "columnName" */
int quoteidentifiers;
config->schema = strdup(pg_schema);
if (strlen(pg_geom) == 0)
- config->geom = strdup("the_geom");
+ config->geom = strdup(GEOMETRY_DEFAULT);
else
config->geom = strdup(pg_geom);