简体   繁体   中英

Change the SRID of a geometry

I would like to develop a python code that set the SRID(A Spatial Reference System Identifier (SRID) is a unique value used to unambiguously identify projected, unprojected, and local spatial coordinate system definitions. These coordinate systems form the heart of all GIS applications) of a geometry to a particular integer value, however i don't have a clue from where to start.

Any help will be very much appreciated.

To implement such a function that mimics ST_SetSRID outside of PostGIS, you need to decide on the format you're willing to operate in.

If you're looking at geometry in EWKT (Extended Well-Known Text), then SRID is stored in the beginning:

SRID=4326;POINT(10.23 10.41)

There it can be replaced using text manipulation functions.

If you are looking at geom in EWKB (Extended Well-Known Binary), then SRID is stored as an integer after a header, if a header has a flag that it stores a SRID raised.

Here is how postgis stores a flag: https://sourcegraph.com/github.com/postgis/postgis/-/blob/liblwgeom/lwout_wkb.c#L145

Here is how it writes the SRID value: https://sourcegraph.com/github.com/postgis/postgis/-/blob/liblwgeom/lwout_wkb.c#L583

If you are implementing it in Python, you may want to use something like WKBheader library to not manipulate the fields youself: https://github.com/MazeMap/wkbheader

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM