Posts

Showing posts from May, 2015

GeoDjango < 1.7 return GeoJSON passing model name in request

I thought this might be hard but it really was not.  Django 1.8 introduced GeoJSON serializer so use that if you are starting a new project with Django version 1.8 up.  For those stuck with Django version <=1.7  this is the solution for you. The problem: You want to pass a model name to a request and return the GeoJSON for some map application. pip install django-geojson add 'djgeojson' to your INSTALLED_APPS in the settings.py urls.py   add the URL for example:  here we limit the model name to an alpha numeric characture including underscore or dash that is between 5 and 50 characters long url(r'^geojs/(?P<geomodel_name>[-\w]{5,50})/$',geoview.get_geojson, name="get_geojs"), views.py  should look something like this: def get_geojson(request, geomodel_name):     '''     Pas model name as string     :param geomodel_name: model name as string     :return: instance of model     '''     mymodel = apps.get_mod

ogr2ogr Append new Shapefile to existing PostGIS table

Ogr2ogr is simply powerful.  It is like salt in cooking you use it everyday. The task how to import a Shapefile into a PostGIS table that exists without overwriting the existing table and simply append some new geometries and match the attribute fields from the Shapefile to the PostGIS table fields. There are lots of things I want to do in this import so lets list off what exactly: append new geometry to an existing PostGIS table from a source Shapefile specifiy the source Shapefile projection, because sometimes ogr2ogr guesses wrong define which attribute fields map to which PostGIS table fields specify a non default PostgreSQL schema, in my case the schema=geodata specify the geometry type for output destination as MultiLineString even though my input Shapefile is  a simple Linestring Here is the monster long command line arguments for OGR2OGR: ogr2ogr -update -append -fieldmap -1,-1,2 -a_srs EPSG:900913 -nlt MULTILINESTRING -lco "SCHEMA=geodata" -f Postgre