Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added editing of common raster metainfo #16

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ __Reproject vector:__

ogr2ogr output.shp -t_srs "EPSG:4326" input.shp

__Convert MULTIPOLYGON to POLYGON:__

This assumes that `input.shp` has the largest part as the first geometry for every multipolygon. If not, parts need to be removed.

ogrinfo -dialect SQLite -sql "UPDATE input SET geometry = ST_GeometryN(geometry,1)" input.shp

__Add an index to a shapefile__

Add an index on an attribute:
Expand Down Expand Up @@ -118,6 +124,11 @@ Given a set of points (trees.shp) and a set of polygons (parks.shp) in the same

Note that features that from parks.shp that don't overlap with trees.shp won't be in the new file.

__Upload Geopackage table to PostGis database__

ogr2ogr -progress -f Postgresql pg:"dbname=database user=user password=password port=port" \
-nln new_table_name geopackage.gpkg -SQL "select* table_in_geopackage"

Raster operations
---
__Get raster information__
Expand Down Expand Up @@ -288,7 +299,18 @@ __Convert GRIB band to .tif__
Assumes data for entire globe in WGS84. Be sure to specify band, or you may end up with a nonsense RGB image composed of the first three.

gdal_translate input.grib -a_ullr -180 -90 180 90 -a_srs EPSG:4326 -b 1 output_band1.tif

__Change scale and offset factors in a raster__

gdal_edit.py -offset 0 -scale 3.05185094759971e-05 input.tif

__Remove nodata value in a raster__

gdal_edit.py -unsetnodata input.tif

__Set nodata value in a raster__

gdal_edit.py -a_nodata -32768 input.tif

Other
---
Expand Down Expand Up @@ -415,6 +437,63 @@ or

This can be a useful way to quickly crop one raster to the same extent as another. Add these to your ~/.bash_profile file for easy terminal access.

__From Bounding Box to Shapefile__

It is possible to create a Shapefile of a bounding box starting from simple geografic coordinates, without using a script. It can be done using
and intermediate raster file to create without an initial data source:

gdal_create -outsize 100 100 -burn 1 -ot Byte -a_srs EPSG:4326 -a_ullr 15.027444 41.982819 16.282455 41.03043 bbox.tif
gdaltindex bbox.shp bbox.tif

An alternative way is directly creating a GeoJSON with the 5 corners of the vertexes in a POLYGON.

cat >bbox.json <<EOF
{
"type": "FeatureCollection",
"name": "bbox",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:OGC:1.3:CRS84"
}
},
"features": [
{
"type": "Feature",
"properties": {
"location": "bbox"
},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
15.027444,
41.982819
],
[
16.282455,
41.982819
],
[
16.282455,
41.03043
],
[
15.027444,
41.03043
],
[
15.027444,
41.982819
]
]
]
}
}
]
}
EOF

Sources
---
Expand Down