Skip to content

Commit

Permalink
add interface to get the projection/ellps/prime_meridian/units lists (#…
Browse files Browse the repository at this point in the history
…251)

* add interface to get the projection/ellps/prime_meridian/units lists

* removed ellipsoid lists and instead pointed to docs for how to get them
  • Loading branch information
snowman2 committed Apr 8, 2019
1 parent 3f72512 commit 2365389
Show file tree
Hide file tree
Showing 9 changed files with 235 additions and 303 deletions.
29 changes: 22 additions & 7 deletions pyproj/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,26 @@
"itransform",
"pj_ellps",
"pj_list",
"get_angular_units_map",
"get_ellps_map",
"get_prime_meridians_map",
"get_proj_operations_map",
"get_units_map",
]

from pyproj.crs import CRS
from pyproj.exceptions import ProjError
from pyproj.geod import Geod, geodesic_version_str, pj_ellps
from pyproj.proj import Proj, pj_list, proj_version_str
from pyproj.transformer import Transformer, itransform, transform
import sys

from pyproj._list import ( # noqa
get_angular_units_map,
get_ellps_map,
get_prime_meridians_map,
get_proj_operations_map,
get_units_map,
)
from pyproj.crs import CRS # noqa
from pyproj.exceptions import ProjError # noqa
from pyproj.geod import Geod, geodesic_version_str, pj_ellps # noqa
from pyproj.proj import Proj, pj_list, proj_version_str # noqa
from pyproj.transformer import Transformer, itransform, transform # noqa


def test(**kwargs):
Expand All @@ -79,7 +92,9 @@ def test(**kwargs):
pyproj.transformer, verbose=verbose
)

return failure_count + failure_count_crs + failure_count_geod + failure_count_transform
return (
failure_count + failure_count_crs + failure_count_geod + failure_count_transform
)


if __name__ == "__main__":
Expand Down
101 changes: 101 additions & 0 deletions pyproj/_list.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
include "proj.pxi"

from collections import namedtuple

from pyproj.compat import pystrdecode


def get_proj_operations_map():
"""
Returns
-------
dict: operations supported by PROJ.
"""
cdef PJ_OPERATIONS *proj_operations = proj_list_operations()
cdef int iii = 0
operations_map = {}
while proj_operations[iii].id != NULL:
operations_map[pystrdecode(proj_operations[iii].id)] = \
pystrdecode(proj_operations[iii].descr[0]).split("\n\t")[0]
iii += 1
return operations_map


def get_ellps_map():
"""
Returns
-------
dict: ellipsoids supported by PROJ.
"""
cdef PJ_ELLPS *proj_ellps = proj_list_ellps()
cdef int iii = 0
ellps_map = {}
while proj_ellps[iii].id != NULL:
major_key, major_val = pystrdecode(proj_ellps[iii].major).split("=")
ell_key, ell_val = pystrdecode(proj_ellps[iii].ell).split("=")
ellps_map[pystrdecode(proj_ellps[iii].id)] = {
major_key: float(major_val),
ell_key: float(ell_val),
"description": pystrdecode(proj_ellps[iii].name)
}
iii += 1
return ellps_map


def get_prime_meridians_map():
"""
Returns
-------
dict: prime meridians supported by PROJ.
"""
cdef PJ_PRIME_MERIDIANS *prime_meridians = proj_list_prime_meridians()
cdef int iii = 0
prime_meridians_map = {}
while prime_meridians[iii].id != NULL:
prime_meridians_map[pystrdecode(prime_meridians[iii].id)] = \
pystrdecode(prime_meridians[iii].defn)
iii += 1
return prime_meridians_map


Unit = namedtuple("Unit", ["id", "to_meter", "name", "factor"])


def get_units_map():
"""
Returns
-------
dict: units supported by PROJ
"""
cdef PJ_UNITS *proj_units = proj_list_units()
cdef int iii = 0
units_map = {}
while proj_units[iii].id != NULL:
units_map[pystrdecode(proj_units[iii].id)] = Unit(
id=pystrdecode(proj_units[iii].id),
to_meter=pystrdecode(proj_units[iii].to_meter),
name=pystrdecode(proj_units[iii].name),
factor=proj_units[iii].factor,
)
iii += 1
return units_map


def get_angular_units_map():
"""
Returns
-------
dict: angular units supported by PROJ
"""
cdef PJ_UNITS *proj_units = proj_list_angular_units()
cdef int iii = 0
units_map = {}
while proj_units[iii].id != NULL:
units_map[pystrdecode(proj_units[iii].id)] = Unit(
id=pystrdecode(proj_units[iii].id),
to_meter=pystrdecode(proj_units[iii].to_meter),
name=pystrdecode(proj_units[iii].name),
factor=proj_units[iii].factor,
)
iii += 1
return units_map
144 changes: 7 additions & 137 deletions pyproj/geod.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,92 +35,10 @@

from pyproj._geod import Geod as _Geod
from pyproj._geod import geodesic_version_str
from pyproj._list import get_ellps_map
from pyproj.utils import _convertback, _copytobuffer

