2016-05-12 21 views
1

我的幾何有什麼問題?幾何是herePostGIS無效的GML表示

當我運行此命令:

SELECT st_geomfromgml('content of file geometry.xml'); 

這個錯誤被拋出:

ERROR: invalid GML representation 

我使用Postgres的9.4.1和2.1.6的PostGIS

謝謝大家幫忙

回答

0

documentation for ST_GeomFromGML表示函數「不支持SQL/MM曲線幾何體」。不幸的是,錯誤信息並沒有闡明這個缺點,因爲GML對現代軟件有一個有效的表示。那裏有is an enhancement ticket to enable this support,但幾年後還沒有任何動作。

作爲一種變通方法,您可以使用GDAL/OGR從(例如)Python來讀取GML和WKB導出到了PostGIS:

from osgeo import ogr 

with open('geometry.xml', 'r') as fp: 
    g = ogr.CreateGeometryFromGML(fp.read()) 
g.GetArea() # 4519550457.106098 

# There is more than one way to insert this to PostGIS, here is one way 
import psycopg2 
conn = psycopg2.connect('dbname=postgis host=localhost user=postgres port=5432') 
curs = conn.cursor() 
curs.execute('CREATE TABLE surf(geom geometry);') 
curs.execute('INSERT INTO surf(geom) VALUES (%s)', (g.ExportToWkb().encode('hex'),)) 
conn.commit() 

curs.execute('SELECT ST_Area(geom) FROM surf') 
curs.fetchone()[0] # 4519550457.07643 

兩個面積計算(採用不同的方法)基本上是相同的,這是令人放心的。