-
Notifications
You must be signed in to change notification settings - Fork 216
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
Accept Datum and Ellipsoid objects for CRS datum= and ellps= constructor params #389
Comments
N.B. The only way I've found to do this, that does work, is
but this seems fragile -- how do I know the dictionary will always have a 'datum' parameter? how do I know that that parameter captures all of the necessary information? |
In a future version, you will be able to do this. But, it is a feature currently in progress in the PROJ repo. >>> from pyproj import CRS
>>> aeqd_crs = CRS(proj="aeqd", lon_0=-80, lat_0=40.5)
>>> print(aeqd_crs.to_json(pretty=True))
{
"type": "ProjectedCRS",
"name": "unknown",
"base_crs": {
"name": "unknown",
"datum": {
"type": "GeodeticReferenceFrame",
"name": "World Geodetic System 1984",
"ellipsoid": {
"name": "WGS 84",
"semi_major_axis": 6378137,
"inverse_flattening": 298.257223563
},
"id": {
"authority": "EPSG",
"code": 6326
}
},
"coordinate_system": {
"subtype": "ellipsoidal",
"axis": [
{
"name": "Longitude",
"abbreviation": "lon",
"direction": "east",
"unit": "degree"
},
{
"name": "Latitude",
"abbreviation": "lat",
"direction": "north",
"unit": "degree"
}
]
}
},
"conversion": {
"name": "unknown",
"method": {
"name": "Modified Azimuthal Equidistant",
"id": {
"authority": "EPSG",
"code": 9832
}
},
"parameters": [
{
"name": "Latitude of natural origin",
"value": 40.5,
"unit": "degree",
"id": {
"authority": "EPSG",
"code": 8801
}
},
{
"name": "Longitude of natural origin",
"value": -80,
"unit": "degree",
"id": {
"authority": "EPSG",
"code": 8802
}
},
{
"name": "False easting",
"value": 0,
"unit": "metre",
"id": {
"authority": "EPSG",
"code": 8806
}
},
{
"name": "False northing",
"value": 0,
"unit": "metre",
"id": {
"authority": "EPSG",
"code": 8807
}
}
]
},
"coordinate_system": {
"subtype": "Cartesian",
"axis": [
{
"name": "Easting",
"abbreviation": "E",
"direction": "east",
"unit": "metre"
},
{
"name": "Northing",
"abbreviation": "N",
"direction": "north",
"unit": "metre"
}
]
}
}
>>> crs_dict = aeqd_crs.to_json_dict()
>>> wgs_84_crs = CRS("EPSG:4326")
>>> wgs_84_crs.datum.to_json_dict()
{'type': 'GeodeticReferenceFrame', 'name': 'World Geodetic System 1984', 'ellipsoid': {'name': 'WGS 84', 'semi_major_axis': 6378137, 'inverse_flattening': 298.257223563}, 'area': 'World', 'bbox': {'south_latitude': -90, 'west_longitude': -180, 'north_latitude': 90, 'east_longitude': 180}, 'id': {'authority': 'EPSG', 'code': 6326}}
>>> crs_dict["base_crs"]["datum"] = wgs_84_crs.datum.to_json_dict()
>>> final_crs = CRS(crs_dict)
>>> final_crs
<Projected CRS: {"type": "ProjectedCRS", "name": "unknown", "base_ ...>
Name: unknown
Axis Info [cartesian]:
- E[east]: Easting (metre)
- N[north]: Northing (metre)
Area of Use:
- undefined
Coordinate Operation:
- name: unknown
- method: Modified Azimuthal Equidistant
Datum: World Geodetic System 1984
- Ellipsoid: WGS 84
- Prime Meridian: Greenwich |
After some thinking, I might add a simpler interface like: >>> from pyproj.crs import Ellipsoid, CRS
>>> wgs_84_crs = CRS("EPSG:4326")
>>> wgs_84_crs
<Geographic 2D CRS: EPSG:4326>
Name: WGS 84
Axis Info [ellipsoidal]:
- Lat[north]: Geodetic latitude (degree)
- Lon[east]: Geodetic longitude (degree)
Area of Use:
- name: World
- bounds: (-180.0, -90.0, 180.0, 90.0)
Datum: World Geodetic System 1984
- Ellipsoid: WGS 84
- Prime Meridian: Greenwich
>>> ell = Ellipsoid.from_string("urn:ogc:def:ellipsoid:EPSG::7001")
>>> wgs_84_crs.from_self(ellipsoid=ell)
<Geographic 2D CRS: {"type": "GeographicCRS", "name": "WGS 84", "datum ...>
Name: WGS 84
Axis Info [ellipsoidal]:
- Lat[north]: Geodetic latitude (degree)
- Lon[east]: Geodetic longitude (degree)
Area of Use:
- name: World
- bounds: (-180.0, -90.0, 180.0, 90.0)
Datum: World Geodetic System 1984
- Ellipsoid: Airy 1830
- Prime Meridian: Greenwich |
@djhoese, maybe something like this would be useful for you in transitioning from PROJ to the more verbose WKT/PROJ JSON? |
Yes, it looks like it. Accessing/using the information that I used to get from the PROJ dict will be the main transition for some of my packages. Thanks for letting me know. |
Sounds good 👍. I think being able to tweak parameters in the CRS would be a nice feature to have. But, with the added complexity, I haven't come up with a simpler interface yet. Maybe having preset CRS classes where you can modify the parameters similar to cartopy would be useful. 🤔 |
Oh I guess I didn't realize this was about assigning new values to a CRS. Most of my users are used to things like:
Or writing the YAML equivalent of the above. Creating areas from other areas isn't done a lot by me, but I'm sure users would find it useful. As a library other being able to do |
For The datum & ellps have the >>> from pyproj import CRS
>>> crs = CRS("ESRI:102719")
>>> crs.datum.name
'North American Datum 1983'
>>> crs.ellipsoid.name
'GRS 1980'
>>> crs.coordinate_operation.name
'NAD_1983_StatePlane_North_Carolina_FIPS_3200_Feet'
>>> crs.coordinate_operation.method_name
'Lambert Conic Conformal (2SP)' For the reference longitude access, I would recommend looking into the |
Addressed in #509 |
This was supposed to have been fixed by #509, but it still doesn't work as of 3.1.0:
I see that there are now a bunch of new classes that let me do something almost equivalent via e.g.
but I don't see why passing a Datum object as the |
The https://pyproj4.github.io/pyproj/stable/build_crs.html
The current method uses PROJ JSON, which is a better option for representing the CRS. |
Why does it have to be only for building PROJ strings? That behavior makes sense when the value is a string, but when it's Datum object already, wouldn't it make more sense to bypass those conversions? Especially since they're lossy. |
@zackw do you have an example of what you are thinking that doesn't use a PROJ string? |
The concrete thing I want to be able to do is construct arbitrary CRSes with the same datum as an existing CRS. In the particular program I am working on today, the existing CRS is the coordinate system of a map loaded by fiona. |
That sounds like a different problem from this issue. I would recommend creating a new issue to discuss. |
Suppose you have a standard lon/lat CRS, e.g.
and you want to create a projected CRS with the same datum. The most obvious way to do that would be to use the 'datum' property of the first CRS as the 'datum' argument to the CRS constructor, but that doesn't work:
Can you make that work, please? Also for the 'ellps' argument and Ellipsoids.
The text was updated successfully, but these errors were encountered: