Skip to main content

Tools for working with Geographical Information System Rasters

Project description

PyPiVersion PyPiDownloads BuildStatus CoverageStatus

The GeoRasters package is a python module that provides a fast and flexible tool to work with GIS raster files. It provides the GeoRaster class, which makes working with rasters quite transparent and easy. In a way it tries to do for rasters what GeoPandas does for geometries.

It includes tools to

  • Merge rasters

  • Plot rasters

  • Extract information from rasters

  • Given a point (lat,lon) find its location in a raster

  • Aggregate rasters to lower resolutions

  • Align two rasters of different sizes to common area and size

  • Get all the geographical information of raster

  • Create GeoTiff files easily

  • Load GeoTiff files as masked numpy rasters

  • Clip raster using geometries

  • Get zonal statistics using geometries

  • Spatial analysis tools

Install

pip install git+git://github.com/ozak/georasters.git
pip install georasters

Example Usage: GeoRasters

import georasters as gr

# Load data
raster = './data/slope.tif'
data = gr.from_file(raster)

# Plot data
data.plot()

# Get some stats
data.mean()
data.sum()
data.std()

# Convert to Pandas DataFrame
df = data.to_pandas()

# Save transformed data to GeoTiff
data2 = data**2
data2.to_tiff('./data2')

# Algebra with rasters
data3 = np.sin(data.raster) / data2
data3.plot()

# Notice that by using the data.raster object,
# you can do any mathematical operation that handles
# Numpy Masked Arrays

# Find value at point (x,y) or at vectors (X,Y)
value = data.map_pixel(x,y)
Value = data.map_pixel(X,Y)

Example Merge GeoRasters:

import os
import georasters as gr
import matplotlib.pyplot as plt

DATA = "/path/to/tiff/files"

# Import raster
raster = os.path.join(DATA, 'pre1500.tif')
data = gr.from_file(raster)
(xmin, xsize, x, ymax, y, ysize) = data.geot

# Split raster in two
data1 = gr.GeoRaster(
    data.raster[:data.shape[0] / 2, :],
    data.geot,
    nodata_value=data.nodata_value,
    projection=data.projection,
    datatype=data.datatype,
)
data2 = gr.GeoRaster(
    data.raster[data.shape[0] / 2:, :],
    (xmin, xsize, x, ymax + ysize * data.shape[0] / 2, y, ysize),
    nodata_value=data.nodata_value,
    projection=data.projection,
    datatype=data.datatype,
)

# Plot both parts and save them
plt.figure(figsize=(12, 8))
data1.plot()
plt.savefig(os.path.join(DATA, 'data1.png'), bbox_inches='tight')
./tests/data/data1.png
plt.figure(figsize=(12,8))
data2.plot()
plt.savefig(os.path.join(DATA,'data2.png'), bbox_inches='tight')
./tests/data/data2.png
# Generate merged raster

data3 = data1.union(data2)

# Plot it and save the figure

plt.figure(figsize=(12,8))
data3.plot()
plt.savefig(os.path.join(DATA,'data3.png'), bbox_inches='tight')
./tests/data/data3.png

Another Merge:

Example Usage: Other functions

import georasters as gr

# Get info on raster
NDV, xsize, ysize, GeoT, Projection, DataType = gr.get_geo_info(raster)

# Load raster
data = load_tiff(raster)

# Find location of point (x,y) on raster, e.g. to extract info at that location
col, row = gr.map_pixel(x,y,GeoT[1],GeoT[-1], GeoT[0],GeoT[3])
value = data[row,col]

# Agregate raster by summing over cells in order to increase pixel size by e.g. 10
gr.aggregate(data,NDV,(10,10))

# Align two rasters
data2 = load_tiff(raster2)
(alignedraster_o, alignedraster_a, GeoT_a) = gr.align_rasters(raster, raster2, how=np.mean)

# Create GeoRaster
A=gr.GeoRaster(data, GeoT, nodata_value=NDV)

# Load another raster
NDV, xsize, ysize, GeoT, Projection, DataType = gr.get_geo_info(raster2)
data = load_tiff(raster2)
B=gr.GeoRaster(data2, GeoT, nodata_value=NDV)

# Plot Raster
A.plot()

# Merge both rasters and plot
C=B.merge(A)
C.plot()

Issues

Find a bug? Report it via github issues by providing

  • a link to download the smallest possible raster and vector dataset necessary to reproduce the error

  • python code or command to reproduce the error

  • information on your environment: versions of python, gdal and numpy and system memory

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

georasters-0.5.24.tar.gz (31.7 kB view details)

Uploaded Source

Built Distribution

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

georasters-0.5.24-py2.py3-none-any.whl (30.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file georasters-0.5.24.tar.gz.

File metadata

  • Download URL: georasters-0.5.24.tar.gz
  • Upload date:
  • Size: 31.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.11.4 pkginfo/1.7.1 requests/2.28.1 requests-toolbelt/0.9.1 tqdm/4.64.0 CPython/3.9.7

File hashes

Hashes for georasters-0.5.24.tar.gz
Algorithm Hash digest
SHA256 7a908b7b87aa2e2ccd82e157d88a7712976ef2b4b6fed22932adf1217c5cd1df
MD5 8e0da4f901f1f5147e852518fae7e2fd
BLAKE2b-256 13e655126620f586a0a7050471e451444566498d6d2b00fa53e929a6ab0a58b7

See more details on using hashes here.

File details

Details for the file georasters-0.5.24-py2.py3-none-any.whl.

File metadata

  • Download URL: georasters-0.5.24-py2.py3-none-any.whl
  • Upload date:
  • Size: 30.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.11.4 pkginfo/1.7.1 requests/2.28.1 requests-toolbelt/0.9.1 tqdm/4.64.0 CPython/3.9.7

File hashes

Hashes for georasters-0.5.24-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 fb8ce5e6a9c88fb6a68ec51e405de934c8198f3142b8697c444e46ef8409018c
MD5 15a7c4ea48f4dbd8aba096477807b824
BLAKE2b-256 efbc4b65bec671069e8294dc893b07df1d269704d23a279ecc4be0470f9ebee5

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