to_crs creates different result from pyproj.transform
See original GitHub issueI’m not sure this is an issue for GeoPandas or pyproj, but parhaps due to always_xy
option for pyproj.transform
, to_crs
creates different result from pyproj.transform
.
Repro
Python and package versions
import sys
import pyproj
import geopandas
print(sys.version)
print(pyproj.__version__)
print(geopandas.__version__)
3.8.0 | packaged by conda-forge | (default, Nov 22 2019, 19:11:19) [Clang 9.0.0 (tags/RELEASE_900/final)]
2.4.2.post1
0.6.2
Reproject by pyproj.transform
x = -567637.0
y = -56204.0
# EPSG 4612: JGD2000, geographical, unit: degree
# https://epsg.io/4612
EPSG4612 = pyproj.Proj("EPSG:4612")
# RPSG 2443: JGD2000 / Japan Plane Rectangular CS I, projected, unit: meter
# https://epsg.io/2443
EPSG2443 = pyproj.Proj("EPSG:2443")
print(pyproj.transform(EPSG2443, EPSG4612, x, y))
(27.878013118155934, 128.92918943580798)
Here, 27.8780 is latitude and 128.929 is longitude.
Reproject by GeoDataFrame.to_crs
gdf = geopandas.GeoDataFrame(
geometry = geopandas.points_from_xy(x = [x], y = [y]),
crs = "EPSG:2443"
)
print(gdf.to_crs("EPSG:4612"))
geometry 0 POINT (123.47406 32.34878)
Swapping x and y produce correct result
gdf = geopandas.GeoDataFrame(
geometry = geopandas.points_from_xy(x = [y], y = [x]),
crs = "EPSG:2443"
)
print(gdf.to_crs("EPSG:4612"))
geometry 0 POINT (128.92919 27.87801)
Result produced by to_crs is similar for the one produced by transform with always_xy = True
print(pyproj.transform(EPSG2443, EPSG4612, x, y, always_xy=True))
(123.4740611549679, 32.34878175793676)
Issue Analytics
- State:
- Created 4 years ago
- Comments:20 (17 by maintainers)
Top Results From Across the Web
Converting Individual Points Instead of Entire Geometries ...
to_crs () but as soon as I use Pyproj.Transformer.transform() it becomes clear I am getting different results from these two methods, when they ......
Read more >python pyproj transform yielding different results for the ...
I get a different answer. I print out inProj both times and both appear to be the same. Run 1: import pyproj import...
Read more >Transformer - pyproj 3.4.1 documentation - GitHub Pages
The pyproj.Transformer has the capabilities of performing 2D, 3D, and 4D (time) transformations. It can do anything that the PROJ command line programs...
Read more >Advanced Examples - pyproj 3.4.0 documentation
import numpy as np from pyproj import Transformer, transform transformer ... Results: 160 ms ± 3.68 ms per loop (mean ± std. dev....
Read more >Transformer — pyproj 2.5.0 documentation - GitHub Pages
CRS or input used to create one) – Projection of output data. ... the transform method will accept as input and return as...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The input CRS has the northing coordinate first.
And the output has the northing coordinate first.
So, you need to input/output with north first and expect lat first:
However,
geopandas
usesalways_xy
, so it expects input x first and output x first always:Based on this,
result_B
seems to be correct.Yeah, you’re right. I originally skimmed your question 🙃 - bad habit of mine. I thought the order of the output was swapped as is shown in the example I provided. But, looking at it again, the values do differ. So only one of the two could have been correct.