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.
New in 1.4.3
fio --version
New in 1.4.3
fio env --formats
fio info input.shp
fio info input.shp --format
fio info input.shp --bounds
fio info input.shp --crs
fio info input.shp --count
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
fio cat input.shp | fio load --format Shapefile output.shp
Using grep.
fio cat input.shp | grep -c "pattern"
Using jq.
fio cat input.shp | jq '.properties.my_prop=="pattern"' | grep -c "true"
fio cat input.shp --bbox "$WEST,$SOUTH,$EAST,$NORTH"
$ fio cat input.shp --bbox "`fio info other.shp --bounds | tr ' ' ','`"
fio cat input.shp --dst_crs EPSG:4326 \
| fio load --sequence --format Shapefile --dst_crs EPSG:4326 output.shp
TODO
fio cat *.shp | fio load --format Shapefile merged.shp
fio cat *.shp | fio collect > merged.json
Using jq for filtering and geojsonio-cli for display of results.
fio cat input.shp \
| jq 'select(.id=="10")' -c \
| fio collect \
| geojsonio
Using GNU Parallel
fio cat input.shp \
| parallel --pipe "jq -c 'select(.id==\"10\")'" \
| fio collect \
| geojsonio
TODO
New in 0.15
rio --version
New in 0.15
rio env --formats
As JSON – no more scraping the output of gdalinfo!
rio info input.tif
rio info input.tif --format
rio info input.tif --bounds
rio info input.tif --crs
rio info input.tif --count
And pipe to geojsonio-cli:
rio bounds input.tif | geojsonio
New in 0.15.
rio stack r.tif g.tif b.tif -o rgb.tif
rio shapes input.tif --bidx 1 > output.json
rio shapes input.tif --mask > output.json
rio-rasterize is new in 0.18
$ rio rasterize output.tif --res 0.0167 < input.geojson
rio-sample is new in 0.18.
$ cat << EOF | rio sample input.tif
> [220649.99999832606, 2719199.999999095]
> EOF
rio-edit-info is new in 0.24.
$ rio edit-info unreferenced.jpg --like referenced.tif --all
(Lots of other operations TODO)
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