Search code examples
postgresqlpostgis

KML to Postgis table


I'm trying to save some KML files to PostgreSQL. I'm using postgis and this is a sample of what I've done so far.

INSERT INTO police_crime_boundaries (name, polygon) VALUES (
    'A',
    ST_GeomFromKML('<LinearRing>
            <coordinates>-2.69927798816,52.9954289967,0 -2.70075298816,52.9932649967,0
                   </coordinates>
        </LinearRing>')
);

Anyone have any idea of what am I doing wrong?

Getting the data from here: https://data.police.uk/data/boundaries/


Solution

  • LinearRing can not be stored to/retrieved from a Geometry column (see the document)

    So you should either use <Polygon> tag instead of <LinearRing> or wrap it with OuterBoundary and Polygon tags like below :

    <Polygon>
    <outerBoundaryIs>
    <LinearRing>
    <coordinates>0,0 0,1 1,1 1,0 0,0</coordinates>
    </LinearRing>
    </outerBoundaryIs>
    </Polygon>