几何图形未被识别为 Find_SRID 的参数
geometry is not recognized as parameter to 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需要三个参数,即架构、table名称和几何列,例如:
SELECT Find_SRID('public','mytable','geom');
您也可以尝试函数 ST_SRID
,它从给定的几何图形中提取 SRS:
SELECT ST_SRID(geom) FROM mytable;
如果您的几何没有声明 SRS,函数 ST_SRID
将 return 归零,因为 PostGIS 无法猜测 SRS。通常我们假设没有显式 SRS 的几何被编码为 WGS84
(EPSG:4326). As a matter of fact, WGS84
is the expected SRS in the GeoJSON Specification
:
The coordinate reference system for all GeoJSON coordinates is a
geographic coordinate reference system, using the World Geodetic
System 1984 (WGS 84) [WGS84] datum, with longitude and latitude units
of decimal degrees. This is equivalent to the coordinate reference
system identified by the Open Geospatial Consortium (OGC) URN
urn:ogc:def:crs:OGC::CRS84.
演示:db<>fiddle
在下面发布的代码中,我想找到一个几何体的 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需要三个参数,即架构、table名称和几何列,例如:
SELECT Find_SRID('public','mytable','geom');
您也可以尝试函数 ST_SRID
,它从给定的几何图形中提取 SRS:
SELECT ST_SRID(geom) FROM mytable;
如果您的几何没有声明 SRS,函数 ST_SRID
将 return 归零,因为 PostGIS 无法猜测 SRS。通常我们假设没有显式 SRS 的几何被编码为 WGS84
(EPSG:4326). As a matter of fact, WGS84
is the expected SRS in the GeoJSON Specification
:
The coordinate reference system for all GeoJSON coordinates is a geographic coordinate reference system, using the World Geodetic System 1984 (WGS 84) [WGS84] datum, with longitude and latitude units of decimal degrees. This is equivalent to the coordinate reference system identified by the Open Geospatial Consortium (OGC) URN urn:ogc:def:crs:OGC::CRS84.
演示:db<>fiddle