[postgis-users] ST_GeomFromKML error with LinearRing

Teluk, Bill G Bill.Teluk at team.telstra.com
Thu May 14 19:24:24 PDT 2020


Thanks Paul!

That makes sense - it would be just duplication to allow LinearRing as a top level object... I assume it's there to make it easier to clearly distinguish donut holes in polygons, but not for use as a top-level "object".

I've found that the "LinearRing" appearing in my data, was in fact a coding error in my application, so the data itself didn't have any actual "LinearRing" as the top level object - it was in fact nested in a complex polygon.  My error!

Regards, 
Bill Teluk

-----Original Message-----
From: postgis-users <postgis-users-bounces at lists.osgeo.org> On Behalf Of Paul Ramsey
Sent: Friday, 15 May 2020 1:59 AM
To: PostGIS Users Discussion <postgis-users at lists.osgeo.org>
Subject: Re: [postgis-users] ST_GeomFromKML error with LinearRing

[External Email] This email was sent from outside the organisation – be cautious, particularly with links and attachments.

It's not a bug, it's deliberate. LinearRing is not an instantiable type, it's a component of a Polygon. If you want to instantiate a closed area, use a Polygon. If you want to instantiate a close line, use a closed LineString.

P

> On May 13, 2020, at 12:04 AM, Teluk, Bill G <Bill.Teluk at team.telstra.com> wrote:
>
> Hi,
>
> I’ve encountered a problem with the ST_GeomFromKML function.  I’m not sure if it’s a bug or not.  The problem description is:
>
> I have an external data source that I’m loading into a PostGIS-enabled PostgreSQL instance.  The data source is KML and needs to be parsed and loaded to the database using just INSERT’s (because of embedded content within it.)
>
> I’m extracting the XML for the feature spatial description, and using the ST_GeomFromKML() function to convert that XML text to the geometry object for the INSERT statement.  This has been working fine for other data sources I’ve got – however I’ve got a data source, that doesn’t work – and checking it, I can see that it differs from the others because it is using “LinearRing” elements as the “top level” spatial element.
>
> As far as I understand – the KML XSD (v2.2) allows for a LinearRing to be a top level spatial object (“AbstractGeometryGroup”.)  but it seems that the ST_GeomFromKML function won’t accept it and generates an error.
>
> I’ve tried wrapping the XML fragment in a “<Polygon><outerBoundaryIs>” element pair, and ST_GeomFromKML accepts that.
>
> I’ve reproduced the error on two different versions of PostGIS being v2.3 and 2.5.  Details below:
>
> SQL Statement that produces error:
> <pre>
> select ST_GeomFromKML('<LinearRing><coordinates>
> 148,-35
> 148,-36
> 144,-36
> 148,-36
> 148,-35
> </coordinates></LinearRing>');
> </pre>
>
> System #1:
> postgis_version:
> 2.3 USE_GEOS=1 USE_PROJ=1 USE_STATS=1
> (1 row)
>
> PostgreSQL version
> PostgreSQL 9.2.18 on x86_64-redhat-linux-gnu, compiled by gcc (GCC) 4.8.5 20150
> 623 (Red Hat 4.8.5-11), 64-bit
> (1 row)
>
> Error Message:
> ERROR:  invalid KML representation
>
> System #2:
> postgis_version:
> 2.5 USE_GEOS=1 USE_PROJ=1 USE_STATS=1
>
> PostgreSQL version
> PostgreSQL 10.12, compiled by Visual C++ build 1800, 64-bit
>
> Error Message:
> ERROR:  invalid KML representation
> SQL state: XX000
>
> Workaround, works successfully in both tested systems:
> <pre>
> select ST_GeomFromKML('<Polygon><outerBoundaryIs><LinearRing><coordinates>
> 148,-35
> 148,-36
> 144,-36
> 148,-36
> 148,-35
> </coordinates></LinearRing></outerBoundaryIs></Polygon>');
> </pre>
> Regards, Bill Teluk
> _______________________________________________
> postgis-users mailing list
> postgis-users at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/postgis-users

_______________________________________________
postgis-users mailing list
postgis-users at lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/postgis-users


More information about the postgis-users mailing list