Geometry

Geometry#

pytileproj has a lightweight setup and does not have GDAL and OGR as a direct dependency. Instead, it defines its own classes to store geospatial geometries. These geometries are used as an interface to and from many functions and class methods within pytileproj.

Several geospatial geometry classes are declared in pytileproj’s projgeom module and are defined by two properties:

  • geom: a shapely.Geometry instance, e.g. shapely.Point, shapely.Polygon, and shapely.MultiPolygon

  • crs: a pyproj.CRS instance

The simplest class, is the ProjCoord class defining a projected coordinate tuple.

import pyproj

from pytileproj import ProjCoord

proj_coord = ProjCoord(x=25, y=10, crs=pyproj.CRS.from_epsg(3857))
print(proj_coord)  # noqa: T201
ProjCoord 
--------- 
X: 
25 
Y: 
10 
Projection: 
+proj=merc +a=6378137 +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null +wktext +no_defs +type=crs

For geographical (longitude and latitude) coordinates, there is a child class GeogCoord:

from pytileproj import GeogCoord

geog_coord = GeogCoord(25, 10)
geog_coord
GeogCoord(25, 10)

All other geometries can be defined with the basic class ProjGeom:

from shapely import Polygon

from pytileproj import ProjGeom

geom = Polygon([(1, 1), (10, 2), (8, 7), (2, 4)])
proj_geom = ProjGeom(geom=geom, crs=pyproj.CRS.from_epsg(27701))
print(proj_geom)  # noqa: T201
ProjGeom 
-------- 
Geometry: 
POLYGON ((1 1, 10 2, 8 7, 2 4, 1 1)) 
Projection: 
+proj=aeqd +lat_0=8.5 +lon_0=21.5 +x_0=5621452.02 +y_0=5990638.423 +datum=WGS84 +units=m +no_defs +type=crs

Also here we can use a special class for geographic coordinates:

from pytileproj import GeogGeom

geog_geom = GeogGeom(geom=geom)
geog_geom
GeogGeom(POLYGON ((1 1, 10 2, 8 7, 2 4, 1 1)))