pj_ellps = {
"MERIT": {"a": 6378137.0, "rf": 298.257, "description": "MERIT 1983"},
"SGS85": {
"a": 6378136.0,
"rf": 298.257,
"description": "Soviet Geodetic System 85",
},
"GRS80": {
"a": 6378137.0,
"rf": 298.257222101,
"description": "GRS 1980(IUGG, 1980)",
},
"IAU76": {"a": 6378140.0, "rf": 298.257, "description": "IAU 1976"},
"airy": {"a": 6377563.396, "b": 6356256.910, "description": "Airy 1830"},
"APL4.9": {"a": 6378137.0, "rf": 298.25, "description": "Appl. Physics. 1965"},
"NWL9D": {"a": 6378145.0, "rf": 298.25, "description": " Naval Weapons Lab., 1965"},
"mod_airy": {"a": 6377340.189, "b": 6356034.446, "description": "Modified Airy"},
"andrae": {
"a": 6377104.43,
"rf": 300.0,
"description": "Andrae 1876 (Den., Iclnd.)",
},
"aust_SA": {
"a": 6378160.0,
"rf": 298.25,
"description": "Australian Natl & S. Amer. 1969",
},
"GRS67": {"a": 6378160.0, "rf": 298.2471674270, "description": "GRS 67(IUGG 1967)"},
"bessel": {"a": 6377397.155, "rf": 299.1528128, "description": "Bessel 1841"},
"bess_nam": {
"a": 6377483.865,
"rf": 299.1528128,
"description": "Bessel 1841 (Namibia)",
},
"clrk66": {"a": 6378206.4, "b": 6356583.8, "description": "Clarke 1866"},
"clrk80": {"a": 6378249.145, "rf": 293.4663, "description": "Clarke 1880 mod."},
"CPM": {
"a": 6375738.7,
"rf": 334.29,
"description": "Comm. des Poids et Mesures 1799",
},
"delmbr": {"a": 6376428.0, "rf": 311.5, "description": "Delambre 1810 (Belgium)"},
"engelis": {"a": 6378136.05, "rf": 298.2566, "description": "Engelis 1985"},
"evrst30": {"a": 6377276.345, "rf": 300.8017, "description": "Everest 1830"},
"evrst48": {"a": 6377304.063, "rf": 300.8017, "description": "Everest 1948"},
"evrst56": {"a": 6377301.243, "rf": 300.8017, "description": "Everest 1956"},
"evrst69": {"a": 6377295.664, "rf": 300.8017, "description": "Everest 1969"},
"evrstSS": {
"a": 6377298.556,
"rf": 300.8017,
"description": "Everest (Sabah & Sarawak)",
},
"fschr60": {
"a": 6378166.0,
"rf": 298.3,
"description": "Fischer (Mercury Datum) 1960",
},
"fschr60m": {"a": 6378155.0, "rf": 298.3, "description": "Modified Fischer 1960"},
"fschr68": {"a": 6378150.0, "rf": 298.3, "description": "Fischer 1968"},
"helmert": {"a": 6378200.0, "rf": 298.3, "description": "Helmert 1906"},
"hough": {"a": 6378270.0, "rf": 297.0, "description": "Hough"},
"intl": {
"a": 6378388.0,
"rf": 297.0,
"description": "International 1909 (Hayford)",
},
"krass": {"a": 6378245.0, "rf": 298.3, "description": "Krassovsky, 1942"},
"kaula": {"a": 6378163.0, "rf": 298.24, "description": "Kaula 1961"},
"lerch": {"a": 6378139.0, "rf": 298.257, "description": "Lerch 1979"},
"mprts": {"a": 6397300.0, "rf": 191.0, "description": "Maupertius 1738"},
"new_intl": {
"a": 6378157.5,
"b": 6356772.2,
"description": "New International 1967",
},
"plessis": {"a": 6376523.0, "b": 6355863.0, "description": "Plessis 1817 (France)"},
"SEasia": {"a": 6378155.0, "b": 6356773.3205, "description": "Southeast Asia"},
"walbeck": {"a": 6376896.0, "b": 6355834.8467, "description": "Walbeck"},
"WGS60": {"a": 6378165.0, "rf": 298.3, "description": "WGS 60"},
"WGS66": {"a": 6378145.0, "rf": 298.25, "description": "WGS 66"},
"WGS72": {"a": 6378135.0, "rf": 298.26, "description": "WGS 72"},
"WGS84": {"a": 6378137.0, "rf": 298.257223563, "description": "WGS 84"},
"sphere": {"a": 6370997.0, "b": 6370997.0, "description": "Normal Sphere"},
}
pj_ellps = get_ellps_map()


