Quantcast

[gdal-dev] ogr2ogr PROMOTE_TO_MULTI with linestrings?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[gdal-dev] ogr2ogr PROMOTE_TO_MULTI with linestrings?

Stephen Woodbridge
Hi,

I'm trying to load both polygons and linestrings and would like
PROMOTE_TO_MULTI to work for both, but it appears to define Multipolygon
type and does not work for linestrings/multilinestrings.

Maybe it would make more sense to have:

PROMOTE_TO_MULTI - work for either polygon or linestring depending on
what the first object is

or have two options like:

PROMOTE_POLY_TO_MULTI
PROMOTE_LINE_TO_MULTI

Or maybe, I'm totally missing something in the docs.

-Steve

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ogr2ogr PROMOTE_TO_MULTI with linestrings?

Stephen Woodbridge
On 5/15/2017 6:15 PM, Stephen Woodbridge wrote:

> Hi,
>
> I'm trying to load both polygons and linestrings and would like
> PROMOTE_TO_MULTI to work for both, but it appears to define Multipolygon
> type and does not work for linestrings/multilinestrings.
>
> Maybe it would make more sense to have:
>
> PROMOTE_TO_MULTI - work for either polygon or linestring depending on
> what the first object is
>
> or have two options like:
>
> PROMOTE_POLY_TO_MULTI
> PROMOTE_LINE_TO_MULTI
>
> Or maybe, I'm totally missing something in the docs.

Sorry, forgot to add:

ogrinfo --version
GDAL 2.1.0, released 2016/04/25

ogr2ogr -t_srs EPSG:4326 -nln census.roads -nlt PROMOTE_TO_MULTI -f
PostgreSQL -append PG:dbname=buildings host=localhost port=5432
user=postgres active_schema=census
/u/ror/buildings/data/census/tmp-11/tl_2016_06061_roads.shp
Warning 1: Geometry to be inserted is of type Multi Line String, whereas
the layer geometry type is Multi Polygon.
Insertion is likely to fail
ERROR 1: ERROR:  Geometry type (MultiLineString) does not match column
type (MultiPolygon)


---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ogr2ogr PROMOTE_TO_MULTI with linestrings?

jratike80
Stephen Woodbridge wrote
On 5/15/2017 6:15 PM, Stephen Woodbridge wrote:
> Hi,
>
> I'm trying to load both polygons and linestrings and would like
> PROMOTE_TO_MULTI to work for both, but it appears to define Multipolygon
> type and does not work for linestrings/multilinestrings.
>
> Maybe it would make more sense to have:
>
> PROMOTE_TO_MULTI - work for either polygon or linestring depending on
> what the first object is
>
> or have two options like:
>
> PROMOTE_POLY_TO_MULTI
> PROMOTE_LINE_TO_MULTI
>
> Or maybe, I'm totally missing something in the docs.

Sorry, forgot to add:

ogrinfo --version
GDAL 2.1.0, released 2016/04/25

ogr2ogr -t_srs EPSG:4326 -nln census.roads -nlt PROMOTE_TO_MULTI -f
PostgreSQL -append PG:dbname=buildings host=localhost port=5432
user=postgres active_schema=census
/u/ror/buildings/data/census/tmp-11/tl_2016_06061_roads.shp
Warning 1: Geometry to be inserted is of type Multi Line String, whereas
the layer geometry type is Multi Polygon.
Insertion is likely to fail
ERROR 1: ERROR:  Geometry type (MultiLineString) does not match column
type (MultiPolygon)
Hi,

Please tell more details about what you plan to do. Shapefile can't contain a mixture of lines and polygons so the error you get must mean that PostGIS table "census.roads" already exists and it has been created as MultiPolygon. Did you convert some polygons from another shapefile into the same table before? Anyway the restriction is at this stage set by PostGIS which requires multipolygons and you just can't  convert your lines into multipolygons.

Drop your table and start again by using -nlt GEOMETRY and you should be fine. That makes the PostGIS table to accept any kind of geometries. If you definitely need a mixture of MULTIpolygons and MULTIlinestrins we must add casts somewhere but perhaps that is not what you really want.

-Jukka Rahkonen-


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ogr2ogr PROMOTE_TO_MULTI with linestrings?

rgreenwood
In reply to this post by Stephen Woodbridge
You could use -nlt geometry but that won't convert simple objects to multi objects.
You could do it in steps: 
  1. use -where to get lines and -nlt MultiLine
  2. use -where to get polys with -nlt MutliPolygon
  3. combine the two tables into a single Geometry table
