[postgis-users] ST_GeomFromKML error with LinearRing
Paul Ramsey
pramsey at cleverelephant.ca
Thu May 14 08:59:22 PDT 2020
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
More information about the postgis-users
mailing list