class Geod(_Geod):
Expand All @@ -144,66 +62,18 @@ def __init__(self, initstring=None, **kwargs):
Geodetic parameters for specifying the ellipsoid
can be given in a dictionary 'initparams', as keyword arguments,
or as as proj4 geod initialization string.
Following is a list of the ellipsoids that may be defined using the
'ellps' keyword (these are stored in the model variable pj_ellps)::
MERIT a=6378137.0 rf=298.257 MERIT 1983
SGS85 a=6378136.0 rf=298.257 Soviet Geodetic System 85
GRS80 a=6378137.0 rf=298.257222101 GRS 1980(IUGG, 1980)
IAU76 a=6378140.0 rf=298.257 IAU 1976
airy a=6377563.396 b=6356256.910 Airy 1830
APL4.9 a=6378137.0. rf=298.25 Appl. Physics. 1965
airy a=6377563.396 b=6356256.910 Airy 1830
APL4.9 a=6378137.0. rf=298.25 Appl. Physics. 1965
NWL9D a=6378145.0. rf=298.25 Naval Weapons Lab., 1965
mod_airy a=6377340.189 b=6356034.446 Modified Airy
andrae a=6377104.43 rf=300.0 Andrae 1876 (Den., Iclnd.)
aust_SA a=6378160.0 rf=298.25 Australian Natl & S. Amer. 1969
GRS67 a=6378160.0 rf=298.247167427 GRS 67(IUGG 1967)
bessel a=6377397.155 rf=299.1528128 Bessel 1841
bess_nam a=6377483.865 rf=299.1528128 Bessel 1841 (Namibia)
clrk66 a=6378206.4 b=6356583.8 Clarke 1866
clrk80 a=6378249.145 rf=293.4663 Clarke 1880 mod.
CPM a=6375738.7 rf=334.29 Comm. des Poids et Mesures 1799
delmbr a=6376428. rf=311.5 Delambre 1810 (Belgium)
engelis a=6378136.05 rf=298.2566 Engelis 1985
evrst30 a=6377276.345 rf=300.8017 Everest 1830
evrst48 a=6377304.063 rf=300.8017 Everest 1948
evrst56 a=6377301.243 rf=300.8017 Everest 1956
evrst69 a=6377295.664 rf=300.8017 Everest 1969
evrstSS a=6377298.556 rf=300.8017 Everest (Sabah & Sarawak)
fschr60 a=6378166. rf=298.3 Fischer (Mercury Datum) 1960
fschr60m a=6378155. rf=298.3 Modified Fischer 1960
fschr68 a=6378150. rf=298.3 Fischer 1968
helmert a=6378200. rf=298.3 Helmert 1906
hough a=6378270.0 rf=297. Hough
helmert a=6378200. rf=298.3 Helmert 1906
hough a=6378270.0 rf=297. Hough
intl a=6378388.0 rf=297. International 1909 (Hayford)
krass a=6378245.0 rf=298.3 Krassovsky, 1942
kaula a=6378163. rf=298.24 Kaula 1961
lerch a=6378139. rf=298.257 Lerch 1979
mprts a=6397300. rf=191. Maupertius 1738
new_intl a=6378157.5 b=6356772.2 New International 1967
plessis a=6376523. b=6355863. Plessis 1817 (France)
SEasia a=6378155.0 b=6356773.3205 Southeast Asia
walbeck a=6376896.0 b=6355834.8467 Walbeck
WGS60 a=6378165.0 rf=298.3 WGS 60
WGS66 a=6378145.0 rf=298.25 WGS 66
WGS72 a=6378135.0 rf=298.26 WGS 72
WGS84 a=6378137.0 rf=298.257223563 WGS 84
sphere a=6370997.0 b=6370997.0 Normal Sphere (r=6370997)
You can get a dictionary of ellipsoids using :func:`~pyproj.get_ellps_map`
or with the variable `pyproj.pj_ellps`.
The parameters of the ellipsoid may also be set directly using
the 'a' (semi-major or equatorial axis radius) keyword, and
any one of the following keywords: 'b' (semi-minor,
or polar axis radius), 'e' (eccentricity), 'es' (eccentricity
squared), 'f' (flattening), or 'rf' (reciprocal flattening).
See the proj documentation (https://github.com/OSGeo/proj.4/wiki) for more
information about specifying ellipsoid parameters (specifically,
the chapter 'Specifying the Earth's figure' in the main Proj
users manual).
See the proj documentation (https://proj4.org) for more
information about specifying ellipsoid parameters.
Example usage:
Expand Down
28 changes: 28 additions & 0 deletions pyproj/proj.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,31 @@ cdef extern from "proj.h":

PJ_GUESSED_WKT_DIALECT proj_context_guess_wkt_dialect(PJ_CONTEXT *ctx,
const char *wkt)

ctypedef struct PJ_OPERATIONS:
const char *id
PJ *(*proj)(PJ *)
const char * const *descr

const PJ_OPERATIONS *proj_list_operations()

ctypedef struct PJ_UNITS:
const char *id
const char *to_meter
const char *name
double factor
const PJ_UNITS *proj_list_units()
const PJ_UNITS *proj_list_angular_units()

ctypedef struct PJ_ELLPS:
const char *id # ellipse keyword name
const char *major # a= value
const char *ell # elliptical parameter
const char *name # comments
const PJ_ELLPS *proj_list_ellps()

ctypedef struct PJ_PRIME_MERIDIANS:
const char *id
const char *defn
const PJ_PRIME_MERIDIANS *proj_list_prime_meridians()

0 comments on commit 2365389

Please sign in to comment.