Skip to main content

A set of useful utilities for working with geospatial data. Makes it simpler to do common operations.

Project description

geotypes

geotypes is a python package for making it easy to work with geospatial data, particularly useful for geospatial planning and analysis. It wraps GeoPandas and rasterio with simple data types to make it easier and more pythonic to work with for some applications.

Visit the documentation for installation, getting started, tutorials and API reference.

Geotypes adds some high-level wrappers around geopandas and shapely to allow for easier use. They allow easy conversion between georeference schemes, better tracking of what coordinate system the variables are in and easy conversion between types. These include:

  • GeoPoint
  • LL
  • GeoPath
  • GeoPoints
  • GeoArea
  • XY
  • LocalPath
  • LocalPoints
  • LocalArea
  • Raster

Installation

Use pip to install geotypes.

GDAL is not added to the requirements. If you already have libgdal-dev installed, you can use:

gdalversion=$(gdalinfo --version | cut -d\  -f2 | sed s'#,##') && pip3 install GDAL==$gdalversion

With GDAL installed or not, you can install geotypes with:

pip install git@github.com:jacksonhshields/geotypes.git

Tutorials

To get started with geotypes, check out the tutorials, which run you through the data types and how to use them.

Basic Usage

GeoPoint

The GeoPoint is an x,y coordinate with an associated Coordinate Reference System (CRS). It allows easy conversion to LL and XY data types.

p = geotypes.geometry.GeoPoint(x=151.28826000, y=-33.79798000, crs="epsg:4326") # initialise a lat, lon centred in Manly.
print("GeoPoint", p)
ll = p.to_ll() # Converts to lat,lon data type
print("In LL", ll)
p_utm = p.to_crs("EPSG:32756")  # converts to utm zone 56S
print("In UTM Zone 56S", p_utm)

LL

LL

The lat,lon data type is there for convience and to make it explicit about what is latitude, what is longitude.

ll = geotypes.geometry.LL(-33.79798000,151.28826000)
print(ll)
# Convert to geopoint
p = ll.to_geopoint()
print(p)

GeoPath

A path in geographic space, effectively a geopandas geoseries / shapely linestring with an associated CRS. It is commonly used to represent sampling transects (such as AUV transects). It has some convient functions to collect samples at set distances along the path - which can be done no-matter what coordinate system the path is in.

# Define a set of points. This is a simple broad grid in CRS "EPSG:32756"
points = [(342041.99358729343, 6259392.849573873),
 (342495.27623430215, 6259603.771833958),
 (342579.64503957686, 6259422.458960008),
 (342126.36269032373, 6259211.536449324),
 (342210.73189359176, 6259030.223443877),
 (342664.01394509675, 6259241.146205157)]

# create the geopath object
geopath = geotypes.geometry.GeoPath(points, crs="EPSG:32756")
print(geopath)

# Iterating over it returns a geopoint.
print("Geopoints:")
for p in geopath:
    print(p)
print("\n")

# Easily convert to other crs
geopath4326 = geopath.to_crs("EPSG:4326")
print(geopath4326)

# Sample points along the geopath
geopath_subsampled = geopath.sample_points_along_path(d=20) # sample a point every 20 meters.
print("Number of points in original {}, in subsampled {}".format(len(geopath), len(geopath_subsampled)))

GeoArea

A GeoArea is a wrapper around a geopandas GeoSeries with just one element, a polygon or multipolygon. They are used within the situ framework to represent sampling bounds or focal areas. As such, they have easy access to random sampling.

# Define a geoarea
geoarea = geotypes.geometry.GeoArea([(151.28412747953516, -33.78781691040293),
 (151.30572252046485, -33.78781691040293),
 (151.30572478467255, -33.805848131225765),
 (151.28412521532746, -33.805848131225765),
 (151.28412747953516, -33.78781691040293)], crs='EPSG:4326')

# get some samples from within it - these are GeoPoints:
for n in range(5):
    print(geoarea.random_point_geo())
# you can get also get points directly as LLs, regardless of the CRS.
for n in range(5):
    print(geoarea.random_point_ll())

Local Equivalents

There are local equivalents to the classes presented above. These include:

  • XY: Equivalent of GeoPoint
  • LocalPoints: Equivalent of GeoPoints
  • LocalPath: Equivalent of GeoPath
  • LocalArea: Equivalent of GeoArea These are just wrappers around the shapely geometry classes, but offer some extra functionality, including being able to convert to and from the Geo equivalents.
origin_ll = geoarea.centroid_ll()
# Convert the position to local
xy = p.to_local(origin_ll)
# Now go back to GeoPoint, this time with a different CRS.
pll = xy.to_geo(origin_ll, "epsg:4326")
# Print all to compare
print(p, xy, pll)


# Convert a GeoPath to a LocalPath
localpath = geopath.to_local(origin_ll)
# And go back again
geopath2 = localpath.to_geo(origin_ll, geopath.crs)

Rasters

There is an abstraction of rasterio Rasters to make it easier to work with rasters. You can use the Raster.get_value function with any geotypes geometry object to get the value or values at that point.

from geotypes.rasters import Raster
r = Raster('manly_uw.tif')
ll = LL(-33.79931, 151.29412)
from geotypes.geometry import LL
ll = LL(-33.79931, 151.29412)
r.get_value(ll)
>>> -7.871370315551758

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

geotypes-0.1.0.tar.gz (22.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

geotypes-0.1.0-py3-none-any.whl (20.1 kB view details)

Uploaded Python 3

File details

Details for the file geotypes-0.1.0.tar.gz.

File metadata

  • Download URL: geotypes-0.1.0.tar.gz
  • Upload date:
  • Size: 22.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for geotypes-0.1.0.tar.gz
Algorithm Hash digest
SHA256 adbb6639ae8a4e0af9f89fa80b929ead41f5fac2107b2268a3d9c552017f45aa
MD5 e6d7e68ac3aef9441dc24fe8bfbf0211
BLAKE2b-256 457a8a12a43f46d93f876147097147a9fe7bb382f1ac4450618adb7b230a5bb1

See more details on using hashes here.

File details

Details for the file geotypes-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: geotypes-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 20.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for geotypes-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c84e1a68bb155c7f9bf39916e9cc3799ea691a6991b2a23105fab22efdeb29c8
MD5 dcd5710a0c6c34fd6f1ae39607743878
BLAKE2b-256 7bfe90d4b38646a83328f5a8f5b9f688f435dba7900f1307937d2c3806dbdbc3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page