question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Coordinates outside bounds of area of use now return inf

See original GitHub issue

Running the GeoPandas tests with proj 6 / pyproj master, turned up this regression:

In [1]: import pyproj 

In [2]: pyproj.__version__ 
Out[2]: '2.1.3'

In [3]: p1 = pyproj.Proj(init='epsg:26918')
   ...: p2 = pyproj.Proj(init='epsg:4326')

In [4]: pyproj.transform(p1, p2, 0, 0)
Out[4]: (inf, inf)

vs

In [1]: import pyproj

In [2]: pyproj.__version__    
Out[2]: '1.9.6'

In [3]: p1 = pyproj.Proj(init='epsg:26918') 
   ...: p2 = pyproj.Proj(init='epsg:4326')  

In [4]: pyproj.transform(p1, p2, 0, 0)
Out[4]: (-79.48874388438705, 0.0)

So the transform now returns inf instead of an actual value. The coordinates however are out of the area of use (see bounds here http://epsg.io/26918). But previously it did calculate the transformed values nevertheless.

Here, it was a dummy test case in geopandas where we did not check that the tested dummy values were actually properly inside the bounds of the tested CRS. So that is easy to edit. But, it still is a breaking change (I don’t know that what extent people run into this in practice).

This seems a bit similar to https://github.com/pyproj4/pyproj/issues/202, but the difference is that here pyproj 1.9.6 actually returned values and not inf.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:15 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
snowman2commented, Jul 1, 2019

@yxdragon, the good news is that there is a simple solution to your problem. In PROJ 6+, they take the axis order into consideration when doing transformations.

In your case, wkt1 has the latitude first longitude second and wkt2 has the east first and the northing second:

>>> from pyproj import CRS, Transformer
>>> wkt2 = 'PROJCS["China_Lambert_Conformal_Conic",GEOGCS["GCS_Beijing_1954",DATUM["Beijing_1954",SPHEROID["Krassowsky_1940",6378245,298.3,AUTHORITY["EPSG","7024"]],AUTHORITY["EPSG","6214"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["standard_parallel_1",30],PARAMETER["standard_parallel_2",62],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",105],PARAMETER["false_easting",0],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]]]'
>>> wkt1 = 'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433],AUTHORITY["EPSG","4326"]]'
>>> crs2 = CRS(wkt2)
>>> crs2
<Projected CRS: PROJCS["China_Lambert_Conformal_Conic",GEOGCS["GCS ...>
Name: China_Lambert_Conformal_Conic
Axis Info [cartesian]:
- E[east]: Easting (metre)
- N[north]: Northing (metre)
Area of Use:
- undefined
Coordinate Operation:
- name: unnamed
- method: Lambert Conic Conformal (2SP)
Datum: Beijing 1954
- Ellipsoid: Krassowsky_1940
- Prime Meridian: Greenwich

>>> crs1 = CRS(wkt1)
>>> crs1
<Geographic 2D CRS: EPSG:4326>
Name: WGS 84
Axis Info [ellipsoidal]:
- Lat[north]: Geodetic latitude (degree)
- Lon[east]: Geodetic longitude (degree)
Area of Use:
- undefined
Datum: World Geodetic System 1984
- Ellipsoid: WGS 84
- Prime Meridian: Greenwich

Since this is the case, you need to swap the order of your input so that the latitude is first and longitude is second:

>>> transformer = Transformer.from_crs(crs1, crs2)
>>> transformer.transform(40, 100.20201515)
(-396207.328443438, 4808545.278686934)

Or, if you want it to always have the longitude first and latitude second, you can toggle on the always_xy argument:

>>> transformer = Transformer.from_crs(crs1, crs2, always_xy=True)
>>> transformer.transform(100.20201515, 40)
(-396207.328443438, 4808545.278686934)

For more information about this, I would recommend looking at:

Hopefully this helps.

0reactions
snowman2commented, Jul 20, 2019

It would be useful to have in another issue so it is easier for someone who has a similar question. I would recommend looking into Transformer.from_pipeline().

Read more comments on GitHub >

github_iconTop Results From Across the Web

The feature geometry could not be modified. The coordinates ...
Technical Article Details : Error: The feature geometry could not be modified. The coordinates or measures are out of bounds.
Read more >
Pyproj returns inf when coordinates are inside bounds
I'm trying to parse the data from GHSL-POP, converting coordinates to real-world latitudes and longitudes. But pyproj returns inf value for ...
Read more >
Finding Area Bounded By Two Polar Curves - YouTube
This calculus 2 video tutorial explains how to find the area ... how to find the area that lies inside the first curve...
Read more >
Finding Area In Polar Coordinates - YouTube
This Calculus 2 video tutorial explains how to find the area of a polar curve in polar coordinates. It provides resources on how...
Read more >
How to raise an error that coordinates are out of raster bounds ...
Rasterio sample module gives back value 0 in case like that, but that is not good (because if raster image has values 0-255)...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found