Rich


On Mon, May 15, 2017 at 6:25 PM, Stephen Woodbridge <[hidden email]> wrote:
On 5/15/2017 6:15 PM, Stephen Woodbridge wrote:
Hi,

I'm trying to load both polygons and linestrings and would like PROMOTE_TO_MULTI to work for both, but it appears to define Multipolygon type and does not work for linestrings/multilinestrings.

Maybe it would make more sense to have:

PROMOTE_TO_MULTI - work for either polygon or linestring depending on what the first object is

or have two options like:

PROMOTE_POLY_TO_MULTI
PROMOTE_LINE_TO_MULTI

Or maybe, I'm totally missing something in the docs.

Sorry, forgot to add:

ogrinfo --version
GDAL 2.1.0, released 2016/04/25

ogr2ogr -t_srs EPSG:4326 -nln census.roads -nlt PROMOTE_TO_MULTI -f PostgreSQL -append PG:dbname=buildings host=localhost port=5432 user=postgres active_schema=census /u/ror/buildings/data/census/tmp-11/tl_2016_06061_roads.shp
Warning 1: Geometry to be inserted is of type Multi Line String, whereas the layer geometry type is Multi Polygon.
Insertion is likely to fail
ERROR 1: ERROR:  Geometry type (MultiLineString) does not match column type (MultiPolygon)



---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev



--
Richard W. Greenwood, PLS
www.greenwoodmap.com

_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ogr2ogr PROMOTE_TO_MULTI with linestrings?

Stephen Woodbridge
In reply to this post by jratike80
I'm just trying to load the census roads data. I think what happened is
that when the table was created using -nlt PROMOTE_TO_MULTI it was
created as polygon geometry. then the subsequent insert failed. I change
the script to -nlt MULTILINESTRING and it loaded all the data. I found a
post from Even circa 2012 IIRC that indicated PROMOTE_TO_MULTI should
work for both polygons and linestrings.

I just checked the log file and the table was created with:

ogr2ogr -t_srs EPSG:4326 -nln census.roads -nlt PROMOTE_TO_MULTI -f
PostgreSQL -overwrite -lco OVERWRITE=YES -lco PRECISION=NO -lco
GEOMETRY_NAME=geom -lco FID=gid "PG:dbname=buildings host=localhost
port=5432 user=postgres active_schema=census"
/u/ror/buildings/data/census/tmp-11/tl_2016_us_county.shp

and then failed on the first insert:

ogr2ogr -t_srs EPSG:4326 -nln census.roads -nlt PROMOTE_TO_MULTI -f
PostgreSQL -append "PG:dbname=buildings host=localhost port=5432
user=postgres active_schema=census"
/u/ror/buildings/data/census/tmp-11/tl_2016_06001_roads.shp
Warning 1: Geometry to be inserted is of type Multi Line String, whereas
the layer geometry type is Multi Polygon.
Insertion is likely to fail
ERROR 1: ERROR:  Geometry type (MultiLineString) does not match column
type (MultiPolygon)

ERROR 1: INSERT command for new feature failed.

When I changed, PROMOTE_TO_MULTI to MULTILINESTRING, everything worked
fine. I only loaded one state (CA), but I do know for a fact that some
of the Census roads data has a mix of Linestring and MultiLinestring
features, which is why I used PROMOTE_TO_MULTI in the first place.

-Steve

On 5/16/2017 2:58 AM, jratike80 wrote:

