GitXplorerGitXplorer
s

frs-cheat-sheet

public
102 stars
11 forks
0 issues

Commits

List of commits on branch master.
Unverified
4291872c72a35dd983716cc319545b5cda15bb17

Merge pull request #1 from gidden/seq

ssgillies committed 9 years ago
Unverified
288b84ac12a2c365da149edfa3f7d81c8c2d2d59

add --sequence to reproject vector based on https://github.com/Toblerity/Fiona/issues/328

ggidden committed 9 years ago
Unverified
7a4c96cf5629a322ee4e17618de45a5e12e2b370

Add rio-edit-info example

ssgillies committed 9 years ago
Unverified
a3f896c1b128bdd3cd28cb0226f2f339359a84c3

Update README.md

ssgillies committed 10 years ago
Unverified
2b52a1cf866e768dbd6e88180d14bfdafc615b6a

Update README.md

ssgillies committed 10 years ago
Unverified
599ce748fb22325a0b2caa0251064e25c5d37d5d

Add merging to GeoJSON example

ssgillies committed 10 years ago

README

The README file for this repository.

Fiona-Rasterio-Shapely Cheat Sheet

A cheat sheet for Fiona/Rasterio/Shapely command-line geodata tools, with apologies to @dwtkns. Suggestions welcome!

See https://github.com/Toblerity/Fiona/blob/master/docs/cli.rst or fio --help and https://github.com/mapbox/rasterio/blob/master/docs/cli.rst or rio --help for more about Fiona and Rasterio commands.

Vector operations

Get Fiona version

New in 1.4.3

fio --version

Enumerate format drivers

New in 1.4.3

fio env --formats

Get vector information

fio info input.shp

Print vector format

fio info input.shp --format

Print vector extent

fio info input.shp --bounds

Print vector coordinate reference system

fio info input.shp --crs

Print count of features

fio info input.shp --count

Convert vectors to GeoJSON

With coordinate reference system transformation and rounding of numbers to a constant precision.

fio cat input.shp --dst_crs EPSG:4326 \
| fio collect --precision 6 > output.json

Convert between vector formats

fio cat input.shp | fio load --format Shapefile output.shp

Print count of features with attributes matching a given pattern

Using grep.

fio cat input.shp | grep -c "pattern"

Using jq.

fio cat input.shp | jq '.properties.my_prop=="pattern"' | grep -c "true"

Select features by long/lat bounding box

fio cat input.shp --bbox "$WEST,$SOUTH,$EAST,$NORTH"

Select features by bounds of another dataset

$ fio cat input.shp --bbox "`fio info other.shp --bounds | tr ' ' ','`"

Reproject vector

fio cat input.shp --dst_crs EPSG:4326 \
| fio load --sequence --format Shapefile --dst_crs EPSG:4326 output.shp

Merge features in a vector file by attribute ("dissolve")

TODO

Merge vector files

fio cat *.shp | fio load --format Shapefile merged.shp

Merge vector files (to GeoJSON)

fio cat *.shp | fio collect > merged.json

Filter a vector file

Using jq for filtering and geojsonio-cli for display of results.

fio cat input.shp \
| jq 'select(.id=="10")' -c \
| fio collect \
| geojsonio

Filter a vector file in parallel

Using GNU Parallel

fio cat input.shp \
| parallel --pipe "jq -c 'select(.id==\"10\")'" \
| fio collect \
| geojsonio

Subset & filter all shapefiles in a directory

TODO

Raster operations

Get Rasterio version

New in 0.15

rio --version

Enumerate format drivers

New in 0.15

rio env --formats

Get raster information

As JSON – no more scraping the output of gdalinfo!

rio info input.tif

Print raster format (not JSON)

rio info input.tif --format

Print raster extent

rio info input.tif --bounds

Print raster coordinate reference system

rio info input.tif --crs

Print count of raster bands

rio info input.tif --count

Get raster extent as GeoJSON

And pipe to geojsonio-cli:

rio bounds input.tif | geojsonio

Concatenate or stack datasets together

New in 0.15.

rio stack r.tif g.tif b.tif -o rgb.tif

Extract vectors from raster band as GeoJSON

rio shapes input.tif --bidx 1 > output.json

Extract data/nodata vectors from raster as GeoJSON

rio shapes input.tif --mask > output.json

Burn vector into raster

rio-rasterize is new in 0.18

$ rio rasterize output.tif --res 0.0167 < input.geojson

Sample values of a dataset

rio-sample is new in 0.18.

$ cat << EOF | rio sample input.tif
> [220649.99999832606, 2719199.999999095]
> EOF

Copy georeferencing, tags, and nodata attribute from one dataset to another

rio-edit-info is new in 0.24.

$ rio edit-info unreferenced.jpg --like referenced.tif --all

(Lots of other operations TODO)

Coordinate transforms

Transform long/lat to other CRS

$ rio transform "[-78.0, 23.0]" --dst_crs EPSG:32618 --precision 2

Transform many pairs of long/lat

$ cat << EOF | rio transform --dst_crs EPSG:32618 --precision 2
> [-78.0, 23.0]
> [-79.0, 24.0]
> EOF