Skip to main content

Some geographical tools for Python developers

Project description

GisTools

Some geographical tools for python developers

GitHub license Maintenance PyPI version fury.io

Introduction

GisTools is a small Python library for performing geographical computations. Typically, it gathers different tools from well-known libraries such as gdal, rasterio, geopandas, fiona and shapely. It allows easily mixing operations between vectors and raster maps (multi-band raster are not supported at the moment).

Basic operations

GisTools allows some of the following operations:

  • Fast polygon intersection and split
  • Polygon partition based on graph theory (requires METIS package)
  • Basic networking (shortest path)
  • Download DEM from online databases
  • Download layers from postgis spatial database
  • Extract raster statistics with respect to vector layers (polygon/line)
  • Raster to/from polygons conversion
  • Compute horizon obstruction from DEM

Requirements

See requirements.txt.

Note on GDAL

Installing GDAL through pip might be tricky as it only gets the bindings, so be sure the library is already installed on your machine, and that the headers are located in the right folder. Another solution may to install it through a third-party distribution such as conda.

Install

Pip installation should normally take care of everything for you.

Using PIP

The easiest way to install GisTools is using pip in a terminal

$ pip install gis-tools

Examples

Example 1

Use DigitalElevationModel, PolygonLayer and ZonalStatistics classes to retrieve average slope within each polygon of a shapefile

>>> dem = gistools.raster.DigitalElevationModel("path/to/dem.tif")
>>> slope = dem.compute_slope()
>>> layer = gistools.layer.PolygonLayer("path/to/layer.shp")
>>> zonal_stat = gistools.stats.ZonalStatistics(slope, layer, is_surface_weighted=False, all_touched=True)
>>> average = zonal_stat.mean()

Example 2

Extract polygons from contour values in raster

>>> from gistools.raster import RasterMap
>>> raster = RasterMap("path/to/raster.tif", no_data_value=-9999)
>>> layer = raster.contour(0.04, False).polygonize("attribute name").to_crs(epsg=4326)

Example 3: download and build DEM tile

Build DEM tile by downloading from CGIAR website and save to file

>>> from gistools import DigitalElevationModel
>>> dem = DigitalElevationModel.from_cgiar_online_database((8, 38, 14, 42))
>>> dem.to_file("path/to/dem.tif")

Example 4: partition a polygon

Split a polygon layer into sub-polygons of equal area with respect to honeycomb mesh (requires METIS package)

>>> polygon_layer = gistools.layer.PolygonLayer("path/to/layer.geojson")
>>> new_partitioned_layer = polygon_layer.partition(threshold=2000, disaggregation_factor=20, 
                                                    split_method="hexana", contig=True)

Note on OSM

You can use the fine osmnx package to download OSM features and then use it as any other GeoLayer :

from gistools.layer import PolygonLayer
import osmnx as ox
country = PolygonLayer.from_gpd(ox.geocode_to_gdf(
    dict(country="France",
         admin_level=2,
         type="boundary")))

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

gis_tools-0.17.8.tar.gz (68.0 kB view details)

Uploaded Source

File details

Details for the file gis_tools-0.17.8.tar.gz.

File metadata

  • Download URL: gis_tools-0.17.8.tar.gz
  • Upload date:
  • Size: 68.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.0 setuptools/50.3.1.post20201107 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.6.10

File hashes

Hashes for gis_tools-0.17.8.tar.gz
Algorithm Hash digest
SHA256 8345130c3d3944d8836ec8796252ffcd7c5aa65e89e34733d3c2d535f59d50e9
MD5 9309017a4f54900311d171feef4ae6f2
BLAKE2b-256 5f6f9a3825f05e819f114814dc488740fe9be20f0abec6a561d2a8570d92cd46

See more details on using hashes here.

Supported by

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