Skip to content

Commit

Permalink
Fixes the following shp2pgsql issues:
Browse files Browse the repository at this point in the history
postgis#229: A new "-r" command line parameter to specify a "from" SRID for reprojecting (the existing -s is the "to").
postgis#779: -S now works for points, and -w is documented.
#864: MULTIPOINT shapefiles with single-vertex points now correctly load with all MULTIPOINTs.
#865: no longer crashes when both -g and -G are used.



git-svn-id: http://svn.osgeo.org/postgis/trunk@6922 b70326c6-7e19-0410-871a-916f4a2858ee
  • Loading branch information
pramsey committed Mar 18, 2011
1 parent c7c2a32 commit a2c725a
Show file tree
Hide file tree
Showing 125 changed files with 1,029 additions and 470 deletions.
15 changes: 15 additions & 0 deletions doc/man/shp2pgsql.1
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ Use the PostgreSQL "dump" format for the output data. This can be combined
with -a, -c and -d. It is much faster to load than the default "insert" SQL
format. Use this for very large data sets.
.TP
\fB\-w\fR
Output WKT format, instead of WKB. Note that this can
introduce coordinate drifts due to loss of precision.
.TP
\fB\-e\fR
Execute each statement on its own, without using a transaction.
This allows loading of the majority of good data when there are some bad
Expand All @@ -62,6 +66,17 @@ geometries that generate errors. Note that this cannot be used with the
\fB\-s\fR <\fISRID\fR>
Creates and populates the geometry tables with the specified SRID.
.TP
\fB\-r\fR <\fISRID\fR>
Specifies that the input shapefile uses the given SRID. If -s is not
specified, this SRID will be used to populate the geometry table. If
-s is specified, the geometries will be reprojected to the SRID given
in the -s parameter. If -G is specified, but -s is not, the geometries
will be reprojected to 4326. This parameter cannot be used with -D.
.TP
\fB\-G\fR
Use the geography type instead of geometry. Geography is used to store
lat/lon data. At the moment the only spatial reference supported is 4326.
.TP
\fB\-g\fR <\fIgeometry_column\fR>
Specify the name of the geometry column (mostly useful in append mode).
.TP
Expand Down
52 changes: 49 additions & 3 deletions doc/using_postgis_dataman.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1734,6 +1734,19 @@ COMMIT;</programlisting>
</listitem>
</varlistentry>

<varlistentry>
<term>-r &lt;SRID&gt;</term>
<listitem>
<para>
Specifies that the input shapefile uses the given SRID. If -s is not
specified, this SRID will be used to populate the geometry table. If
-s is specified, the geometries will be reprojected to the SRID given
in the -s parameter. If -G is specified, but -s is not, the geometries
will be reprojected to 4326. This parameter cannot be used with -D.
</para>
</listitem>
</varlistentry>

<varlistentry>
<term>-k</term>
<listitem>
Expand Down Expand Up @@ -1766,7 +1779,9 @@ COMMIT;</programlisting>
<term>-S </term>
<listitem>
<para>
Generate simple geometries instead of MULTI geometries.
Generate simple geometries instead of MULTI geometries. Will only succeed if
all the geometries are actually single (I.E. a MULTIPOLYGON with a single shell, or
or a MULTIPOINT with a single vertex).
</para>
</listitem>
</varlistentry>
Expand All @@ -1775,8 +1790,20 @@ COMMIT;</programlisting>
<term>-w</term>
<listitem>
<para>
Output WKT format, for use with older (0.x) versions of PostGIS. Note that this will
introduce coordinate drifts and will drop M values from shapefiles.
Output WKT format, instead of WKB. Note that this can
introduce coordinate drifts due to loss of precision.
</para>
</listitem>
</varlistentry>

<varlistentry>
<term>-e</term>
<listitem>
<para>
Execute each statement on its own, without using a transaction.
This allows loading of the majority of good data when there are some bad
geometries that generate errors. Note that this cannot be used with the
-D flag as the "dump" format always uses a transaction.
</para>
</listitem>
</varlistentry>
Expand Down Expand Up @@ -1819,6 +1846,25 @@ COMMIT;</programlisting>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>-T &lt;tablespace&gt;</term>
<listitem>
<para>
Specify the tablespace for the new table. Indexes will still use the
default tablespace unless the -X parameter is also used. The PostgreSQL
documentation has a good description on when to use custom tablespaces.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>-X &lt;tablespace&gt;</term>
<listitem>
<para>
Specify the tablespace for the new table's indexes. This applies to
the primary key index, and the GIST spatial index if -I is also used.
</para>
</listitem>
</varlistentry>
</variablelist>

<para>
Expand Down
46 changes: 32 additions & 14 deletions loader/shp2pgsql-cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ usage()
printf(_( "RELEASE: %s (r%s)\n" ), POSTGIS_VERSION, RCSID);
printf(_( "USAGE: shp2pgsql [<options>] <shapefile> [<schema>.]<table>\n"
"OPTIONS:\n" ));
printf(_( " -s <srid> Set the SRID field. Defaults to -1.\n"
" (-d|a|c|p) These are mutually exclusive options:\n"
printf(_( " -s <srid> Set the SRID field. Defaults to %d.\n"
" -r <srid> Specify the SRID to reproject from (if -s or -G is also used).\n"
" Cannot be used with -D.\n"), SRID_UNKNOWN);
printf(_( " (-d|a|c|p) These are mutually exclusive options:\n"
" -d Drops the table, then recreates it and populates\n"
" it with current shape file data.\n"
" -a Appends shape file into current table, must be\n"
Expand All @@ -36,11 +38,13 @@ usage()
printf(_( " -D Use postgresql dump format (defaults to SQL insert statments).\n" ));
printf(_( " -e Execute each statement individually, do not use a transaction.\n"
" Not compatible with -D.\n" ));
printf(_( " -G Use geography type (requires lon/lat data).\n" ));
printf(_( " -G Use geography type (requires lon/lat data or -r to reproject).\n" ));
printf(_( " -k Keep postgresql identifiers case.\n" ));
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(_( " -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"
" attribute column. (default: \"UTF-8\")\n" ));
printf(_( " -N <policy> NULL geometries handling policy (insert*,skip,abort).\n" ));
Expand Down Expand Up @@ -82,7 +86,7 @@ main (int argc, char **argv)
set_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:iknpr:s:wDGIN:ST:W:X:")) != EOF)
{
switch (c)
{
Expand All @@ -100,6 +104,11 @@ main (int argc, char **argv)
fprintf(stderr, "Cannot use both -D and -e.\n");
exit(1);
}
if (config->shp_sr_id != SRID_UNKNOWN)
{
fprintf(stderr, "Cannot use both -D and -r.\n");
exit(1);
}
break;

case 'G':
Expand All @@ -122,9 +131,26 @@ main (int argc, char **argv)
exit(0);
}
break;
case 'r':
if (config->dump_format)
{
fprintf(stderr, "Cannot use both -D and -r.\n");
exit(1);
}
if (pgis_optarg)
{
sscanf(pgis_optarg, "%d", &(config->shp_sr_id));
}
else
{
/* With -r, user must specify SRID */
usage();
exit(0);
}
break;

case 'g':
config->geom = pgis_optarg;
config->geo_col = pgis_optarg;
break;

case 'k':
Expand All @@ -140,7 +166,7 @@ main (int argc, char **argv)
break;

case 'w':
config->hwgeom = 1;
config->use_wkt = 1;
break;

case 'n':
Expand Down Expand Up @@ -263,14 +289,6 @@ main (int argc, char **argv)
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);

Expand Down
Loading

0 comments on commit a2c725a

Please sign in to comment.