geometry is not recognized as parameter to Find_SRID

Viewed 211

in the below posted code, i want to find the SRID of a geometry. i pass the geometry as a parameter. the problem is when i run the code, i receive :

psycopg2.errors.SyntaxError: FEHLER:  Syntaxfehler bei »{«
LINE 3:             Find_SRID({'coordinates': [[[747588.406469401...
                             ^

as an attempt to fix it, i enclosed the geometry parameter between single qoutes as follows:

            ST_GeomFromJSON('{geometry}') As geomertySRID       

but then i receive the following error:

psycopg2.errors.SyntaxError: FEHLER:  Syntaxfehler bei »coordinates«
LINE 3:             Find_SRID('{'coordinates': [[[747588.40646940...
                                ^

please let me know how to fix this error

code:

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

    

geometry

here is the geometry i would like to find its 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'}
1 Answers

The function Find_SRID expects three parameters, namely the schema, the table name and the geometry column, e g.:

SELECT Find_SRID('public','mytable','geom');

You might also try the function ST_SRID, which extracts the SRS from a given geometry:

SELECT ST_SRID(geom) FROM mytable;

If your geometry has no SRS declared, the function ST_SRID will return zero, as there is no way that PostGIS can guess the SRS. Normally we assume that a geometry without explicit SRS is encoded as 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.

Demo: db<>fiddle

Related