本文介绍了几何未被识别为FIND_SRID的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在下面发布的代码中,我希望找到几何图形的SRID
。我将几何体作为参数传递。问题是,当我运行代码时,我收到:
psycopg2.errors.SyntaxError: FEHLER: Syntaxfehler bei »{«
LINE 3: Find_SRID({'coordinates': [[[747588.406469401...
^
为了尝试修复它,我将geometry
参数括在单个qoutes之间,如下所示:
ST_GeomFromJSON('{geometry}') As geomertySRID
但随后我收到以下错误:
psycopg2.errors.SyntaxError: FEHLER: Syntaxfehler bei »coordinates«
LINE 3: Find_SRID('{'coordinates': [[[747588.40646940...
^
请告诉我如何修复此错误
编码:
def executeForFindSRID(self,geometry):
print(geometry)
query="""
SELECT
ST_GeomFromGeoJSON({geometry}) As geomertySRID
""".format(geometry=geometry)
data = self.connection.query(query,[])
# print(data)
return data
几何
这是我要查找的几何图形的SRID`
DEBUG:root:responseParameters['treatmentAsJSONInEPSG25832']: {'coordinates': [[[747588.4064694013, 6643569.636689969], [747597.3898909885, 6643584.395168291], [747581.3480667257, 6643607.880399012], [747574.9313370206, 6643609.292079547], [747563.5095581454, 6643597.870300672], [747556.9644938463, 6643584.780172074], [747562.6112159868, 6643575.668415893], [747577.2413597145, 6643570.278362939], [747588.4064694013, 6643569.636689969]]], 'type': 'Polygon'}
{'coordinates': [[[747588.4064694013, 6643569.636689969], [747597.3898909885, 6643584.395168291], [747581.3480667257, 6643607.880399012], [747574.9313370206, 6643609.292079547], [747563.5095581454, 6643597.870300672], [747556.9644938463, 6643584.780172074], [747562.6112159868, 6643575.668415893], [747577.2413597145, 6643570.278362939], [747588.4064694013, 6643569.636689969]]], 'type': 'Polygon'}
推荐答案
函数FIND_SRID需要三个参数,即架构、表名和几何列,例如:
SELECT Find_SRID('public','mytable','geom');
您还可以尝试函数ST_SRID
,该函数从给定的几何图形中提取SR:
SELECT ST_SRID(geom) FROM mytable;
如果您的几何体没有声明SRS,则函数ST_SRID
将返回零,因为PostGIS无法猜测SRS。通常,我们假设没有显式SRS的几何图形被编码为WGS84
(EPSG:4326)。事实上,WGS84
是GeoJSON Specification
中的预期SRS:
演示:db<>fiddle
这篇关于几何未被识别为FIND_SRID的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!