[postgis-users] forced conversion of linestring tomulitlinestring when using shp2pgsql utility ?

Obe, Regina robe.dnd at cityofboston.gov
Wed Jan 28 04:13:37 PST 2009


If you have mixed linestrings and multilinestrings, I would just bring
in the data without the -S option as you were into a temp table.

Then what you do is create a new table  using the create structure of
your original (minus the geometry field).

If you use PgAdmin, you can use the generate create script for that.

So would look something like
CREATE TABLE single_linestrings
somefield1 varchar(20),
somefield2 varchar(50)

Then use AddGeometryColumn

SELECT AddGeometryColumn

(Note your SRID may be different but should match what you loaded).

Now insert from the shp2pgsql loaded table

INSERT INTO(somefield1,somefield2, the_geom)
SELECT somefield1,somefield2, (ST_Dump(the_geom)).geom
FROM the_multiline_table_you_loaded;

As documented here

then once you are done, drop the shp2pgsql loaded table with

SELECT DropGeometryTable('public', 'the_multiline_table_you_loaded');

As documented here

Hope that helps,

-----Original Message-----
From: postgis-users-bounces at postgis.refractions.net
[mailto:postgis-users-bounces at postgis.refractions.net] On Behalf Of
Smith Roman
Sent: Wednesday, January 28, 2009 2:20 AM
To: Nicolas Ribot
Cc: postgis-users at postgis.refractions.net
Subject: Re: [postgis-users] forced conversion of linestring
tomulitlinestring when using shp2pgsql utility ?


The -S option worked very well. But I am still not clear about how to
load a shape file that has many linestrings and a few mulitlinestrings.
When using the -S option it failed. You mentioned something about
exploding multilinestrings into linestrings by dropping the
enforce_geom_type constraint on my table. I will like to have more
clarification about how this can be done using the shp2pgsql utility.

Also how can I use the ST_Dump utility to do the samething ?



--- On Mon, 1/26/09, Nicolas Ribot <nicky666 at gmail.com> wrote:

> From: Nicolas Ribot <nicky666 at gmail.com>
> Subject: Re: [postgis-users] forced conversion of linestring to
mulitlinestring when using shp2pgsql utility ?
> To: autisi at yahoo.com, "PostGIS Users Discussion"
<postgis-users at postgis.refractions.net>
> Date: Monday, January 26, 2009, 2:09 PM
> > Hi,
> >
> > I have a shape file of linestrings that I want to load
> into postgis as linestrings.
> > My problem is whenever i use the shp2pgsql utility, 
> the utility converts all the linestrings
> > to multilinestrings. My purpose of loading the shape
> files is to do geometry operations on them
> > eg line interpolation. This operation can only be done
> on linestring not multilinestrings.
> >
> > Is there a way shp2pgsql can load linestrings to
> postgis as linestrings ? or is there another tool that
> > can do that for me ?
> >
> The -S switch is your friend. it forces simple geometries
> as stated if
> you run shp2pgsql w/o args:
> RCSID: $Id: shp2pgsql.c 2782 2008-05-27 02:59:06Z pramsey $
> RELEASE: 1.3.5
> USAGE: shp2pgsql [<options>] <shapefile>
> [<schema>.]<table>
>   -s <srid>  Set the SRID field. If not specified it
> defaults to -1.
>   (-d|a|c|p) These are mutually exclusive options:
>       -d  Drops the table, then recreates it and populates
>           it with current shape file data.
>       -a  Appends shape file into current table, must be
>           exactly the same table schema.
>       -c  Creates a new table and populates it, this is the
>           default if you do not specify any options.
>       -p  Prepare mode, only creates the table.
>   -g <geometry_column> Specify the name of the
> geometry column
>      (mostly useful in append mode).
>   -D  Use postgresql dump format (defaults to sql insert
> statments.
>   -k  Keep postgresql identifiers case.
>   -i  Use int4 type for all integer dbf fields.
>   -I  Create a GiST index on the geometry column.
>   -S  Generate simple geometries instead of MULTI
> geometries.
>   -w  Use wkt format (for postgis-0.x support - drops M -
> drifts coordinates).
>   -W <encoding> Specify the character encoding of
> Shape's
>      attribute column. (default : "ASCII")
>   -N <policy> Specify NULL geometries handling policy
> (insert,skip,abort)
>   -n  Only import DBF file.
>   -? Display this help screen
> you can also explode multi into simple objects once the
> table is
> loaded, by dropping the enforce_geom_type constraint on
> your table.
> Nicolas


postgis-users mailing list
postgis-users at postgis.refractions.net
The substance of this message, including any attachments, may be
confidential, legally privileged and/or exempt from disclosure
pursuant to Massachusetts law. It is intended
solely for the addressee. If you received this in error, please
contact the sender and delete the material from any computer.

More information about the postgis-users mailing list