yourcelf / olwidget

Javascript library to replace textareas that contain WKT data with editable OpenLayers maps, and a django app using it for django forms and admin.
Other
91 stars 43 forks source link

Enhancement request: use gdal transformation in order not to loose Z information on 3D geometries #14

Closed elpaso closed 15 years ago

elpaso commented 15 years ago

Hello,

here is a patch that prevent olwidget to loose Z (height) information, I know geodjango does not (yet) fully support this but It will not hurt anyway.

--- /home/ale/public_html/django/itineraria/contrib/olwidget/widgets.py 2009-10-21 14:57:13.000000000 +0200
+++ Downloads/python/olwidget/django-olwidget/olwidget/widgets.py       2009-10-20 15:33:38.000000000 +0200
@@ -1,6 +1,6 @@
from os.path import join

-from django.contrib.gis.gdal import OGRException, OGRGeometry
+from django.contrib.gis.gdal import OGRException
from django.contrib.gis.geos import GEOSGeometry, GEOSException
from django.forms.widgets import Textarea
from django.template.loader import render_to_string
@@ -23,16 +23,12 @@
except AttributeError:
    YAHOO_APP_ID = ""

-try:
-    OL_API = settings.OL_API
-except AttributeError:
-    OL_API = "http://openlayers.org/api/2.8/OpenLayers.js"
-

GOOGLE_API = "http://maps.google.com/maps?file=api&v=2&key=%s" % GOOGLE_API_KEY
YAHOO_API = "http://api.maps.yahoo.com/ajaxymap?v=3.0&appid=%s" % YAHOO_APP_ID
MS_VE_API = "http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.1"
OSM_API = "http://openstreetmap.org/openlayers/OpenStreetMap.js"
+OL_API = "http://openlayers.org/api/2.8/OpenLayers.js"
OLWIDGET_JS = join(OLWIDGET_MEDIA_URL, "js/olwidget.js")
OLWIDGET_CSS = join(OLWIDGET_MEDIA_URL, "css/olwidget.css")

@@ -284,10 +280,9 @@
    wkt = ''
    if value:
        try:
-            # ABP: don't loose z
-            g = OGRGeometry(value.wkt, value.get_srid())
-            g.transform(srid)
-            wkt = g.wkt
+            ogr = value.ogr
+            ogr.transform(srid)
+            wkt = ogr.wkt
        except OGRException:
            pass
    return wkt
yourcelf commented 15 years ago

Thanks. Implemented this in latest commit.

yourcelf commented 15 years ago

.