New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pyproj test for two equal projections #15
Comments
I like the idea of a few lines of code detecting if the projections are the same. I am unsure if the built-in 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 I like the idea of a |
Yes I see. I would find a |
Pseudocode of how I would make a
This seems fairly easy to me. Below are a few more notes: Fiona has crs.py, which has the I don't know Cython, which pyproj uses to interface with the Proj.4, but Cython seems fairly straightforward. |
Just to add one more thing. The goal of this code is very similar to the already existing OGR function If you need that type of functionality right now, I'd use that library. If you are already using Fiona, using |
@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" EDIT: or even more pythonic:
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.") |
No problem @fmaussion In my limited additional testing and OGR/GDAL seems to fail sometimes, but that does work better for more cases than 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. |
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. |
pyproj doesn't seem to check if projections are equal when asked to transform:
Takes about 3 seconds on my laptop. I wonder if it would be possible for pyproj to catch these?
Would the following workaround work or is it dangerous?
Thanks,
Fabien
The text was updated successfully, but these errors were encountered: