Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a database in GeoDjango containing data based on the Australian MGA54 coordinate system (SRID 28354). I have the srid set in the model definintions and when using the standard GeoModelAdmin (using OSM as base layer) it all works fine, displaying the onjects in the correct location and allowing them to be editted correctly.

For a more functionality I would like to use Olwidget in the Django admin, with the Google layers as basemap, however it doesn't seem to handle the MGA54 system. I have set the 'projection' to 900913 and 'display_projection' to 28354, however this is not working correctly. If I set the text area to visible I can see that it is setting the SRID correctly at the start of the WKT statement, but then is using coordinates that I suspect are in 900913.

I read somewhere that Openlayers can only transform 4326 and 900913 without using Proj4s libraries, but starnge that Djangos GeoModelAdmin can handle it correctly.

Does anyone know if it is possible to use alternative coordinate systems (beyond 4326 and 900913) with olwidget and if yes how to go about it?

share|improve this question
    
You said display_projection. The right variable is displayProjection. Or is that a typo? –  R.K. Sep 23 '12 at 2:07
    
In olwidget you use 'display_projection' and it converts it to 'displayProjection' when putting the page together. docs.olwidget.org/en/latest/… –  THOMAS MCADAM Dec 8 '12 at 6:12
add comment

2 Answers

So after leaving this problem for a few weeks and coming back to it, I have found a solution. Not very pretty I'm afraid as it involves editing olwidget source and hard coding the projection, but seems to work well, for both displaying and editing.

Basically it involves adding proj4 support for transformations into olwidget. You need to edit two olwidget files olwidget.js and widgets.py.

widgets.py:

In this file file I am trying to add some links to the head of the generated html file. Insert these two lines after the for loop in def_media (roughly line 172),

    js.add("http://svn.osgeo.org/metacrs/proj4js/trunk/lib/proj4js-compressed.js")
    js.add("http://spatialreference.org/ref/epsg/28354/proj4js/")

The first adds the proj4 library. The second makes sure proj4 has the details of your projection, in this case mine is 28354, so you can change it to what you require.

olwidget.js:

You just need to change line 219, to your projected coord system, so for me I changed:

    displayProjection: "EPSG:4326",

to

    displayProjection: "EPSG:28354",

As you may have guessed I am not very experienced at programming, and am just starting to get my head around Django and Openlayers and how they play together. If anyone has a way to make this a more versatile solution (ie. reading the projection from the geometry field, so that it is not hard coded), that would be great.

share|improve this answer
add comment

According to the docs:

Projections olwidget uses the projections given in mapOptions to determine the input and output of WKT data. By default, it expects incoming WKT data to use "EPSG:4326" (familiar latitudes and longitudes), which is transformed internally to the map projection (by default, "EPSG:900913", the projection used by OpenStreetMaps, Google, and others). Currently, olwidget ignores the SRID present in any initial WKT data, and uses the projection specified in mapOptions.displayProjection to read the data.

To change the projection used for WKT, define the mapOptions.displayProjection. For example, the following will use EPSG:900913 for all WKT data in addition to map display:

new olwidget.EditableMap('textareaId', {
    mapOptions: {
        projection: "EPSG:900913",
        displayProjection: "EPSG:900913"
    }
});

Or have you found this section of the docs already?

share|improve this answer
    
Thanks for this. I had seen this section, but it only worked for the two projections shown 4326/900913 for which the transformation is built into OpenLayers. If you want to use any other projections I think proj4 is needed, which is what I was trying to achieve. –  THOMAS MCADAM Oct 8 '12 at 3:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.