├── LICENSE └── README.md /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014, Sean Gillies 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of frs-cheat-sheet nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Fiona-Rasterio-Shapely Cheat Sheet 2 | ================================== 3 | 4 | A cheat sheet for Fiona/Rasterio/Shapely command-line geodata tools, with apologies to [@dwtkns](https://github.com/dwtkns/gdal-cheat-sheet). Suggestions welcome! 5 | 6 | See https://github.com/Toblerity/Fiona/blob/master/docs/cli.rst or `fio --help` and 7 | https://github.com/mapbox/rasterio/blob/master/docs/cli.rst or `rio --help` for more about Fiona and Rasterio commands. 8 | 9 | Vector operations 10 | --- 11 | 12 | #### Get Fiona version 13 | 14 | New in 1.4.3 15 | 16 | fio --version 17 | 18 | #### Enumerate format drivers 19 | 20 | New in 1.4.3 21 | 22 | fio env --formats 23 | 24 | #### Get vector information 25 | 26 | fio info input.shp 27 | 28 | #### Print vector format 29 | 30 | fio info input.shp --format 31 | 32 | #### Print vector extent 33 | 34 | fio info input.shp --bounds 35 | 36 | #### Print vector coordinate reference system 37 | 38 | fio info input.shp --crs 39 | 40 | #### Print count of features 41 | 42 | fio info input.shp --count 43 | 44 | #### Convert vectors to GeoJSON 45 | 46 | With coordinate reference system transformation and rounding of numbers to a constant precision. 47 | 48 | fio cat input.shp --dst_crs EPSG:4326 \ 49 | | fio collect --precision 6 > output.json 50 | 51 | #### Convert between vector formats 52 | 53 | fio cat input.shp | fio load --format Shapefile output.shp 54 | 55 | #### Print count of features with attributes matching a given pattern 56 | 57 | Using grep. 58 | 59 | fio cat input.shp | grep -c "pattern" 60 | 61 | Using [jq](http://stedolan.github.io/jq/). 62 | 63 | fio cat input.shp | jq '.properties.my_prop=="pattern"' | grep -c "true" 64 | 65 | #### Select features by long/lat bounding box 66 | 67 | fio cat input.shp --bbox "$WEST,$SOUTH,$EAST,$NORTH" 68 | 69 | #### Select features by bounds of another dataset 70 | 71 | $ fio cat input.shp --bbox "`fio info other.shp --bounds | tr ' ' ','`" 72 | 73 | #### Reproject vector 74 | 75 | fio cat input.shp --dst_crs EPSG:4326 \ 76 | | fio load --sequence --format Shapefile --dst_crs EPSG:4326 output.shp 77 | 78 | #### Merge features in a vector file by attribute ("dissolve") 79 | 80 | TODO 81 | 82 | #### Merge vector files 83 | 84 | fio cat *.shp | fio load --format Shapefile merged.shp 85 | 86 | #### Merge vector files (to GeoJSON) 87 | 88 | fio cat *.shp | fio collect > merged.json 89 | 90 | #### Filter a vector file 91 | 92 | Using jq for filtering and 93 | [geojsonio-cli](https://github.com/mapbox/geojsonio-cli) for display of results. 94 | 95 | fio cat input.shp \ 96 | | jq 'select(.id=="10")' -c \ 97 | | fio collect \ 98 | | geojsonio 99 | 100 | #### Filter a vector file in parallel 101 | 102 | Using GNU Parallel 103 | 104 | fio cat input.shp \ 105 | | parallel --pipe "jq -c 'select(.id==\"10\")'" \ 106 | | fio collect \ 107 | | geojsonio 108 | 109 | #### Subset & filter all shapefiles in a directory 110 | 111 | TODO 112 | 113 | Raster operations 114 | --- 115 | 116 | #### Get Rasterio version 117 | 118 | New in 0.15 119 | 120 | rio --version 121 | 122 | #### Enumerate format drivers 123 | 124 | New in 0.15 125 | 126 | rio env --formats 127 | 128 | #### Get raster information 129 | 130 | As JSON – no more scraping the output of gdalinfo! 131 | 132 | rio info input.tif 133 | 134 | #### Print raster format (not JSON) 135 | 136 | rio info input.tif --format 137 | 138 | #### Print raster extent 139 | 140 | rio info input.tif --bounds 141 | 142 | #### Print raster coordinate reference system 143 | 144 | rio info input.tif --crs 145 | 146 | #### Print count of raster bands 147 | 148 | rio info input.tif --count 149 | 150 | #### Get raster extent as GeoJSON 151 | 152 | And pipe to geojsonio-cli: 153 | 154 | rio bounds input.tif | geojsonio 155 | 156 | #### Concatenate or stack datasets together 157 | 158 | New in 0.15. 159 | 160 | rio stack r.tif g.tif b.tif -o rgb.tif 161 | 162 | #### Extract vectors from raster band as GeoJSON 163 | 164 | rio shapes input.tif --bidx 1 > output.json 165 | 166 | #### Extract data/nodata vectors from raster as GeoJSON 167 | 168 | rio shapes input.tif --mask > output.json 169 | 170 | #### Burn vector into raster 171 | 172 | [rio-rasterize](https://github.com/mapbox/rasterio/blob/master/docs/cli.rst#rasterize) is new in 0.18 173 | 174 | $ rio rasterize output.tif --res 0.0167 < input.geojson 175 | 176 | #### Sample values of a dataset 177 | 178 | [rio-sample](https://github.com/mapbox/rasterio/blob/master/docs/cli.rst#sample) is new in 0.18. 179 | 180 | ```bash 181 | $ cat << EOF | rio sample input.tif 182 | > [220649.99999832606, 2719199.999999095] 183 | > EOF 184 | ``` 185 | 186 | #### Copy georeferencing, tags, and nodata attribute from one dataset to another 187 | 188 | [rio-edit-info](https://github.com/mapbox/rasterio/blob/master/docs/cli.rst#edit-info) is new in 0.24. 189 | 190 | ```bash 191 | $ rio edit-info unreferenced.jpg --like referenced.tif --all 192 | ``` 193 | 194 | (Lots of other operations TODO) 195 | 196 | Coordinate transforms 197 | --- 198 | 199 | [Transform]( 200 | https://github.com/mapbox/rasterio/blob/master/docs/cli.rst#transform) long/lat to other CRS 201 | 202 | $ rio transform "[-78.0, 23.0]" --dst_crs EPSG:32618 --precision 2 203 | 204 | Transform many pairs of long/lat 205 | 206 | $ cat << EOF | rio transform --dst_crs EPSG:32618 --precision 2 207 | > [-78.0, 23.0] 208 | > [-79.0, 24.0] 209 | > EOF 210 | --------------------------------------------------------------------------------