Wednesday, December 21, 2016

How to create Django translations for django-rosetta from a model field

How to create Django translations from a model field for django-rosetta?

I am using Django-Rosetta to handle all of my project translations.  Unfortunately I have only one model and one field of data that needs translation, the name of the POI.  To get around this I have created a little script to query my Django Database directly to deliver the list of names to be translated.  The output is a new html file with "trans" tags.  This html file is then placed in my templates folder so that "makemessages" can find the file and mark them for translation.

Anytime I want to update this I can run this script and bingo, new template file and new translations.

Note to self:  When adding msgid and msgstr  by hand the command "makemessages" will remove them in the .po file every time the command is called.

Tuesday, September 13, 2016

CORS with Geoserver 2.9.0 and Tomcat

How to enable CORS on your Geoserver 2.9.0 running on Tomcat.

This is taken directly from the tomcat homepage

add the following code to your  web.xml  file then stop/start the tomcat process

service tomcat stop
service tomcat start


Thursday, September 1, 2016

Using Django to create a point GeoJSON feature from the centroid of a polygon

A practical example showing how to use geoDjango, Django geospatial functions to create the centroid of a polygon, returning a GeoJSON dataset that includes all the attributes of the original polygon feature excluding the original  geometry.

We are using the Django Rest Framework to server up the response but you could of course use simple the Django response as well.

We pass in a unique_id value to get a single polygon feature to generate the centroid.

NOTE you will need to hook up your URLs to look something like this:

url(r'^getcenter/(?P<unique_id>.+/$', get_room_center, name='centroid'),

Wednesday, August 24, 2016

Geoserver slice string values using SLD for label manipulation

I have an attribute column in my PostGIS polygon table and want to only show the first 2 characters of this text field on my label using SLD in Geoserver.  My goal is to place the label at the center of the polygon so here it goes in SLD xml syntax as usual very verbose and ugly.

              <ogc:Function name="centroid">

              <ogc:Function name="strSubstring">
                  <ogc:Function name="parseInt">
                  <ogc:Function name="parseInt">                            

My table column name is "short_name"  and the geometry column name is "geom".  This works and creates my label in the center of the polygon only drawing the first 2 characters from the field "short_name".

I hope this helps :)

Friday, January 8, 2016

Goals for 2016

This year I want to start out with a bang and what better way to start the year off right than setting up some goals for 2016.  I think 5 goals should be reasonalble to achieve.

Goals 2016

  1. Do more Django coding
  2. Learn better Javascript best practises
  3. Write more blog posts
  4. Complete two spare time projects for fun
lets check this out again in January 2016 and see what gets done.



Tuesday, January 5, 2016

Python Geospatial Analysis Cookbook now available

Python Geospatial Analysis Cookbook

Well almost 1 year has past and my book is finally available for purchase.  For those of you visiting this blog you habe 2 awesome choices to get the book at a great discount.

Exclusive deal 50% off with this code:

Packt is also offering a great deal to get my book and many more at only 5$ !! click below

Wednesday, November 11, 2015

How to import Spatialite into PostGIS using ogr2ogr

GOAL: Import a Spatialite table into an existing PostGIS table appending (inserting) new rows using ogr2ogr. The trick is we want to map the fields to import to the correct corresponding PostGIS columns.

 First get the list of Spatialite fields using ogrinfo

 ogrinfo somedb.sqlite sqliteTableName

INFO: Open of `..\sqlite\socgen-db-final.sqlite'
      using driver `SQLite' successful.

Layer name: e00_poly_join
Geometry: Polygon
Feature Count: 60
Extent: (-168613.719162, 5983831.402051) - (-168508.270008, 5983961.187764)
Layer SRS WKT:
PROJCS["WGS 84 / Pseudo-Mercator",
    GEOGCS["WGS 84",
            SPHEROID["WGS 84",6378137,298.257223563,
    EXTENSION["PROJ4","+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0
FID Column = PK_UID
Geometry Column = geom
Text: String (0.0)
spacetype: String (0.0)
building: Integer (0.0)
floor: Integer (0.0)
type_id: Integer (0.0)
tag: String (0.0)
name: String (0.0)

Now you see we have a total of 9 columns
 using the -fieldmap option of ogr2ogr we can only input 7 of those fields.. The FID column and geometry column do NOT count towards the -fieldmap list

-fieldmap 7,4,6,9,10,3,2

This means  7 = field Text,  4 = field spacetype, 6 = building, 9=floor, 10=type_id, 3=tag, 2=name

the value 7 for example represents the column position in your PostgreSQL DB where you want to import INTO using the Spatialite column called "Text" in this example.

Counting the column number in Postgresql is also hard.  You start at 0 NOT including the primary key and excluding the geometry column where ever it is the the column order.