Comments (7)
I like the idea of a few lines of code detecting if the projections are the same. I am unsure if the built-in transform()
should do that checking.
Your work around will work for the above case because you defined both projections in exactly the same way. It is not a bad way to test. Look at my example using the same projection defined in two different ways.
p1 = pyproj.Proj(init='epsg:26915')
p2 = pyproj.Proj('+proj=utm +zone=15 +datum=NAD83 +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0')
if p1.srs == p2.srs:
print("They are equal???") # this shouldn't happen
else:
print("Test fails.")
In order to make a projection equivalence test, PyProj would either have to expose pj_get_def()
from Proj.4 or create a new function Proj.__eq__()
that to check if the projections are equivalent and most likely use the `pr_get_def() .
I like the idea of a Proj.__eq__()
so you can test p1 == p2
. Then, your code could test ==
and skip the transform. There other useful application for that projection equivalency of function.
from pyproj.
Yes I see. I would find a Proj.__eq__()
very useful in general, yes! How complicated would it be to implement?
from pyproj.
Pseudocode of how I would make a Proj.__eq__()
.
- Run
pj_get_def()
on a projection - convert Proj4 string to Fiona.crs dictionary representation,
from_string()
- remove those key from dictionary that are for metadata, such as the 'init' key
- Do steps 1-3 on a 2nd projection.
- compare parameters that a functionally equivalent or convert them, such as '+to_meters=.3048' and '+units=ft'
- return Boolean value of
p1_dict == p2_dict
This seems fairly easy to me.
Below are a few more notes:
Running pj_get_def()
for the projection string '+init=epsg:26915'
returns the string ' +init=epsg:26915 +proj=utm +zone=15 +datum=NAD83 +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0'
Fiona has crs.py, which has the from_string()
, which converts a above Proj.4 strings into dictionaries. If the licenses will allow, I would just copy from_string()
into pyproj.
I don't know Cython, which pyproj uses to interface with the Proj.4, but Cython seems fairly straightforward.
from pyproj.
Just to add one more thing. The goal of this code is very similar to the already existing OGR function IsSame()
, (C++ code) which can be accessed in Python through osgeo.osr
library.
If you need that type of functionality right now, I'd use that library. If you are already using Fiona, using osr
shouldn't be any more of a burden to your users. PyProj probably should not be relying upon OGR.
from pyproj.
@micahcochran sorry it took me so long to get back to you. Indeed your suggestion is working perfectly (see test case below). I agree with you that pyproj should avoid depending upon OGR (the fact that pyproj is lightweight is really great). I just changed to the title and keep the issue open for later use. A "homemade" p1.is_same(p2)
would still be very useful.
EDIT: or even more pythonic: p1.__eq__(other)
.
IsSame
using OGR:
import pyproj
from osgeo import osr
# Pyproj version
p1 = pyproj.Proj(init='epsg:26915')
p2 = pyproj.Proj('+proj=utm +zone=15 +datum=NAD83 +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0')
if p1.srs == p2.srs:
print("They are equal")
else:
print("Test fails.") # This is what happens
# OGR version
s1 = osr.SpatialReference()
s1.ImportFromProj4(p1.srs)
s2 = osr.SpatialReference()
s2.ImportFromProj4(p2.srs)
if s1.IsSame(s2):
print("They are equal") # This is what happens
else:
print("Test fails.")
from pyproj.
No problem @fmaussion
In my limited additional testing and OGR/GDAL seems to fail sometimes, but that does work better for more cases than p1.srs == p2.srs
.
This would be extending pyproj beyond the capabilities of proj.4's public facing API, which pyproj mirrors fairly closely. OGR/GDAL depends upon proj.4 for its coordinate transformations, but extends its capabilities with the IsSame and other functions.
I'm going to make a suggestion that's not quite going to solve your problem. PyCRS is a python library has some of the workings to understand projection parameters. It is already a useful library to convert between WKT and proj4 projection representations. It seems like a projection equality comparison could compliment it. It might not be too hard extend it. Note: PyCRS still has a few rough edges.
from pyproj.
Thanks a lot @micahcochran ! I'll have a look at PyCRS, although I think that the simple solution above will largely fulfill my needs.
I'll close this issue then.
from pyproj.
Related Issues (20)
- Add JSON serializeability with PROJJSON? HOT 7
- to_CF for polar_stereographic, with latitude_true_scale, should include latitude_of_projection_origin HOT 2
- Reverse transformation does not produce initial coordinates
- DeprecationWarning: pkg_resources is deprecated as an API. HOT 1
- Support for deprecated and non-deprecated objects HOT 3
- Invert lat lon "Transformer" HOT 1
- Internal Proj Error: proj_create: unrecognized format / unknown name HOT 4
- Inverted x/y for transformation from WSG84 to LV95 (EPSG:2056) HOT 3
- muslinux wheel missing HOT 1
- test_azimuthal_equidistant fails with PROJ 9.4.0 HOT 1
- test failure in test_crs_cf.py HOT 2
- Add proj_query_geodetic_crs_from_datum HOT 2
- 3.6.1: pytest fails in `test/crs/test_crs_cf.py::test_azimuthal_equidistant` unit HOT 1
- A question about pyproj/_datadir.pyx HOT 2
- geometry_area_perimeter limitations not documented HOT 1
- Calculate area of arbitrary polygon on Earth's surface HOT 4
- Interrupted Mollweide gives wrong result on inverse projections of some lat/lons. HOT 1
- test_datum__from_epsg fails with PROJ 9.4.1 HOT 4
- Proj4 export from a bound CRS object fails HOT 4
- Antipodes don't match when calculated numerically HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyproj.