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:
clsGryd.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:
xfloat - X-axis valueyfloat - Y-axis valuezfloat - 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:
pxfloat - pixel column positionpyfloat - pixel row positionllaGryd.Geodesic - geodesic coordinates associated to the pixel coordinatesxyaGryd.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:
distancefloat - great circle distance in metersinitial_bearingfloat - initial bearing in degreesfinal_bearingfloat - 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:
longitudefloat - destination longitude in degreeslatitudefloat - destination latitude in degreesdestination_bearingfloat - 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:
signint -1if positive,-1if negativedegreefloat - integer parts of valueminutefloat -1/60fractions of valuesecondfloat -1/3600fractions 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:
signint -1if positive,-1if negativedegreefloat - integer parts of valueminutefloat -1/60fractions 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
dictthen it is used as a reccord - it is an
intthen try to get a record from database using epsg id - it is a
strthen 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:
epsgint - EPSG referenceratiofloat - 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:
epsgint - EPSG referencelongitudefloat - 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:
epsgint - EPSG referenceafloat - semi major axisbfloat - semi minor axisefloat - exentricityffloat - 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:
lla0Gryd.Geodesic - point Alla1Gryd.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:
llaGryd.Geodesic - start pointbearingfloat - start bearing in degreesdistancefloat - 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:
lla0Gryd.Geodesic - start pointlla1Gryd.Geodesic - end pointnint - 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:
epsgint - EPSG referenceprimeGryd.Prime - prime meridianellispoidGryd.Ellipsoid - ellipsoiddsfloat - expansion coefdxfloat - x-axis translation coefdyfloat - y-axis translation coefdzfloat - z-axis translation coefrxfloat - x-axis rotation coefryfloat - y-axis rotation coefrzfloat - 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:
llaGryd.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:
xyzGryd.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:
dstGryd.Datum - destination datumllaGryd.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:
epsgint - EPSG referencedatumGryd.Datum - prime used in crsunitGryd.Unit - unit used in crslambda0float - tmerc projection coefphi0float - tmerc and omerc projection coefphi1float - lcc projection coefphi2float - lcc projection coefk0float - tmerc projection coefx0float - false northingy0float - false eastingazimutfloat - 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:
elementGryd.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:
dstGryd.Crs - destination coordinate reference systemxyaGryd.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:
pxfloat - pixel column positionpyfloat - pixel row positionpointGryd.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_indexesint 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:
pxfloat - pixel column positionpyfloat - pixel row positiongeographicbool - 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:
pointGryd.Geodesic or Gryd.Geographic - geodesic or geographic coordinates
Returns:
Gryd.Point