Forcing Right-Hand Rule (Counter Clockwise) Polygons in GeoDjango for Google Earth / KML

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
""" models.py """
from django.contrib.gis.db import models

class Airspaces(models.Model):
    geom = models.PolygonField()

""" your script """
# Import your models as usual
from airspaces.models import *

# Import the GeomField from geodjango
from django.contrib.gis.db.models.sql import GeomField

# Add the custom select field for the geometry field (this needs PostGIS to work)
qs = Airspaces.objects.extra(select={'rhr' : 'ST_ForceRHR(geom)'})

# Cast the field to the GeomField type
qs.query.extra_select_fields['rhr'] = GeomField()

# Iterate over objects as usual
for airspace in qs:
    # Output our counter clockwise polygon
    print airspace.rhr.coords

More like this

  1. KMLMiddleware by takinbo 2 years, 3 months ago
  2. KMZMiddleware by giovabal 5 years, 1 month ago
  3. GoogleAdmin: GMaps base layer in Geographic Admin (GeoDjango) by jbronn 4 years, 7 months ago
  4. MaxMind(R) GeoIP Lite geolocation models by jbronn 5 years, 10 months ago
  5. Multi-level (tree-ish) navigation by jpic 4 years, 7 months ago

Comments

(Forgotten your password?)