1

Transformation query PostGIS:

SELECT ST_AsText(ST_Transform(ST_GeomFromText('POINT (16.0317217831498 45.0589613134642)',4326),3857))

Result:

POINT(1784643.10543967 5630808.51923201)

These coordinates are correctly transformed ones

I am trying to get same result only by using Python ogr lib.

Python code:

from osgeo import ogr
from osgeo import osr
source = osr.SpatialReference()
source.ImportFromEPSG(4326)
target = osr.SpatialReference()
target.ImportFromEPSG(3857)
transform = osr.CoordinateTransformation(source, target)
point = ogr.CreateGeometryFromWkt("POINT (16.0317217831498 45.0589613134642)")
point.Transform(transform)
point.ExportToWkt()

Result:

POINT (5015940.62908865 1808396.61831747)

What am I not doing right in transformation with ogr lib ? (ps. I also tried to assignSpatialReference 4326 to geometry before applying transformation but result is still the same)

Vince
20.5k16 gold badges49 silver badges65 bronze badges
asked Dec 28, 2021 at 10:35
1
  • 2
    EPSG:4326 is officially using axis order latitude-longitude but PostGIS and many others are using longitude-latitude order that has been a tradition in GIS. Try with "POINT (45.0589613134642 16.0317217831498)". Or read gdal.org/tutorials/osr_api_tut.html and use oSRS.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER). Commented Dec 28, 2021 at 11:09

1 Answer 1

3

EPSG:4326 is officially using axis order latitude-longitude but PostGIS and many others are using longitude-latitude order that has been a tradition in GIS. Turn the coordinates into "POINT (45.0589613134642 16.0317217831498)

>>> point = ogr.CreateGeometryFromWkt("POINT (45.0589613134642 16.0317217831498)")
>>> point.Transform(transform)
0
>>> point.ExportToWkt()
'POINT (1784643.10543967 5630808.51923201)'
answered Dec 28, 2021 at 17:19

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.