Skip to main content

A GDAL wrapper with Python conveniences

Project description

https://travis-ci.org/bkg/greenwich.svg?branch=master https://coveralls.io/repos/bkg/greenwich/badge.png?branch=master

Adding Python conveniences to the wonderful world of GDAL.

Greenwich provides a wrapper for the GDAL SWIG Python bindings. The focus here is on providing some higher level behavior mainly to the raster side of the GDAL/OGR fence.

Installation

The GDAL Python bindings need a little assistance in finding the pertinent headers when building from within a virtualenv. If the usual pip install greenwich fails, specify the GDAL header directory wherever that may be for you such as:

CFLAGS=-I/usr/include/gdal pip install greenwich

Basic Usage

Open any raster data set you have lying around, perhaps some climate data from WorldClim.

from greenwich import Geometry, Raster
from greenwich.io import MemFileIO

with Raster('cc85tn701.tif') as tmax:
    # Save as a NetCDF file.
    tmax.save('cc85tn701.nc')
    geom = Geometry(
        wkt='POLYGON((-123 47,-123 48,-122 49,-121 48,-121 47,-123 47))',
        srs=4326)
    # Clip the raster with a geometry and save the result as a GeoTIFF.
    with tmax.clip(geom) as clipped:
        clipped.save('clipped.tif')

    # Return a NumPy MaskedArray using nodata values for a given bounding box.
    m = tmax.masked_array((-120, 38, -118, 44))

    # Convert to an Erdas Imagine file in memory.
    imgio = MemFileIO(suffix='.img')
    tmax.save(imgio)
    imgdata = imgio.read()
    imgio.close()

    # Iterate over bands and retrieve the maximum pixel values.
    maxvals = [band.GetMaximum() for band in tmax]

Retrieve a NumPy array for a specific area by providing the extent as a 4-tuple of min/max x, y coordinates:

arr = tmax.array((-120, 38, -118, 44))

Reproject the raster to another coordinate system. You may pass EPSG codes, WKT, proj4 formatted projections, or a SpatialReference instance as an argument:

warped = tmax.warp(3857)

Perhaps you would like to resample your image to a new resolution which can be achieved with:

resampled = tmax.resample((100, 100))

Raster instances still behave like a gdal.Dataset:

meta = tmax.GetMetadata()

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

greenwich-0.8.0.tar.gz (16.5 kB view details)

Uploaded Source

File details

Details for the file greenwich-0.8.0.tar.gz.

File metadata

  • Download URL: greenwich-0.8.0.tar.gz
  • Upload date:
  • Size: 16.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for greenwich-0.8.0.tar.gz
Algorithm Hash digest
SHA256 8517dbb7da91964751e671adcd184a7954f70a1cbb0db30bc68be86808d464c4
MD5 94c1aeeca44351b9f971d7176638827b
BLAKE2b-256 c775526521d575cc67452936acc61036ee10161fa23f0abdfcfd9ebabfac81af

See more details on using hashes here.

Supported by

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