Gryd
Most used projections implemented
- Mercator
- Transverse Mercator
- Lambert Conformal Conic.
- Miller
- Eqc
CRS
Coordinates reference systems (crs) linked to these projections are available within python API using epsg id or name.
Four main grids are available:
- Universal Transverse Mercator
- Military Grid Reference System
- British National Grid
- Irish National Grid.
Raster map interpolation
Gryd.Crs
provides functions for raster map coordinates interpolation using
calibration Points
(two minimum are required).
Geodesic object
names
names(cls)
Return list of tuples (name and epsg reference) available in the sqlite database.
Arguments:
cls
Gryd.Epsg - Epsg instance
Returns:
(str
, int
) list
Geocentric Objects
class Geocentric(ctypes.Structure)
ctypes
structure for geocentric coordinates. This reference is generaly
used as a transition for datum conversion.
Attributes:
x
float - X-axis valuey
float - Y-axis valuez
float - Z-axis value
>>> Gryd.Geocentric(4457584, 429216, 4526544)
<X=4457584.000 Y=429216.000 Z=4526544.000>
>>> Gryd.Geocentric(x=4457584, y=429216, z=4526544)
<X=4457584.000 Y=429216.000 Z=4526544.000>
Point Objects
class Point(ctypes.Structure)
ctypes
structure for calibration point. It is used for coordinates
interpolation on a raster image. Two points minimum are required.
Attributes:
px
float - pixel column positionpy
float - pixel row positionlla
Gryd.Geodesic - geodesic coordinates associated to the pixel coordinatesxya
Gryd.Geographic - geographic coordinates associated to the pixel coordinates
Vincenty_dist Objects
class Vincenty_dist(ctypes.Structure)
Great circle distance computation result using Vincenty formulae.
Vincenty_dist
structures are returned by Gryd.Ellipsoid.distance
function.
Attributes:
distance
float - great circle distance in metersinitial_bearing
float - initial bearing in degreesfinal_bearing
float - final bearing in degrees
Vincenty_dest Objects
class Vincenty_dest(ctypes.Structure)
Great circle destination computation result using Vincenty formulae.
Vincenty_dist
structures are returned by Gryd.Ellipsoid.destination
function.
Attributes:
longitude
float - destination longitude in degreeslatitude
float - destination latitude in degreesdestination_bearing
float - destination bearing in degrees
Dms Objects
class Dms(ctypes.Structure)
Degrees Minutes Seconde value of a float value. Dms
structure are
returned by Gryd.dms
function.
>>> d = Gryd.dms(-60.42286847222222)
>>> d
-060°25'22.326''
>>> float(d)
-60.42286847222222
Attributes:
sign
int -1
if positive,-1
if negativedegree
float - integer parts of valueminute
float -1/60
fractions of valuesecond
float -1/3600
fractions of value
Dmm Objects
class Dmm(ctypes.Structure)
Degrees Minutes value of a float value. Dmm
structure are returned by
Gryd.dmm
function.
>>> d = Gryd.dmm(-60.42286847222222)
>>> d
-060°25.372108'
>>> float(d)
-60.42286847222222
Attributes:
sign
int -1
if positive,-1
if negativedegree
float - integer parts of valueminute
float -1/60
fractions of value
Epsg Objects
class Epsg(ctypes.Structure)
ctypes
structure with a sqlite connection to EPSG database for
initialization purpose.
sqlite
Shared sqlite database to be linked with
table
The table database name where __init__
will find data
__init__
| __init__(*args, **pairs)
If list of values is given as *args
, structure members are
initialized in the order of the field definition. If *args
only
contains one value:
- it is a
dict
then it is used as a reccord - it is an
int
then try to get a record from database using epsg id - it is a
str
then try to get a record from database using epsg name
All values in **pairs
are merged in the record before attributes
initialization.
if an attribute is not defined in the _fields_
list, it is set to the
python part of the class, not the ctypes
structure.
Unit Objects
class Unit(Epsg)
Unit ratio relative to meter.
>>> Gryd.Unit(9001)
<Unit epsg=9001 ratio=1.0>
>>> Gryd.Unit(epsg=9001).name
'metre'
>>> Gryd.Unit(name="foot")
<Unit epsg=9002 ratio=3.2808693302666354>
>>> float(Gryd.Unit(name="foot"))
3.2808693302666354
Attributes:
epsg
int - EPSG referenceratio
float - coeficient to apply for metter conversion
Prime Objects
class Prime(Epsg)
Prime meridian.
>>> prime = Gryd.Prime(epsg=8902)
>>> prime
<Prime meridian epsg=8902 longitude=-009°07'54.862''>
Attributes:
epsg
int - EPSG referencelongitude
float - latitude value
Ellipsoid Objects
class Ellipsoid(Epsg)
Ellipsoid model. If initialized with no args nor keyword args, it is a 6378137-meters-radius sphere.
>>> wgs84 = Gryd.Ellipsoid("WGS 84")
>>> wgs84
<Ellispoid epsg=7030 a=6378137.000000 1/f=298.25722356>
Attributes:
epsg
int - EPSG referencea
float - semi major axisb
float - semi minor axise
float - exentricityf
float - flattening
distance
| distance(lla0, lla1)
Return Vincenty distance between two geodesic points.
>>> london = Gryd.Geodesic(-0.127005, 51.518602, 0.)
>>> dublin = Gryd.Geodesic(-6.259437, 53.350765, 0.)
>>> wgs84.distance(dublin, london)
<Dist 464.025km initial bearing=113.6 final bearing=118.5°>
Arguments:
lla0
Gryd.Geodesic - point Alla1
Gryd.Geodesic - point B
Returns:
Gryd.Vincenty_dist
structure
destination
| destination(lla, bearing, distance)
Return Vincenty destination from geodesic start point following specific bearing with a determined distance.
>>> wgs84.destination(
... london, math.degrees(vdist.final_bearing) + 180, vdist.distance
... )
<Dest lon=-006°15'33.973'' lat=+053°21'2.754'' end bearing=-66.4°>
>>> dublin
<lon=-006°15'33.973'' lat=+053°21'2.754'' alt=0.000>
Arguments:
lla
Gryd.Geodesic - start pointbearing
float - start bearing in degreesdistance
float - distance in meters
Returns:
Gryd.Vincenty_dest
structure
npoints
| npoints(lla0, lla1, n)
Return number of intermediary geodesic coordinates points between two points using Vincenty formulae.
>>> for p in wgs84.npoints(dublin, londre, 4): print(p)
...
<Dest lon=-006°15'33.973'' lat=+053°21'2.754'' end bearing=113.6>
<Dest lon=-004°59'32.422'' lat=+053°00'36.687'' end bearing=114.6>
<Dest lon=-003°44'43.501'' lat=+052°39'22.715'' end bearing=115.6>
<Dest lon=-002°31'7.792'' lat=+052°17'22.201'' end bearing=116.6>
<Dest lon=-001°18'45.650'' lat=+051°54'36.502'' end bearing=117.5>
<Dest lon=-000°07'37.218'' lat=+051°31'6.967'' end bearing=118.5>
Arguments:
lla0
Gryd.Geodesic - start pointlla1
Gryd.Geodesic - end pointn
int - number uf intermediary points
Returns:
list of Gryd.Vincenty_dest
(start, *intermediaries, end)
Datum Objects
class Datum(Epsg)
Datum is defined by an ellipsoid, a prime meridian and a set of seven parameters to convert geodesic coordinates to wgs84.
>>> Gryd.Datum(epsg=4326)
<Datum epsg=4326:
<Ellispoid epsg=7030 a=6378137.000000 1/f=298.25722356>
<Prime meridian epsg=8901 longitude=0.000000>
to wgs84: 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0>
Attributes:
epsg
int - EPSG referenceprime
Gryd.Prime - prime meridianellispoid
Gryd.Ellipsoid - ellipsoidds
float - expansion coefdx
float - x-axis translation coefdy
float - y-axis translation coefdz
float - z-axis translation coefrx
float - x-axis rotation coefry
float - y-axis rotation coefrz
float - z-axis rotation coef
xyz
| xyz(lla)
Convert geodesic coordinates to geocentric coordinates.
>>> wgs84.xyz(london)
<X=3977018.848 Y=-8815.695 Z=4969650.564>
Arguments:
lla
Gryd.Geodesic - geodesic coordinates
Returns:
Gryd.Geocentric
coordinates
lla
| lla(xyz)
Convert geocentric coordinates to geodesic coordinates.
>>> wgs84.lla(wgs84.xyz(london))
<lon=-000°07'37.218'' lat=+051°31'6.967'' alt=0.000>
>>> london
<lon=-000°07'37.218'' lat=+051°31'6.967'' alt=0.000>
Arguments:
xyz
Gryd.Geodesic - geocentric coordinates
Returns:
Gryd.Geodesic
coordinates
transform
| transform(dst, lla)
Transform geodesic coordinates to another datum.
>>> airy = Gryd.Datum(epsg=4277)
>>> wgs84.transform(airy, london)
<lon=-000°07'31.431'' lat=+051°31'5.137'' alt=-46.118>
Arguments:
dst
Gryd.Datum - destination datumlla
Gryd.Geodesic - geodesic coordinates to transform
Returns:
Gryd.Geodesic
coordinates
Crs Objects
class Crs(Epsg)
Coordinate reference system object allowing projection of geodesic coordinates to flat map (geographic coordinates).
>>> pvs = Gryd.Crs(epsg=3785)
>>> osgb36 = Gryd.Crs(epsg=27700)
>>> osgb36.datum.xyz(london)
<X=3976632.017 Y=-8814.837 Z=4969286.446>
>>> osgb36.datum.ellipsoid.distance(dublin, london)
<Dist 463.981km initial bearing=113.6° final bearing=118.5°>
>>> osgb36
<Crs epsg=27700:
<Datum epsg=4277:
<Ellispoid epsg=7001 a=6377563.396000 1/f=299.32496460>
<Prime meridian epsg=8901 longitude=0.000000>
to wgs84 446.45,-125.16,542.06,-20.49,0.15,0.25,0.84>
<Unit epsg=9001 ratio=1.0>
Projection 'tmerc'>
Attributes:
epsg
int - EPSG referencedatum
Gryd.Datum - prime used in crsunit
Gryd.Unit - unit used in crslambda0
float - tmerc projection coefphi0
float - tmerc and omerc projection coefphi1
float - lcc projection coefphi2
float - lcc projection coefk0
float - tmerc projection coefx0
float - false northingy0
float - false eastingazimut
float - omerc projection coef
__reduce__
| __reduce__()
special method that allows Gryd.Crs
instance to be pickled
__call__
| __call__(element)
Heuristic transformation according to crs properties.
>>> osgb36(london) # projection of Geodesic point
<X=529939.106 Y=181680.962s alt=0.000>
>>> osgb36(osgb36(london)) # deprojection of Geographic point
<lon=-000°07'37.218'' lat=+051°31'6.967'' alt=0.000>
Arguments:
element
Gryd.Geodesic or Gryd.Geographic - coordinates to be transformed
Returns:
Gryd.Geographic
or Gryd.Geodesic
coordinates
transform
| transform(dst, xya)
Transform geographical coordinates to another coordinate reference system.
>>> london_pvs = osgb36.transform(pvs, osgb36(london))
>>> london_pvs
<X=-14317.072 Y=6680144.273s alt=-13015.770>
>>> pvs.transform(osgb36, london_pvs)
<X=529939.101 Y=181680.963s alt=0.012>
>>> osgb36(london)
<X=529939.106 Y=181680.962s alt=0.000>
Arguments:
dst
Gryd.Crs - destination coordinate reference systemxya
Gryd.Geographic - geographic coordinates to transform
Returns:
Gryd.Geographic
coordinates
add_map_point
| add_map_point(px, py, point)
Add a calibration point to coordinate reference system. Calibration points maps a specific pixel coordinates from a raster image (top left reference) to a geodesic coordinates and its associated geographic ones.
>>> # 512x512 pixel web map mercator
>>> pvs.add_map_point(0,0, Gryd.Geodesic(-179.999, 85))
>>> pvs.add_map_point(512,512, Gryd.Geodesic(179.999, -85))
>>> pvs.map_points
[<px=0 py=0
<lon=-179°59'56.400'' lat=+085°00'0.000'' alt=0.000>
<X=-20037397.023 Y=19971868.880s alt=0.000>
>, <px=512 py=512
<lon=+179°59'56.400'' lat=-085°00'0.000'' alt=0.000>
<X=20037397.023 Y=-19971868.880s alt=0.000>
>]
Arguments:
px
float - pixel column positionpy
float - pixel row positionpoint
Gryd.Geodesic or Gryd.Geographic - geodesic or geographic coordinates
delete_map_point
| delete_map_point(*points_or_indexes)
Delete multiple calibration points using index (starting with 1) or
Gryd.Point
reference.
pvs.delete_map_point(0)
[<px=512 py=512
<lon=+179°59'56.400'' lat=-085°00'0.000'' alt=0.000>
<X=20037397.023 Y=-19971868.880s alt=0.000>
>]
>>> pvs.delete_map_point(pvs.map_points[0])
[<px=0 py=0
<lon=-179°59'56.400'' lat=+085°00'0.000'' alt=0.000>
<X=-20037397.023 Y=19971868.880s alt=0.000>
>]
>>> pvs.map_points
[]
Arguments:
*points_or_indexes
int or Gryd.Point - index (starting with 1) or point reference
Returns:
list
of deleted Gryd.Point
map2crs
| map2crs(px, py, geographic=False)
Geodesic or geographic interpolation on raster image from pixel coordinates.
>>> pvs.map2crs(256+128, 256+128)
<lon=+089°59'58.20'' lat=-066°23'43.74'' alt=0.000>
>>> pvs.map2crs(256-128, 256+128, geographic=True)
<point X=-10018698.512 Y=-9985934.440s alt=0.000>
Arguments:
px
float - pixel column positionpy
float - pixel row positiongeographic
bool - determine coordinates type returned
Returns:
Gryd.Geographic
if geographic
is True else Gryd.Geodesic
crs2map
| crs2map(point)
Pixel interpolation on raster image from geodesic point.
>>> pvs.crs2map(london)
<px=256 py=170
<lon=-000°07'37.218'' lat=+051°31'6.967'' alt=0.000>
<X=-14138.132 Y=6713546.215s alt=0.000>
>
>>> pvs.crs2map(dublin)
<px=247 py=166
<lon=-006°15'33.973'' lat=+053°21'2.754'' alt=0.000>
<X=-696797.339 Y=7048145.354s alt=0.000>
>
Arguments:
point
Gryd.Geodesic or Gryd.Geographic - geodesic or geographic coordinates
Returns:
Gryd.Point