> Stephen Woodbridge wrote
>> On 5/15/2017 6:15 PM, Stephen Woodbridge wrote:
>>> Hi,
>>>
>>> I'm trying to load both polygons and linestrings and would like
>>> PROMOTE_TO_MULTI to work for both, but it appears to define Multipolygon
>>> type and does not work for linestrings/multilinestrings.
>>>
>>> Maybe it would make more sense to have:
>>>
>>> PROMOTE_TO_MULTI - work for either polygon or linestring depending on
>>> what the first object is
>>>
>>> or have two options like:
>>>
>>> PROMOTE_POLY_TO_MULTI
>>> PROMOTE_LINE_TO_MULTI
>>>
>>> Or maybe, I'm totally missing something in the docs.
>>
>> Sorry, forgot to add:
>>
>> ogrinfo --version
>> GDAL 2.1.0, released 2016/04/25
>>
>> ogr2ogr -t_srs EPSG:4326 -nln census.roads -nlt PROMOTE_TO_MULTI -f
>> PostgreSQL -append PG:dbname=buildings host=localhost port=5432
>> user=postgres active_schema=census
>> /u/ror/buildings/data/census/tmp-11/tl_2016_06061_roads.shp
>> Warning 1: Geometry to be inserted is of type Multi Line String, whereas
>> the layer geometry type is Multi Polygon.
>> Insertion is likely to fail
>> ERROR 1: ERROR:  Geometry type (MultiLineString) does not match column
>> type (MultiPolygon)
>
> Hi,
>
> Please tell more details about what you plan to do. Shapefile can't contain
> a mixture of lines and polygons so the error you get must mean that PostGIS
> table "census.roads" already exists and it has been created as MultiPolygon.
> Did you convert some polygons from another shapefile into the same table
> before? Anyway the restriction is at this stage set by PostGIS which
> requires multipolygons and you just can't  convert your lines into
> multipolygons.
>
> Drop your table and start again by using -nlt GEOMETRY and you should be
> fine. That makes the PostGIS table to accept any kind of geometries. If you
> definitely need a mixture of MULTIpolygons and MULTIlinestrins we must add
> casts somewhere but perhaps that is not what you really want.
>
> -Jukka Rahkonen-
>
>
>
>
>
>
> --
> View this message in context: http://osgeo-org.1560.x6.nabble.com/gdal-dev-ogr2ogr-PROMOTE-TO-MULTI-with-linestrings-tp5320602p5320626.html
> Sent from the GDAL - Dev mailing list archive at Nabble.com.
> _______________________________________________
> gdal-dev mailing list
> [hidden email]
> https://lists.osgeo.org/mailman/listinfo/gdal-dev
>


---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ogr2ogr PROMOTE_TO_MULTI with linestrings?

Even Rouault-2

On mardi 16 mai 2017 09:21:06 CEST Stephen Woodbridge wrote:

> I'm just trying to load the census roads data. I think what happened is

> that when the table was created using -nlt PROMOTE_TO_MULTI it was

> created as polygon geometry. then the subsequent insert failed. I change

> the script to -nlt MULTILINESTRING and it loaded all the data. I found a

> post from Even circa 2012 IIRC that indicated PROMOTE_TO_MULTI should

> work for both polygons and linestrings.

 

It does, but it promotes the layer geometry type *source* to the corresponding multi geometry type. It doesn't take into account the target layer geometry type. We should perhaps have a a-nlt DST_GEOMETRY_TYPE for that.

 

Even

 

--

Spatialys - Geospatial professional services

http://www.spatialys.com


_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ogr2ogr PROMOTE_TO_MULTI with linestrings?

jratike80
In reply to this post by Stephen Woodbridge
Hi,

Could you have a try with attached data that contains 2 linestrings?

ogr2ogr -f Postgresql PG:"dbname=gis host=localhost port=5432 user=user password=password" -overwrite -nln linetest -nlt promote_to_multi lines.shp --debug on

ogr2ogr -f Postgresql PG:"dbname=gis host=localhost port=5432 user=user password=password" -append -nln linetest -nlt promote_to_multi lines.shp --debug on

For me the result is a table named as "linetest" that contains 4 multilinestring geometries. I tried to fool ogr2ogr by creating first "linetest" with multipolygon geometries but it cleared the test and -overwrite changed the table into multilinestring just fine. I tested also with a polygon shapefile and I can tell that for me PROMOTE_TO_MULTI does work for both lines and polygons.

The SQL create statement captured from the database for the multilinestring case is

-- Table: public.linetest

-- DROP TABLE public.linetest;

CREATE TABLE public.linetest
(
  ogc_fid integer NOT NULL DEFAULT nextval('linetest_ogc_fid_seq'::regclass),
  wkb_geometry geometry(MultiLineString),
  CONSTRAINT linetest_pkey PRIMARY KEY (ogc_fid)
)
WITH (
  OIDS=FALSE
);
ALTER TABLE public.linetest
  OWNER TO xxxx;

-- Index: public.linetest_wkb_geometry_geom_idx

-- DROP INDEX public.linetest_wkb_geometry_geom_idx;

CREATE INDEX linetest_wkb_geometry_geom_idx
  ON public.linetest
  USING gist
  (wkb_geometry);

Please check what you have in your first shapefile "tl_2016_us_county.shp ". Could it be that it contains polygon(s)? If it does it explains everything.

-Jukka Rahkonen-

_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev

lines.zip (612 bytes) Download Attachment
Loading...