Python wrapper for Gdal/OGR command line tools
Project description
Python library providing wrappers for the most common Gdal/OGR command line tools. Currently, only ogr2ogr and gdalinfo are supported. Note that this library requires GDAL/OGR tools to be installed in the system.
Installation
pip install pygdaltools
Usage
Gdalinfo:
import gdaltools info = gdaltools.gdalinfo("/mypath/myraster.tif") print info # output is the same generated by the gdalinfo command
Raster stats:
stats = gdaltools.get_raster_stats("/mypath/myraster.tif") print stats[0] # outputs a tuple: (band0_min, band0_max, band0_mean, band0_stdev) print stats[1] # outputs a tuple: (band1_min, band1_max, band1_mean, band1_stdev)
Ogr2ogr. From shp to geojson:
ogr = gdaltools.ogr2ogr() ogr.set_encoding("UTF-8") ogr.set_input("mylayer.shp", srs="EPSG:4326") ogr.set_output("mylayer.geojson") ogr.execute()
It can also be chained in a single line:
gdaltools.ogr2ogr()\ .set_encoding("UTF-8")\ .set_input("mylayer.shp", srs="EPSG:4326")\ .set_output("mylayer.geojson").execute()
Ogr2ogr. From postgis to shp:
ogr = gdaltools.ogr2ogr() conn = gdaltools.PgConnectionString(host="localhost", port=5432, dbname="scolab", schema="data", user="myuser", password="mypass") ogr.set_input(conn, table_name="roads", srs="EPSG:4326") ogr.set_output("mylayer.shp") ogr.execute()
Ogr2ogr. From postgis to spatialite, specifying a different output table name:
ogr = gdaltools.ogr2ogr() conn = gdaltools.PgConnectionString(host="localhost", port=5432, dbname="scolab", schema="data", user="myuser", password="mypass") ogr.set_input(conn, table_name="roads", srs="EPSG:4326") ogr.set_output("mydb.sqlite", table_name="roads2010") ogr.set_output_mode(data_source_mode=ogr.MODE_DS_CREATE_OR_UPDATE) # required to add the layer to an existing DB ogr.execute()
Ogr2ogr. From postgis to spatialite, reprojecting to “EPSG:25830”:
ogr = gdaltools.ogr2ogr() conn = gdaltools.PgConnectionString(host="localhost", port=5432, dbname="scolab", schema="data", user="myuser", password="mypass") ogr.set_input(conn, table_name="roads", srs="EPSG:4326") ogr.set_output("mydb.sqlite", srs="EPSG:25830") ogr.execute()
Configuration
By default, gdaltools assumes that Gdal/Ogr commands are installes under /usr/bin/ (the standard Linux path). In order to configure specific paths (for instance for using the library in Windows), you can use:
import gdaltools gdaltools.Wrapper.BASEPATH = "C/Program Files/Gdal/bin" print gdaltools.gdalinfo("mywindowsraster.tif")
You can also use lower level API for setting the full path for specific commands:
info = gdaltools.GdalInfo(command_path="C/Program Files/Gdal/bin/gdalinfo.exe") info.set_input('mywindowsraster.tif') print info.execute() print info.get_raster_stats()
FAQ
Nobody asked yet, but just in case.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file pygdaltools-0.1-py2.py3-none-any.whl
.
File metadata
- Download URL: pygdaltools-0.1-py2.py3-none-any.whl
- Upload date:
- Size: 13.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e98318ffce015f0b796a39463f9d606352366234c88b8001ce027e0657fa52c |
|
MD5 | 443900282c8c3dd61a6bf8597b008e97 |
|
BLAKE2b-256 | 96ac928138a642faa357fa4aeb34870bb558339d26e79194453ae5af0cee8ac4 |