GDAL/OGR
Jakob Miksch
jakob@meggsimum.de
@jakobmiksch
@jakobmiksch
Geospatial Developer
OSGeo Foundation Charter Member
meggsimum
info@meggsimum.de
@meggsimum
@meggsimum
meggsimum.de
services in the field of GIS, webmapping & SDI
tailored WebGIS solutions
software development
geodata
consulting and training
## GDAL/OGR [www.gdal.org](https://gdal.org/) - C/C++ Library for geospatial data - conversion - transformation - processing
## GDAL/OGR [gdal.org](https://gdal.org/) most vector/raster formats
## Development [github.com/OSGeo/gdal](https://github.com/OSGeo/gdal/)
## Support [gdal.org/sponsors](https://gdal.org/sponsors/index.html)
## GDAL/OGR - used by [many programs](https://gdal.org/software_using_gdal.html#software-using-gdal): - QGIS, ArcGIS, Google Earth, ... - bindings to: - Python, R, Java, ... - commandline
## Commandline direct interface to computer
NOTE: - automation - reproducibility - without user interface - useful for server or docker - GDAL/OGR commands are a bit tricky at the beginning, but are very powerfull once understood
## Installation - **Linux**: via package manager ```shell $ sudo apt install gdal-bin ``` - **Windows**: [OSGeo4W](https://trac.osgeo.org/osgeo4w/) shell
## QGIS helps with commands
Raster
## gdalinfo digital elevation model Tirol
by [Land Tirol - data.tirol.gv.at](https://www.data.gv.at/katalog/dataset/land-tirol_tirolgelnde) - [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/deed.de)
## gdalinfo ```shell $ gdalinfo tirol.tif ``` output: ```text Driver: GTiff/GeoTIFF Files: tirol.tif tirol.tif.aux.xml Size is 43880, 24265 Coordinate System is: PROJCRS["MGI / Austria GK West", BASEGEOGCRS["MGI", DATUM["Militar-Geographische Institut", ELLIPSOID["Bessel 1841",6377397.155,299.1528128, LENGTHUNIT["metre",1]]], PRIMEM["Greenwich",0, ANGLEUNIT["degree",0.0174532925199433]], ID["EPSG",4312]], CONVERSION["Austria Gauss-Kruger West", METHOD["Transverse Mercator", ID["EPSG",9807]], PARAMETER["Latitude of natural origin",0, ANGLEUNIT["degree",0.0174532925199433], ID["EPSG",8801]], PARAMETER["Longitude of natural origin",10.3333333333333, ANGLEUNIT["degree",0.0174532925199433], ID["EPSG",8802]], PARAMETER["Scale factor at natural origin",1, SCALEUNIT["unity",1], ID["EPSG",8805]], PARAMETER["False easting",0, LENGTHUNIT["metre",1], ID["EPSG",8806]], PARAMETER["False northing",-5000000, LENGTHUNIT["metre",1], ID["EPSG",8807]]], CS[Cartesian,2], AXIS["northing (X)",north, ORDER[1], LENGTHUNIT["metre",1]], AXIS["easting (Y)",east, ORDER[2], LENGTHUNIT["metre",1]], USAGE[ SCOPE["Engineering survey, topographic mapping."], AREA["Austria west of 11°50'E of Greenwich (29°30'E of Ferro)."], BBOX[46.77,9.53,47.61,11.84]], ID["EPSG",31254]] Data axis to CRS axis mapping: 2,1 Origin = (-18187.500000000000000,291477.500000000000000) Pixel Size = (5.000000000000000,-5.000000000000000) Metadata: AREA_OR_POINT=Area DataType=Elevation Image Structure Metadata: COMPRESSION=DEFLATE INTERLEAVE=BAND Corner Coordinates: Upper Left ( -18187.500, 291477.500) ( 10d 5'26.52"E, 47d45'43.96"N) Lower Left ( -18187.500, 170152.500) ( 10d 5'44.26"E, 46d40'14.89"N) Upper Right ( 201212.500, 291477.500) ( 13d 0'58.12"E, 47d43'51.96"N) Lower Right ( 201212.500, 170152.500) ( 12d57'42.23"E, 46d38'27.06"N) Center ( 91512.500, 230815.000) ( 11d32'29.27"E, 47d12'37.49"N) Band 1 Block=256x256 Type=Float32, ColorInterp=Gray Min=460.496 Max=3796.002 Minimum=460.496, Maximum=3796.002, Mean=1743.038, StdDev=649.372 NoData Value=-9999 Metadata: RepresentationType=ATHEMATIC STATISTICS_COVARIANCES=421683.5509713619 STATISTICS_MAXIMUM=3796.001953125 STATISTICS_MEAN=1743.0380317268 STATISTICS_MINIMUM=460.49600219727 STATISTICS_SKIPFACTORX=1 STATISTICS_SKIPFACTORY=1 STATISTICS_STDDEV=649.3716585834 ```
## gdalinfo with JSON output ```shell $ gdalinfo \ -json \ tirol.tif ``` output: ```json { "description":"tirol.tif", "driverShortName":"GTiff", "driverLongName":"GeoTIFF", "files":[ "tirol.tif", "tirol.tif.aux.xml" ], "size":[ 43880, 24265 ], "coordinateSystem":{ "wkt":"PROJCRS[\"MGI / Austria GK West\",\n BASEGEOGCRS[\"MGI\",\n DATUM[\"Militar-Geographische Institut\",\n ELLIPSOID[\"Bessel 1841\",6377397.155,299.1528128,\n LENGTHUNIT[\"metre\",1]]],\n PRIMEM[\"Greenwich\",0,\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n ID[\"EPSG\",4312]],\n CONVERSION[\"Austria Gauss-Kruger West\",\n METHOD[\"Transverse Mercator\",\n ID[\"EPSG\",9807]],\n PARAMETER[\"Latitude of natural origin\",0,\n ANGLEUNIT[\"degree\",0.0174532925199433],\n ID[\"EPSG\",8801]],\n PARAMETER[\"Longitude of natural origin\",10.3333333333333,\n ANGLEUNIT[\"degree\",0.0174532925199433],\n ID[\"EPSG\",8802]],\n PARAMETER[\"Scale factor at natural origin\",1,\n SCALEUNIT[\"unity\",1],\n ID[\"EPSG\",8805]],\n PARAMETER[\"False easting\",0,\n LENGTHUNIT[\"metre\",1],\n ID[\"EPSG\",8806]],\n PARAMETER[\"False northing\",-5000000,\n LENGTHUNIT[\"metre\",1],\n ID[\"EPSG\",8807]]],\n CS[Cartesian,2],\n AXIS[\"northing (X)\",north,\n ORDER[1],\n LENGTHUNIT[\"metre\",1]],\n AXIS[\"easting (Y)\",east,\n ORDER[2],\n LENGTHUNIT[\"metre\",1]],\n USAGE[\n SCOPE[\"Engineering survey, topographic mapping.\"],\n AREA[\"Austria west of 11°50'E of Greenwich (29°30'E of Ferro).\"],\n BBOX[46.77,9.53,47.61,11.84]],\n ID[\"EPSG\",31254]]", "dataAxisToSRSAxisMapping":[ 2, 1 ] }, "geoTransform":[ -18187.5, 5.0, 0.0, 291477.5, 0.0, -5.0 ], "metadata":{ "":{ "AREA_OR_POINT":"Area", "DataType":"Elevation" }, "IMAGE_STRUCTURE":{ "COMPRESSION":"DEFLATE", "INTERLEAVE":"BAND" } }, "cornerCoordinates":{ "upperLeft":[ -18187.5, 291477.5 ], "lowerLeft":[ -18187.5, 170152.5 ], "lowerRight":[ 201212.5, 170152.5 ], "upperRight":[ 201212.5, 291477.5 ], "center":[ 91512.5, 230815.0 ] }, "wgs84Extent":{ "type":"Polygon", "coordinates":[ [ [ 10.0903894, 47.7615684 ], [ 10.0953809, 46.6702868 ], [ 12.9610971, 46.6404207 ], [ 13.0154327, 47.7305462 ], [ 10.0903894, 47.7615684 ] ] ] }, "bands":[ { "band":1, "block":[ 256, 256 ], "type":"Float32", "colorInterpretation":"Gray", "min":460.496, "max":3796.002, "minimum":460.496, "maximum":3796.002, "mean":1743.038, "stdDev":649.372, "noDataValue":-9999.0, "metadata":{ "":{ "RepresentationType":"ATHEMATIC", "STATISTICS_COVARIANCES":"421683.5509713619", "STATISTICS_MAXIMUM":"3796.001953125", "STATISTICS_MEAN":"1743.0380317268", "STATISTICS_MINIMUM":"460.49600219727", "STATISTICS_SKIPFACTORX":"1", "STATISTICS_SKIPFACTORY":"1", "STATISTICS_STDDEV":"649.3716585834" } } } ] } ```
## gdalinfo histogram ```shell $ gdalinfo \ -hist \ -json \ tirol.tif ``` output: ```json { "description":"tirol.tif", "driverShortName":"GTiff", "driverLongName":"GeoTIFF", "files":[ "tirol.tif", "tirol.tif.aux.xml" ], "size":[ 43880, 24265 ], "coordinateSystem":{ "wkt":"PROJCRS[\"MGI / Austria GK West\",\n BASEGEOGCRS[\"MGI\",\n DATUM[\"Militar-Geographische Institut\",\n ELLIPSOID[\"Bessel 1841\",6377397.155,299.1528128,\n LENGTHUNIT[\"metre\",1]]],\n PRIMEM[\"Greenwich\",0,\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n ID[\"EPSG\",4312]],\n CONVERSION[\"Austria Gauss-Kruger West\",\n METHOD[\"Transverse Mercator\",\n ID[\"EPSG\",9807]],\n PARAMETER[\"Latitude of natural origin\",0,\n ANGLEUNIT[\"degree\",0.0174532925199433],\n ID[\"EPSG\",8801]],\n PARAMETER[\"Longitude of natural origin\",10.3333333333333,\n ANGLEUNIT[\"degree\",0.0174532925199433],\n ID[\"EPSG\",8802]],\n PARAMETER[\"Scale factor at natural origin\",1,\n SCALEUNIT[\"unity\",1],\n ID[\"EPSG\",8805]],\n PARAMETER[\"False easting\",0,\n LENGTHUNIT[\"metre\",1],\n ID[\"EPSG\",8806]],\n PARAMETER[\"False northing\",-5000000,\n LENGTHUNIT[\"metre\",1],\n ID[\"EPSG\",8807]]],\n CS[Cartesian,2],\n AXIS[\"northing (X)\",north,\n ORDER[1],\n LENGTHUNIT[\"metre\",1]],\n AXIS[\"easting (Y)\",east,\n ORDER[2],\n LENGTHUNIT[\"metre\",1]],\n USAGE[\n SCOPE[\"Engineering survey, topographic mapping.\"],\n AREA[\"Austria west of 11°50'E of Greenwich (29°30'E of Ferro).\"],\n BBOX[46.77,9.53,47.61,11.84]],\n ID[\"EPSG\",31254]]", "dataAxisToSRSAxisMapping":[ 2, 1 ] }, "geoTransform":[ -18187.5, 5.0, 0.0, 291477.5, 0.0, -5.0 ], "metadata":{ "":{ "AREA_OR_POINT":"Area", "DataType":"Elevation" }, "IMAGE_STRUCTURE":{ "COMPRESSION":"DEFLATE", "INTERLEAVE":"BAND" } }, "cornerCoordinates":{ "upperLeft":[ -18187.5, 291477.5 ], "lowerLeft":[ -18187.5, 170152.5 ], "lowerRight":[ 201212.5, 170152.5 ], "upperRight":[ 201212.5, 291477.5 ], "center":[ 91512.5, 230815.0 ] }, "wgs84Extent":{ "type":"Polygon", "coordinates":[ [ [ 10.0903894, 47.7615684 ], [ 10.0953809, 46.6702868 ], [ 12.9610971, 46.6404207 ], [ 13.0154327, 47.7305462 ], [ 10.0903894, 47.7615684 ] ] ] }, "bands":[ { "band":1, "block":[ 256, 256 ], "type":"Float32", "colorInterpretation":"Gray", "min":460.496, "max":3796.002, "minimum":460.496, "maximum":3796.002, "mean":1743.038, "stdDev":649.372, "histogram":{ "count":256, "min":453.95579445035293, "max":3802.5421608719171, "buckets":[ 122307, 444451, 692463, 739296, 1059772, 1343431, 1109441, 1225387, 1385797, 1566467, 1387877, 1439655, 1536478, 1632861, 1854065, 1870077, 1751666, 1553370, 1439856, 1402075, 1535812, 1579325, 1629047, 1776246, 1917626, 2026873, 2073550, 2226755, 2371506, 2553156, 2566083, 2548920, 2454397, 2387842, 2387187, 2408336, 2914860, 2572179, 2636912, 2915787, 2778913, 2774631, 2803680, 2799514, 2798174, 2798773, 2870353, 3008508, 2976983, 3072212, 3139523, 3103186, 3070381, 3192485, 3251495, 3232797, 3273707, 3236792, 3249312, 3228953, 3254788, 3308216, 3317771, 3340063, 3315998, 3346994, 3362254, 3383965, 3441874, 3454326, 3504309, 3497329, 3533257, 3542251, 3500928, 3504388, 3506477, 3509129, 3506324, 3516995, 3520598, 3496040, 3491038, 3502705, 3512497, 3478265, 3442015, 3422658, 3424500, 3454337, 3454086, 3431835, 3409280, 3406328, 3410650, 3389070, 3380332, 3372305, 3366841, 3453872, 3448400, 3379328, 3381607, 3380911, 3387483, 3379827, 3445987, 3394435, 3381411, 3359465, 3355885, 3347062, 3337602, 3318643, 3284101, 3278774, 3286904, 3256878, 3252365, 3271679, 3236043, 3227418, 3201516, 3189828, 3173346, 3168684, 3180299, 3181184, 3164391, 3149644, 3131087, 3134175, 3109493, 3115573, 3108981, 3099581, 3064926, 3031757, 3030904, 3002944, 2981753, 2938898, 2944413, 2881032, 2842539, 2821577, 2788879, 2758910, 2721441, 2709682, 2675260, 2658290, 2624042, 2572219, 2528461, 2495675, 2469777, 2447914, 2398723, 2363383, 2335677, 2310260, 2281003, 2223896, 2173762, 2111542, 2066586, 2007884, 1975536, 1917980, 1866749, 1825604, 1769497, 1719218, 1647867, 1593665, 1534334, 1483474, 1431555, 1374711, 1327759, 1277803, 1230051, 1181132, 1135248, 1101789, 1062709, 1016084, 991748, 952530, 904435, 869935, 834904, 810366, 781731, 756625, 725968, 688974, 661061, 625758, 597959, 565520, 537595, 510409, 490088, 463743, 447119, 432571, 402791, 373988, 350690, 325710, 302904, 283531, 264594, 235792, 209136, 189514, 175188, 161357, 147117, 130812, 114836, 98995, 90033, 85100, 70379, 58161, 48426, 40018, 34456, 27777, 22735, 16503, 13261, 11041, 9027, 7214, 6459, 5923, 5552, 4869, 4377, 4050, 3632, 2574, 2030, 1599, 1170, 821, 606, 449, 228, 88, 62, 13 ] }, "noDataValue":-9999.0, "metadata":{ "":{ "RepresentationType":"ATHEMATIC", "STATISTICS_COVARIANCES":"421683.5509713619", "STATISTICS_MAXIMUM":"3796.001953125", "STATISTICS_MEAN":"1743.0380317268", "STATISTICS_MINIMUM":"460.49600219727", "STATISTICS_SKIPFACTORX":"1", "STATISTICS_SKIPFACTORY":"1", "STATISTICS_STDDEV":"649.3716585834" } } } ] } ```
## gdalinfo remote datasource ```shell $ gdalinfo \ WMS:https://services.meggsimum.de/geoserver/ows ``` output: ```text Driver: WMS/OGC Web Map Service Files: none associated Size is 512, 512 Subdatasets: SUBDATASET_1_NAME=WMS:https://services.meggsimum.de/geoserver/wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&LAYERS=mgsm-world%3Ane_10m_admin_0_countries&SRS=EPSG:4326&BBOX=-180.0,-90.0,180.0,83.6341 SUBDATASET_1_DESC=World Countries SUBDATASET_2_NAME=WMS:https://services.meggsimum.de/geoserver/wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&LAYERS=mgsm-world%3Ane_10m_populated_places&SRS=EPSG:4326&BBOX=-179.59,-90.0,179.383,82.4833 SUBDATASET_2_DESC=World Places SUBDATASET_3_NAME=WMS:https://services.meggsimum.de/geoserver/wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&LAYERS=mgsm-world%3Ane_10m_rivers_lake_centerlines&SRS=EPSG:4326&BBOX=-164.903,-52.1577,177.52,75.7935 SUBDATASET_3_DESC=World Rivers SUBDATASET_4_NAME=WMS:https://services.meggsimum.de/geoserver/wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&LAYERS=mgsm-world%3Ane_world&SRS=EPSG:4326&BBOX=-189.00892604139275,-114.50858369100003,189.00892604139275,114.508583691 SUBDATASET_4_DESC=World Image SUBDATASET_5_NAME=WMS:https://services.meggsimum.de/geoserver/wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&LAYERS=mgsm-ger%3Apostal_codes_germany&SRS=EPSG:4326&BBOX=5.86632,47.2701,15.0419,55.0587 SUBDATASET_5_DESC=Postal Codes Germany Corner Coordinates: Upper Left ( 0.0, 0.0) Lower Left ( 0.0, 512.0) Upper Right ( 512.0, 0.0) Lower Right ( 512.0, 512.0) Center ( 256.0, 256.0) ```
## gdalinfo specific subset (layer) ```shell $ gdalinfo \ WMS:https://services.meggsimum.de/geoserver/ows \ -sd 4 ``` output: ```json Driver: WMS/OGC Web Map Service Files: none associated Size is 1073741824, 650512428 Coordinate System is: GEOGCRS["WGS 84", DATUM["World Geodetic System 1984", ELLIPSOID["WGS 84",6378137,298.257223563, LENGTHUNIT["metre",1]]], PRIMEM["Greenwich",0, ANGLEUNIT["degree",0.0174532925199433]], CS[ellipsoidal,2], AXIS["geodetic latitude (Lat)",north, ORDER[1], ANGLEUNIT["degree",0.0174532925199433]], AXIS["geodetic longitude (Lon)",east, ORDER[2], ANGLEUNIT["degree",0.0174532925199433]], ID["EPSG",4326]] Data axis to CRS axis mapping: 2,1 Origin = (-189.008926041392755,114.508583690999998) Pixel Size = (0.000000352056559,-0.000000352056560) Image Structure Metadata: INTERLEAVE=PIXEL Corner Coordinates: Upper Left ( -189.009, 114.509) (189d 0'32.13"W,114d30'30.90"N) Lower Left ( -189.009, -114.509) (189d 0'32.13"W,114d30'30.90"S) Upper Right ( 189.009, 114.509) (189d 0'32.13"E,114d30'30.90"N) Lower Right ( 189.009, -114.509) (189d 0'32.13"E,114d30'30.90"S) Center ( 0.0000000, -0.0000000) ( 0d 0' 0.01"E, 0d 0' 0.00"S) Band 1 Block=1024x1024 Type=Byte, ColorInterp=Red Overviews: 536870912x325256214, 268435456x162628107, 134217728x81314054, 67108864x40657027, 33554432x20328513, 16777216x10164257, 8388608x5082128, 4194304x2541064, 2097152x1270532, 1048576x635266, 524288x317633, 262144x158817, 131072x79408, 65536x39704, 32768x19852, 16384x9926, 8192x4963, 4096x2482, 2048x1241, 1024x620 Band 2 Block=1024x1024 Type=Byte, ColorInterp=Green Overviews: 536870912x325256214, 268435456x162628107, 134217728x81314054, 67108864x40657027, 33554432x20328513, 16777216x10164257, 8388608x5082128, 4194304x2541064, 2097152x1270532, 1048576x635266, 524288x317633, 262144x158817, 131072x79408, 65536x39704, 32768x19852, 16384x9926, 8192x4963, 4096x2482, 2048x1241, 1024x620 Band 3 Block=1024x1024 Type=Byte, ColorInterp=Blue Overviews: 536870912x325256214, 268435456x162628107, 134217728x81314054, 67108864x40657027, 33554432x20328513, 16777216x10164257, 8388608x5082128, 4194304x2541064, 2097152x1270532, 1048576x635266, 524288x317633, 262144x158817, 131072x79408, 65536x39704, 32768x19852, 16384x9926, 8192x4963, 4096x2482, 2048x1241, 1024x620 ```
## gdal_translate assign a projection ```shell $ gdal_translate \ -a_srs EPSG:4326 input.tif \ output.tif ```
## gdal_translate reduce size ```shell $ gdal_translate \ -outsize 40% 40% \ earth.tif \ earth50.tif ```
## gdalwarp reproject raster ```shell $ gdalwarp \ -t_srs EPSG:4326 \ input.tif \ output.tif ```
## gdalwarp raster earth
## gdalwarp crop by coordinates ```shell $ gdalwarp \ -te -29.7 35.0 47.1 72.4 \ -te_srs EPSG:4326 \ earth.tif \ europe.tif ```
## gdalwarp crop by layer ```shell $ gdalwarp \ -cutline countries.shp \ -cl countries \ -cwhere "NAME = 'Germany'" \ -crop_to_cutline \ earth.tif \ germany.tif ```
## gdalwarp crop by remote layer ```shell $ gdalwarp \ -cutline https://raw.githubusercontent.com/martynafford/natural-earth-geojson/master/10m/cultural/ne_10m_admin_0_countries.json \ -cl ne_10m_admin_0_countries \ -cwhere "NAME = 'Switzerland'" \ -crop_to_cutline \ earth.tif \ switzerland.tif ```
## gdalwarp cut by many features ```shell $ gdalwarp \ -cutline countries.shp \ -cwhere "NAME IN ('Germany', 'Spain', 'Italy')" \ -crop_to_cutline \ earth.tif \ many_countries.tif ```
## Virtual Raster ```shell $ gdalbuildvrt \ output.vrt \ germany.tif \ switzerland.tif ``` `output.vrt`: ```xml
GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]
5.8666666666481149e+00, 3.3333333333329968e-02, 0.0000000000000000e+00, 5.5033333333336827e+01, 0.0000000000000000e+00, -3.3333333333329995e-02
Red
switzerland.tif
1
germany.tif
1
Green
switzerland.tif
2
germany.tif
2
Blue
switzerland.tif
3
germany.tif
3
```
## Pyramids
```shell $ gdaladdo \ -r average \ input.tif \ 2 4 8 16 ```
### gdal2tiles ```shell $ gdal2tiles.py \ --zoom=2-5 \ input.tif \ output_folder ``` directory structure: ```text output_folder ├── 2 │ ├── 0 │ │ ├── 0.png │ │ ├── 1.png │ │ ├── 2.png │ │ └── 3.png │ ├── 1 │ │ ├── 0.png │ │ ├── 1.png │ │ ├── 2.png │ │ └── 3.png │ ├── 2 │ │ ├── 0.png │ │ ├── 1.png │ │ ├── 2.png │ │ └── 3.png │ └── 3 │ ├── 0.png │ ├── 1.png │ ├── 2.png │ └── 3.png ├── googlemaps.html ├── leaflet.html ├── openlayers.html └── tilemapresource.xml ```
## gdaldem hillshade ```shell $ gdaldem hillshade \ reutte.tif \ hillshade.tif ```
## gdaldem slope ```shell aspect $ gdaldem slope \ reutte.tif \ slope.tif ```
## gdaldem aspect ```shell $ gdaldem aspect \ reutte.tif \ aspect.tif ```
## gdal_viewshed ```shell $ gdal_viewshed \ -ox 28648.097 \ -oy 261212.391 \ reutte.tif \ viewshed.tif ```
## contour contour lines ```shell $ gdal_contour \ -a myElevation \ -i 100.0 \ reutte.tif \ contour_lines.gpkg ```
## contour contour polygons ```shell $ gdal_contour \ -i 100.0 \ -p \ reutte.tif \ contour_polygons.gpkg ```
Vector
### ogrinfo information about vector data ```shell $ ogrinfo \ places.shp ``` output: ```text INFO: Open of `places.shp' using driver `ESRI Shapefile' successful. 1: places (Point) ``` NOTE: - information not very useful yet
## ogrinfo ```shell $ ogrinfo \ -al \ places.shp ``` output: ```text INFO: Open of `places.shp' using driver `ESRI Shapefile' successful. Layer name: places Metadata: DBF_DATE_LAST_UPDATE=2021-05-14 Geometry: Point Feature Count: 7343 Extent: (-179.589979, -90.000000) - (179.383304, 82.483323) Layer SRS WKT: GEOGCRS["WGS 84", DATUM["World Geodetic System 1984", ELLIPSOID["WGS 84",6378137,298.257223563, LENGTHUNIT["metre",1]]], PRIMEM["Greenwich",0, ANGLEUNIT["degree",0.0174532925199433]], CS[ellipsoidal,2], AXIS["latitude",north, ORDER[1], ANGLEUNIT["degree",0.0174532925199433]], AXIS["longitude",east, ORDER[2], ANGLEUNIT["degree",0.0174532925199433]], ID["EPSG",4326]] Data axis to CRS axis mapping: 2,1 NAME: String (100.0) POP_MAX: Integer (9.0) OGRFeature(places):0 NAME (String) = Colonia del Sacramento POP_MAX (Integer) = 21714 POINT (-57.8400024734013 -34.4799990054175) OGRFeature(places):1 NAME (String) = Trinidad POP_MAX (Integer) = 21093 POINT (-56.9009965601587 -33.5439989373607) OGRFeature(places):2 NAME (String) = Fray Bentos POP_MAX (Integer) = 23279 POINT (-58.3039974719095 -33.1389990288435) OGRFeature(places):3 NAME (String) = Canelones POP_MAX (Integer) = 19698 POINT (-56.2840014932431 -34.5380040066755) OGRFeature(places):4 NAME (String) = Florida POP_MAX (Integer) = 32234 POINT (-56.2149984479942 -34.0990020052172) OGRFeature(places):5 NAME (String) = Bassar POP_MAX (Integer) = 61845 POINT (0.789003573778132 9.26100006831723) OGRFeature(places):6 NAME (String) = Sotouboua POP_MAX (Integer) = 21054 POINT (0.98499646233131 8.5570021330571) OGRFeature(places):7 NAME (String) = Medenine POP_MAX (Integer) = 61705 POINT (10.4166995575967 33.3999990024673) OGRFeature(places):8 NAME (String) = Kebili POP_MAX (Integer) = 19875 POINT (8.9710025379012 33.6899970349206) OGRFeature(places):9 NAME (String) = Tataouine POP_MAX (Integer) = 62577 POINT (10.4667035894155 33.0000031543208) OGRFeature(places):10 NAME (String) = L'Ariana POP_MAX (Integer) = 97687 POINT (10.1999975474793 36.8666731534449) OGRFeature(places):11 NAME (String) = Jendouba POP_MAX (Integer) = 51408 POINT (8.74999861457911 36.5000040594261) OGRFeature(places):12 NAME (String) = Kasserine POP_MAX (Integer) = 76243 POINT (8.71669850332046 35.2167031048242) OGRFeature(places):13 NAME (String) = Sdid Bouzid POP_MAX (Integer) = 42098 POINT (9.50000448225563 35.0166960791497) OGRFeature(places):14 NAME (String) = Siliana POP_MAX (Integer) = 26960 POINT (9.38330159965864 36.0833041252355) OGRFeature(places):15 NAME (String) = Mahdia POP_MAX (Integer) = 45977 POINT (11.040876615322 35.4839130445027) [...] ```
## ogrinfo ```shell $ ogrinfo \ places.shp \ -so \ -al ``` output: ```text INFO: Open of `places.shp' using driver `ESRI Shapefile' successful. Layer name: places Metadata: DBF_DATE_LAST_UPDATE=2021-05-14 Geometry: Point Feature Count: 7343 Extent: (-179.589979, -90.000000) - (179.383304, 82.483323) Layer SRS WKT: GEOGCRS["WGS 84", DATUM["World Geodetic System 1984", ELLIPSOID["WGS 84",6378137,298.257223563, LENGTHUNIT["metre",1]]], PRIMEM["Greenwich",0, ANGLEUNIT["degree",0.0174532925199433]], CS[ellipsoidal,2], AXIS["latitude",north, ORDER[1], ANGLEUNIT["degree",0.0174532925199433]], AXIS["longitude",east, ORDER[2], ANGLEUNIT["degree",0.0174532925199433]], ID["EPSG",4326]] Data axis to CRS axis mapping: 2,1 NAME: String (100.0) POP_MAX: Integer (9.0) ```
## Shapefile directory of shapefiles ```text shp ├── countries.dbf ├── countries.prj ├── countries.shp ├── countries.shx ├── places.dbf ├── places.prj ├── places.shp └── places.shx ```
## Shapefile directory is treated a data source ```shell $ ogrinfo shp ``` output: ```text INFO: Open of `shp' using driver `ESRI Shapefile' successful. 1: places (Point) 2: countries (Polygon) ``` NOTE: GDAL/OGR treats a directory of shapefiles as datasource
## GPX exchange format for GPS/GNSS tracks ```xml
Name of GPX track
2433.1
2021-04-01T06:35:40Z
4.3
1
text
2429.3
2021-04-01T06:36:00Z
3.6
0
2433.6
2021-04-01T06:36:21Z
3.9
0.1
2429.7
2021-04-01T06:36:41Z
7.7
1.3
```
## GPX ```shell $ ogrinfo \ track.gpx ``` output: ```text INFO: Open of `track.gpx' using driver `GPX' successful. 1: waypoints (Point) 2: routes (Line String) 3: tracks (Multi Line String) 4: route_points (Point) 5: track_points (Point) ``` NOTE: - GPX does not comply to simple feature - OGR abstracts it
## GPX ```shell $ ogrinfo \ track.gpx \ track_points \ -so ``` output: ```text INFO: Open of `track.gpx' using driver `GPX' successful. Layer name: track_points Geometry: Point Feature Count: 902 Extent: (72.544079, 34.776858) - (72.574542, 34.798658) Layer SRS WKT: GEOGCRS["WGS 84", DATUM["World Geodetic System 1984", ELLIPSOID["WGS 84",6378137,298.257223563, LENGTHUNIT["metre",1]]], PRIMEM["Greenwich",0, ANGLEUNIT["degree",0.0174532925199433]], CS[ellipsoidal,2], AXIS["geodetic latitude (Lat)",north, ORDER[1], ANGLEUNIT["degree",0.0174532925199433]], AXIS["geodetic longitude (Lon)",east, ORDER[2], ANGLEUNIT["degree",0.0174532925199433]], ID["EPSG",4326]] Data axis to CRS axis mapping: 2,1 track_fid: Integer (0.0) track_seg_id: Integer (0.0) track_seg_point_id: Integer (0.0) ele: Real (0.0) time: DateTime (0.0) magvar: Real (0.0) geoidheight: Real (0.0) name: String (0.0) cmt: String (0.0) desc: String (0.0) src: String (0.0) link1_href: String (0.0) link1_text: String (0.0) link1_type: String (0.0) link2_href: String (0.0) link2_text: String (0.0) link2_type: String (0.0) sym: String (0.0) type: String (0.0) fix: String (0.0) sat: Integer (0.0) hdop: Real (0.0) vdop: Real (0.0) pdop: Real (0.0) ageofdgpsdata: Real (0.0) dgpsid: Integer (0.0) osmand_speed: Real (0.0) ```
## GeoJSON exchange format for the web ```json { "type": "FeatureCollection", "name": "places", "crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } }, "features": [ { "type": "Feature", "properties": { "NAME": "Colonia del Sacramento", "POP_MAX": 21714 }, "geometry": { "type": "Point", "coordinates": [ -57.840002473401341, -34.47999900541754 ] } }, { "type": "Feature", "properties": { "NAME": "Trinidad", "POP_MAX": 21093 }, "geometry": { "type": "Point", "coordinates": [ -56.900996560158717, -33.543998937360698 ] } }, { "type": "Feature", "properties": { "NAME": "Fray Bentos", "POP_MAX": 23279 }, "geometry": { "type": "Point", "coordinates": [ -58.303997471909497, -33.1389990288435 ] } }, { "type": "Feature", "properties": { "NAME": "Canelones", "POP_MAX": 19698 }, "geometry": { "type": "Point", "coordinates": [ -56.284001493243068, -34.538004006675465 ] } } ] } ```
## GeoJSON ```shell $ ogrinfo \ places.geojson \ -al \ -so ``` output: ```text INFO: Open of `places.geojson' using driver `GeoJSON' successful. Layer name: places Geometry: Point Feature Count: 7343 Extent: (-179.589979, -90.000000) - (179.383304, 82.483323) Layer SRS WKT: GEOGCRS["WGS 84", DATUM["World Geodetic System 1984", ELLIPSOID["WGS 84",6378137,298.257223563, LENGTHUNIT["metre",1]]], PRIMEM["Greenwich",0, ANGLEUNIT["degree",0.0174532925199433]], CS[ellipsoidal,2], AXIS["geodetic latitude (Lat)",north, ORDER[1], ANGLEUNIT["degree",0.0174532925199433]], AXIS["geodetic longitude (Lon)",east, ORDER[2], ANGLEUNIT["degree",0.0174532925199433]], ID["EPSG",4326]] Data axis to CRS axis mapping: 2,1 NAME: String (0.0) POP_MAX: Integer (0.0) ```
## GeoJSON remote ```shell ogrinfo \ -so \ -al \ https://raw.githubusercontent.com/martynafford/natural-earth-geojson/master/10m/cultural/ne_10m_populated_places.json ``` output: ```text INFO: Open of `https://raw.githubusercontent.com/martynafford/natural-earth-geojson/master/10m/cultural/ne_10m_populated_places.json' using driver `GeoJSON' successful. Layer name: ne_10m_populated_places Geometry: Point Feature Count: 7343 Extent: (-179.589979, -90.000000) - (179.383304, 82.483323) Layer SRS WKT: GEOGCRS["WGS 84", DATUM["World Geodetic System 1984", ELLIPSOID["WGS 84",6378137,298.257223563, LENGTHUNIT["metre",1]]], PRIMEM["Greenwich",0, ANGLEUNIT["degree",0.0174532925199433]], CS[ellipsoidal,2], AXIS["geodetic latitude (Lat)",north, ORDER[1], ANGLEUNIT["degree",0.0174532925199433]], AXIS["geodetic longitude (Lon)",east, ORDER[2], ANGLEUNIT["degree",0.0174532925199433]], ID["EPSG",4326]] Data axis to CRS axis mapping: 2,1 SCALERANK: Integer (0.0) NATSCALE: Integer (0.0) LABELRANK: Integer (0.0) FEATURECLA: String (0.0) NAME: String (0.0) NAMEPAR: String (0.0) NAMEALT: String (0.0) DIFFASCII: Integer (0.0) NAMEASCII: String (0.0) ADM0CAP: Real (0.0) CAPIN: String (0.0) WORLDCITY: Real (0.0) MEGACITY: Integer (0.0) SOV0NAME: String (0.0) SOV_A3: String (0.0) ADM0NAME: String (0.0) ADM0_A3: String (0.0) ADM1NAME: String (0.0) ISO_A2: String (0.0) NOTE: String (0.0) LATITUDE: Real (0.0) LONGITUDE: Real (0.0) CHANGED: Real (0.0) NAMEDIFF: Integer (0.0) DIFFNOTE: String (0.0) POP_MAX: Integer (0.0) POP_MIN: Integer (0.0) POP_OTHER: Integer (0.0) RANK_MAX: Integer (0.0) RANK_MIN: Integer (0.0) GEONAMEID: Real (0.0) MEGANAME: String (0.0) LS_NAME: String (0.0) LS_MATCH: Integer (0.0) CHECKME: Integer (0.0) MAX_POP10: Real (0.0) MAX_POP20: Real (0.0) MAX_POP50: Real (0.0) MAX_POP300: Real (0.0) MAX_POP310: Real (0.0) MAX_NATSCA: Real (0.0) MIN_AREAKM: Real (0.0) MAX_AREAKM: Real (0.0) MIN_AREAMI: Real (0.0) MAX_AREAMI: Real (0.0) MIN_PERKM: Real (0.0) MAX_PERKM: Real (0.0) MIN_PERMI: Real (0.0) MAX_PERMI: Real (0.0) MIN_BBXMIN: Real (0.0) MAX_BBXMIN: Real (0.0) MIN_BBXMAX: Real (0.0) MAX_BBXMAX: Real (0.0) MIN_BBYMIN: Real (0.0) MAX_BBYMIN: Real (0.0) MIN_BBYMAX: Real (0.0) MAX_BBYMAX: Real (0.0) MEAN_BBXC: Real (0.0) MEAN_BBYC: Real (0.0) COMPARE: Integer (0.0) GN_ASCII: String (0.0) FEATURE_CL: String (0.0) FEATURE_CO: String (0.0) ADMIN1_COD: Real (0.0) GN_POP: Real (0.0) ELEVATION: Real (0.0) GTOPO30: Real (0.0) TIMEZONE: String (0.0) GEONAMESNO: String (0.0) UN_FID: Integer (0.0) UN_ADM0: String (0.0) UN_LAT: Real (0.0) UN_LONG: Real (0.0) POP1950: Real (0.0) POP1955: Real (0.0) POP1960: Real (0.0) POP1965: Real (0.0) POP1970: Real (0.0) POP1975: Real (0.0) POP1980: Real (0.0) POP1985: Real (0.0) POP1990: Real (0.0) POP1995: Real (0.0) POP2000: Real (0.0) POP2005: Real (0.0) POP2010: Real (0.0) POP2015: Real (0.0) POP2020: Real (0.0) POP2025: Real (0.0) POP2050: Real (0.0) CITYALT: String (0.0) min_zoom: Real (0.0) wikidataid: String (0.0) wof_id: Integer (0.0) CAPALT: Integer (0.0) NAME_EN: String (0.0) NAME_DE: String (0.0) NAME_ES: String (0.0) NAME_FR: String (0.0) NAME_PT: String (0.0) NAME_RU: String (0.0) NAME_ZH: String (0.0) ```
## WFS Web Feature Service ```shell ogrinfo \ WFS:https://services.meggsimum.de/geoserver/ows ``` output: ```shell INFO: Open of `WFS:https://services.meggsimum.de/geoserver/ows' using driver `WFS' successful. Metadata: PROVIDER_NAME=meggsimum – Büro für Geoinformatik 1: mgsm-ger:postal_codes_germany (title: Postal Codes Germany) (Multi Surface) 2: mgsm-world:ne_10m_admin_0_countries (title: World Countries) (Multi Surface) 3: mgsm-world:ne_10m_populated_places (title: World Places) (Multi Point) 4: mgsm-world:ne_10m_rivers_lake_centerlines (title: World Rivers) (Multi Curve) ```
## WFS Web Feature Service ```shell ogrinfo \ -so \ WFS:https://services.meggsimum.de/geoserver/ows \ ne_10m_admin_0_countries ``` output: ``` INFO: Open of `WFS:https://services.meggsimum.de/geoserver/ows' using driver `WFS' successful. Metadata: PROVIDER_NAME=meggsimum – Büro für Geoinformatik Layer name: mgsm-world:ne_10m_admin_0_countries Metadata: KEYWORD_1=features KEYWORD_2=ne_10m_admin_0_countries TITLE=World Countries Geometry: Multi Surface Feature Count: 255 Extent: (-180.000000, -90.000000) - (180.000000, 83.634100) Layer SRS WKT: GEOGCRS["WGS 84", DATUM["World Geodetic System 1984", ELLIPSOID["WGS 84",6378137,298.257223563, LENGTHUNIT["metre",1]]], PRIMEM["Greenwich",0, ANGLEUNIT["degree",0.0174532925199433]], CS[ellipsoidal,2], AXIS["geodetic latitude (Lat)",north, ORDER[1], ANGLEUNIT["degree",0.0174532925199433]], AXIS["geodetic longitude (Lon)",east, ORDER[2], ANGLEUNIT["degree",0.0174532925199433]], USAGE[ SCOPE["Horizontal component of 3D system."], AREA["World."], BBOX[-90,-180,90,180]], ID["EPSG",4326]] Data axis to CRS axis mapping: 2,1 Geometry Column = geom gml_id: String (0.0) NOT NULL featurecla: String (0.0) scalerank: Integer (0.0) LABELRANK: Integer (0.0) SOVEREIGNT: String (0.0) SOV_A3: String (0.0) ADM0_DIF: Integer (0.0) LEVEL: Integer (0.0) TYPE: String (0.0) ADMIN: String (0.0) ADM0_A3: String (0.0) GEOU_DIF: Integer (0.0) GEOUNIT: String (0.0) GU_A3: String (0.0) SU_DIF: Integer (0.0) SUBUNIT: String (0.0) SU_A3: String (0.0) BRK_DIFF: Integer (0.0) NAME: String (0.0) NAME_LONG: String (0.0) BRK_A3: String (0.0) BRK_NAME: String (0.0) BRK_GROUP: String (0.0) ABBREV: String (0.0) POSTAL: String (0.0) FORMAL_EN: String (0.0) FORMAL_FR: String (0.0) NAME_CIAWF: String (0.0) NOTE_ADM0: String (0.0) NOTE_BRK: String (0.0) NAME_SORT: String (0.0) NAME_ALT: String (0.0) MAPCOLOR7: Integer (0.0) MAPCOLOR8: Integer (0.0) MAPCOLOR9: Integer (0.0) MAPCOLOR13: Integer (0.0) POP_EST: Integer64 (0.0) POP_RANK: Integer (0.0) GDP_MD_EST: Real (0.0) POP_YEAR: Integer (0.0) LASTCENSUS: Integer (0.0) GDP_YEAR: Integer (0.0) ECONOMY: String (0.0) INCOME_GRP: String (0.0) WIKIPEDIA: Integer (0.0) FIPS_10_: String (0.0) ISO_A2: String (0.0) ISO_A3: String (0.0) ISO_A3_EH: String (0.0) ISO_N3: String (0.0) UN_A3: String (0.0) WB_A2: String (0.0) WB_A3: String (0.0) WOE_ID: Integer (0.0) WOE_ID_EH: Integer (0.0) WOE_N-OTE: String (0.0) ADM0_A3_IS: String (0.0) ADM0_A3_US: String (0.0) ADM0_A3_UN: Integer (0.0) ADM0_A3_WB: Integer (0.0) CONTINENT: String (0.0) REGION_UN: String (0.0) SUBREGION: String (0.0) REGION_WB: String (0.0) NAME_LEN: Integer (0.0) LONG_LEN: Integer (0.0) ABBREV_LEN: Integer (0.0) TINY: Integer (0.0) HOMEPART: Integer (0.0) MIN_ZOOM: Real (0.0) MIN_LABEL: Real (0.0) MAX_LABEL: Real (0.0) NE_ID: Integer64 (0.0) WIKIDATAID: String (0.0) NAME_AR: String (0.0) NAME_BN: String (0.0) NAME_DE: String (0.0) NAME_EN: String (0.0) NAME_ES: String (0.0) NAME_FR: String (0.0) NAME_EL: String (0.0) NAME_HI: String (0.0) NAME_HU: String (0.0) NAME_ID: String (0.0) NAME_IT: String (0.0) NAME_JA: String (0.0) NAME_KO: String (0.0) NAME_NL: String (0.0) NAME_PL: String (0.0) NAME_PT: String (0.0) NAME_RU: String (0.0) NAME_SV: String (0.0) NAME_TR: String (0.0) NAME_VI: String (0.0) NAME_ZH: String (0.0) ```
### CSV Comma-separated values |ID |Name |latitude|longitude| |---|----------|--------|---------| |1 |Salzburg | 47.8 | 13.0 | |2 |Heidelberg| 49.4 | 8.7 | |3 |Trondheim | 63.4 | 10.4 |
### CSV ```shell $ ogrinfo \ cities.csv \ -al ``` output: ```text INFO: Open of `cities.csv' using driver `CSV' successful. Layer name: cities Geometry: None Feature Count: 3 Layer SRS WKT: (unknown) ID: String (0.0) Name: String (0.0) latitude: String (0.0) longitude: String (0.0) OGRFeature(cities):1 ID (String) = 1 Name (String) = Salzburg latitude (String) = 47.8 longitude (String) = 13.0 OGRFeature(cities):2 ID (String) = 2 Name (String) = Heidelberg latitude (String) = 49.4 longitude (String) = 8.7 OGRFeature(cities):3 ID (String) = 3 Name (String) = Trondheim latitude (String) = 63.4 longitude (String) = 10.4 ``` NOTE: - geometries are not recognised
### CSV specify geometry columns ```shell $ ogrinfo \ -al \ cities.csv \ -oo X_POSSIBLE_NAMES=longitude \ -oo Y_POSSIBLE_NAMES=latitude \ -oo KEEP_GEOM_COLUMNS=NO ``` output: ```text INFO: Open of `cities.csv' using driver `CSV' successful. Layer name: cities Geometry: Point Feature Count: 3 Extent: (8.700000, 47.800000) - (13.000000, 63.400000) Layer SRS WKT: (unknown) ID: String (0.0) Name: String (0.0) OGRFeature(cities):1 ID (String) = 1 Name (String) = Salzburg POINT (13.0 47.8) OGRFeature(cities):2 ID (String) = 2 Name (String) = Heidelberg POINT (8.7 49.4) OGRFeature(cities):3 ID (String) = 3 Name (String) = Trondheim POINT (10.4 63.4) ```
### PostgreSQL / PostGIS ```shell $ ogrinfo PG:dbname=demo ``` output: ```text INFO: Open of `PG:dbname=demo' using driver `PostgreSQL' successful. 1: places (Point) 2: tracks (Multi Line String) 3: track_points (Point) 4: waypoints (Point) 5: routes (Line String) 6: route_points (Point) 7: ne_10m_admin_1_states_provinces_shp (Multi Polygon) 8: ne_10m_admin_0_boundary_lines_disputed_areas (Multi Line String) 9: ne_10m_admin_0_scale_rank_minor_islands (Multi Polygon) 10: ne_10m_admin_0_map_units (Multi Polygon) 11: ne_10m_parks_and_protected_lands_area (Multi Polygon) 12: ne_10m_admin_1_states_provinces_lines (Multi Line String) 13: ne_10m_admin_0_boundary_lines_maritime_indicator (Multi Line String) 14: ne_10m_admin_0_map_subunits (Multi Polygon) 15: ne_10m_admin_0_boundary_lines_land (Multi Line String) 16: ne_10m_roads (Multi Line String) 17: ne_10m_admin_1_states_provinces_lines_shp (Multi Line String) 18: ne_10m_populated_places (Multi Point) 19: ne_10m_admin_0_boundary_lines_map_units (Multi Line String) 20: ne_10m_urban_areas (Multi Polygon) 21: ne_10m_parks_and_protected_lands_line (Multi Line String) 22: ne_10m_admin_1_states_provinces_lakes (Multi Polygon) 23: ne_10m_parks_and_protected_lands_point (Multi Point) 24: ne_10m_admin_0_disputed_areas (Multi Polygon) 25: ne_10m_admin_1_states_provinces (Multi Polygon) 26: ne_10m_admin_0_countries (Multi Polygon) ```
### PostgreSQL / PostGIS Postgres connection string ```shell $ ogrinfo \ PG:" dbname=demo host=localhost port=5432 user=postgres password=postgres schemas=public tables=places" ```
## ogr2ogr transformation and processing
## ogr2ogr convert format ```shell $ ogr2ogr \ -f GeoJSON \ output.geojson \ countries.shp ``` newer GDAL recognises format by extension ```shell $ ogr2ogr \ output.geojson \ countries.shp ```
## ogr2ogr reproject ```shell $ ogr2ogr \ -t_srs EPSG:3857 \ output.gpkg \ input.gpkg ```
## ogr2ogr reproject, specify source SRS ```shell $ ogr2ogr \ -s_srs EPSG:4326 \ -t_srs EPSG:3857 \ output.gpkg \ input.gpkg ```
## ogr2ogr filter by extent ```shell ogr2ogr \ -spat -13.931 34.886 46.23 74.12 \ output.gpkg \ natural_earth_vector.gpkg ```
## ogr2ogr filter by condition ```shell ogr2ogr \ -where "\"POP_EST\" < 1000000" \ output.gpkg \ natural_earth_vector.gpkg \ ne_10m_admin_0_countries ```
## ogr2ogr filter by SQL ```shell ogr2ogr \ output.gpkg \ cities.csv \ -sql "SELECT * FROM cities WHERE latitude < 50" \ -oo X_POSSIBLE_NAMES=longitude \ -oo Y_POSSIBLE_NAMES=latitude \ -a_srs EPSG:4326 ``` NOTE: - SQL filter also works for non-database formats - many SQL dialects: - OGR SQL - Spatialite SQL - DB specific SQL (e.g. PostgreSQL)
## Docker ```shell $ docker run \ -v $(pwd):/data \ osgeo/gdal:alpine-small-latest \ ogr2ogr \ /data/out.geojson \ /data/input.shp ```
## Links - [GDAL Website](https://gdal.org/) - [Blogpost](https://jakobmiksch.eu/post/gdal_ogr/) by Jakob Miksch - [Podcast Episode](https://podcasts.apple.com/us/podcast/gdal-geospatial-data-abstraction-library/id1452297085?i=1000520451921) by Mapscaping with Paul Ramsey - [Blogpost](https://podcasts.apple.com/us/podcast/gdal-geospatial-data-abstraction-library/id1452297085?i=1000520451921) by Robert Simmon