Install pyproj using pip
Assuming you’re using pip to install Python packages:
$ pip install pyproj
Here is a map application that illustrates very well the different tile schemes used (TMS, QuadTree, Google Maps):
Online documentation for GDAL/OGR Python is sparse. Here I show some recommended ways of learning more about GDAL/OGR in Python.
You can learn about GDAL and OGR from inside the Python interpreter.
Start python interpreter:
Import the modules:
from osgeo import gdal,ogr,osr
Learn about the modules using ‘help’ and ‘dir’ in Python. These built-in functions work for any type of object (module, class, functions etc):
help(ogr) # display help for the ogr module dir(ogr) # what's contained in ogr module? help(ogr.Geometry) # display help for ogr.Geometry class dir(ogr.Geometry) # show contents of an object, like functions on a class
gis.stackexchange.com is a Q&A site about GIS. Many people here know about GDAL and ORG, also about the Python bindings.
Some good questions I’ve found:
Transformation using OGR in Python
Will add more as I find them…
GDAL is not very well documented, and a complete Python API documentation site is not something I’ve found. So here are the best tutorials I’ve found so far for GDAL + Python.
You have a CSV file called “data.csv”. It has a header line, and is delimited using “;”. You want to import it into Postgres and a table called “your_table”:
Create the database table. Set column-types so the string fields in the CSV file, can be cast to values in columns.
CREATE TABLE your_table ( -- Your columns );
Assuming a shapefile called myshapefile.shp, a table mytable in schema xyz, in a PostGIS enabled database called mydb on localhost. The table is owned by user dbuser who has password “secret”.
shp2pgsql myshapefile -I xyz.mytable > statements.sql psql -d mydb -h localhost -U dbuser -f statements.sql
This tip and many more can be read in Making Maps Fast.
This is even easier with ogr2ogr:
ogr2ogr -f "PostgreSQL" PG:"host=localhost user=dbuser dbname=mydb password=secret" -lco SCHEMA=xyz myshapefile.shp
In a previous post I tried generating OpenStreetMap tiles using GeoServer. It ended when I couldn’t find a good style (SLD) to apply the OSM layer.
In this post I tried to use Mapnik to generating OSM map tiles in EPSG:25832. It failed mainly because the Python scripts published by OSM for generating tiles don’t support epsg:25832 out of the box. Mapnik is however an obvious choice for OSM because:
Warning: This is a description of how to create a OpenStreetMap WMS with GeoServer. It works fine up to the point where the layers published as an unstyled WMS. This is where I’ve not been able to produce a good result, because of lack of a good Styled Layer Descriptor (SLD). If you have hints about a good SLD, feel welcome to submit a comment!
The idea is/was to first create a good general purpose OpenStreetMap WMS, and then use GeoWebCache to generate tiles from this WMS source in a custom projection, epsg:25832 in our case.
If you have an ESRI Shapefile (.shp) that you want to reproject, you can use ogr2ogr
ogr2ogr -t_srs <EPSG-CODE> newfile.shp oldfile.shp
The EPSG code could be for instance epsg:28532.