Skip to main content

[![DOI](https://zenodo.org/badge/73121780.svg)](https://zenodo.org/badge/latestdoi/73121780)

# pygeotools Libraries and command line tools for geospatial data processing and analysis

## Features - Resample/warp rasters to common resolution/extent/projection - Many functions to handle rasters with NoData gaps using [NumPy masked arrays](https://docs.scipy.org/doc/numpy/reference/maskedarray.generic.html) - Point data coordinate transformations, sampling, and interpolation routines (e.g., arrays of xyz points) - Common raster filtering operations

### Libraries [pygeotools/lib](./pygeotools/lib) - geolib - Coordinate transformations, raster to vector, vector to raster - malib - NumPy Masked Array operations, DEMStack class - warplib - On-the-fly GDAL warp operations for abitrary number of input datasets - iolib - File input/output, wrappers for GDAL I/O, masked array write to disk - timelib - Time conversions, extract timestamps from filenames, useful for raster time series analysis - filtlib - Collection of filters for 2D masked arrays (Gauss, rolling median, high pass, etc.)

### Command-line utilities (run with no arguments for usage) - warptool.py - Warp arbitrary rasters to common res/extent/proj - make_stack.py - Create a “stack” of input rasters (a raster time series object) and compute stats - clip_raster_by_shp.py - Clip and mask an input raster using a polygon shapefile - apply_mask.py - Apply mask from one raster to another - filter.py - Apply various filters available in filtlib - trim_ndv.py - Remove rows/cols containing only NoData from raster margins - replace_ndv.py - Replace NoData value - proj_select.py - Automatically determine projection for input lat/lon or raster - raster2shp.py - Create polygon shapefile of input raster footprints - ogr_merge.sh - Merge shapefiles - …

## Examples

### Warping multiple datasets to common grid, computing difference, writing out ` from pygeotools.lib import iolib, warplib, malib fn1 = 'raster1.tif' fn2 = 'raster2.tif' ds_list = warplib.memwarp_multi_fn([fn1, fn2], res='max', extent='intersection', t_srs='first', r='cubic') r1 = iolib.ds_getma(ds_list[0]) r2 = iolib.ds_getma(ds_list[1]) rdiff = r1 - r2 malib.print_stats(rdiff) out_fn = 'raster_diff.tif' iolib.writeGTiff(rdiff, out_fn, ds_list[0]) ` or, from the command line…

Warp all to match raster1.tif projection with common intersection and largest pixel size:

warptool.py -tr max -te intersection -t_srs first raster1.tif raster2.tif raster3.tif

Create version of raster1.tif that matches resolution, extent, and projection of raster2.tif:

warptool.py -tr raster2.tif -te raster2.tif -t_srs raster2.tif raster1.tif

Reproject and clip to user-defined extent, preserving original resolution of each input raster:

warptool.py -tr source -te ‘439090 5285360 458630 5306450’ -t_srs EPSG:32610 raster1.tif raster2.tif

### Creating a time series “stack” object: ` from pygeotools.lib import malib fn_list = ['20080101_dem.tif', '20090101_dem.tif', '20100101_dem.tif'] s = malib.DEMStack(fn_list, res='min', extent='union') #Stack standard deviation s.stack_std #Stack linear trend s.stack_trend ` or, from the command line…

make_stack.py -tr ‘min’ -te ‘union’ 20*.tif

## Documentation

http://pygeotools.readthedocs.io

## Installation

Install the latest release from PyPI:

pip install pygeotools

Note: by default, this will deploy executable scripts in /usr/local/bin

### Building from source

Clone the repository and install:

git clone https://github.com/dshean/pygeotools.git pip install -e pygeotools

The -e flag (“editable mode”, setuptools “develop mode”) will allow you to modify source code and immediately see changes.

### Core requirements - [GDAL/OGR](http://www.gdal.org/) - [NumPy](http://www.numpy.org/) - [SciPy](https://www.scipy.org/)

### Optional requirements (needed for some functionality) - [matplotlib](http://matplotlib.org/) - [NASA Ames Stereo Pipeline (ASP)](https://ti.arc.nasa.gov/tech/asr/intelligent-robotics/ngt/stereo/)

## Disclaimer

This originated as a personal repo that I am slowly cleaning up and distributing. There are some useful things that work very well, other things that were hastily written for a one-off task several years ago, and some confusing things that were never finished.

Contributions, bug reports, and general feedback are all welcome. My time is limited, I have some bad habits, and I could really use some help. Thanks in advance.

This was all originally developed for Python 2.X, but should now also work with Python 3.X thanks to [@dlilien](https://github.com/dlilien)

Some of this functionality now exists in the excellent, mature, well-supported [rasterio](https://github.com/mapbox/rasterio). Eventually, I will integrate rasterio API calls where appropriate.

## License

This project is licensed under the terms of the MIT License.

Release files for pygeotools 1.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pygeotools 1.1.4
File Size Uploaded
pygeotools-1.1.4.tar.gz 83.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pygeotools 1.1.4
File Interpreter ABI Platform
pygeotools-1.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 172.8 kB

Release files / pygeotools-1.1.4.tar.gz

Download URL pygeotools-1.1.4.tar.gz
Size 83.8 kB
Tags Source
SHA-256 checksum
How to use checksums
7745241b3a222c59d051cff1a76cb8ce97fbd098114bbbdfce32b6c5c1898813
BLAKE2b-256 checksum
How to use checksums
2e0cf7105a00a5ed636ffd86bd4a5e2ecaa32403b1444455cb995de36224616c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / pygeotools-1.1.4-py3-none-any.whl

Download URL pygeotools-1.1.4-py3-none-any.whl
Size 89.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f1313efa1b966817e5361c9c41f0f5d0afffb66b4a108b7fdef5825379c4252c
BLAKE2b-256 checksum
How to use checksums
fee66c331a5ca35a4b74b6fd698a8d0eb35237e4a1e4f6156ee3712d36391f10
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

1.1.4 This release

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

1 release file

0.6.0

1 release file

0.5.0

1 release file

0.4.0

1 release file

0.3.0

1 release file

0.2.0

1 release file

0.1.6

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page