Added:
trunk/georssfeed.xml
Modified:
trunk/geoserv.py
trunk/index.yaml
Log:
Adding GeoRSS output (issue 5)
Added: trunk/georssfeed.xml
==============================================================================
--- (empty file)
+++ trunk/georssfeed.xml Tue Sep 30 18:13:44 2008
@@ -0,0 +1,25 @@
+<feed xmlns="http://www.w3.org/2005/Atom"
+ xmlns:georss="http://www.georss.org/georss">
+ <id>http://geodatastore.appspot.com/</id>
+ <link rel="self" type="application/atom+xml"
+ href="http://geodatastore.appspot.com/"/>
+ <title>GeoDataStore GeoRSS Feed: Recently Added Entries</title>
+ <updated>{{now}}</updated>
+ {% for geometry in geometries %}
+ <entry>
+ <id>http://geodatastore.appspot.com/geometry/{{geometry.key}}</id>
+ <author>
+ <name>{{geometry.userId}}</name>
+ </author>
+ <title>{{geometry.name}}</title>
+ <updated>{{now}}</updated>
+ <content type="html"><![CDATA[
+ {{geometry.description}}
+ ]]></content>
+ {% ifequal geometry.type "point" %}
+ <georss:point>{{geometry.georssPoint}}</georss:point>
+ {% else %}
+ <georss:box>{{geometry.georssBox}}</georss:box>
+ {% endifequal %}
+ </entry> {% endfor %}
+</feed>
Modified: trunk/geoserv.py
==============================================================================
--- trunk/geoserv.py (original)
+++ trunk/geoserv.py Tue Sep 30 18:13:44 2008
@@ -4,10 +4,13 @@
import geohash
import traceback
import sys
+import time
+import os
from google.appengine.ext import db
from google.appengine.ext import webapp
from google.appengine.api import users
+from google.appengine.ext.webapp import template
class Geometry(db.Model):
name = db.StringProperty()
@@ -25,6 +28,14 @@
bboxNorth = db.FloatProperty()
geohash = db.StringProperty()
+ def georssPoint(self):
+ lat = float(self.coordinates[0].lat)
+ lon = float(self.coordinates[0].lon)
+ return ('%s %s' % (lat, lon))
+
+ def georssBox(self):
+ return ('%s %s %s %s' % (self.bboxSouth, self.bboxWest, self.bboxNorth,
+ self.bboxEast))
def getCoordinates(gp):
lat,lon = 0.0,0.0
@@ -36,6 +47,11 @@
lon = 0.0
return lat,lon
+def GetCurrentRfc822Time():
+ now = time.gmtime()
+ #YYYY-MM-DDTHH:MM:SSZ
+ return time.strftime('%Y-%m-%dT%H:%M:%SZ', now)
+
def jsonOutput(geometries, operation):
geoJson = []
geoJson.append("{operation: '%s', status: 'success',
result:{geometries:{" % operation)
@@ -45,7 +61,6 @@
for geometry in geometries:
coords = []
for gp in geometry.coordinates:
-
lat, lon = getCoordinates(gp)
coords.append('lat: %s, lng: %s' % (lat, lon))
altitudes = '[0.0]'
@@ -62,6 +77,14 @@
contentType = 'text/javascript'
return geoJsonOutput, contentType
+def georssOutput(geometries):
+ template_values = {'geometries' : geometries,
+ 'now' : GetCurrentRfc822Time() }
+ path = os.path.join(os.path.dirname(__file__), 'georssfeed.xml')
+ contentType = 'text/xml'
+ georssOutput2 = template.render(path, template_values)
+ return georssOutput2, contentType
+
def
kmlOutput(geometries,bboxWest=None,bboxSouth=None,bboxEast=None,bboxNorth=None):
# This creates the core document.
kmlDoc = xml.dom.minidom.Document()
@@ -193,11 +216,20 @@
bboxSouth = float(bboxList[1])
bboxEast = float(bboxList[2])
bboxNorth = float(bboxList[3])
- qryString = ''
+ queryString = ''
if len(query) > 0:
- qryString = 'WHERE %s LIMIT %s' % (' and '.join(query), limit)
- geometries = Geometry.gql(qryString)
- outputAction = {'json': jsonOutput(geometries,'get'),'kml':
kmlOutput(geometries,bboxWest,bboxSouth,bboxEast,bboxNorth)}
+ queryString = 'WHERE %s LIMIT %s' % (' and '.join(query), limit)
+
+ if (output == 'georss'):
+ query = Geometry.all()
+ query.order('-dateModified')
+ geometries = query.fetch(limit=20)
+ else:
+ geometries = Geometry.gql(queryString)
+
+ outputAction = {'json': jsonOutput(geometries,'get'),
+ 'kml':
kmlOutput(geometries,bboxWest,bboxSouth,bboxEast,bboxNorth),
+ 'georss': georssOutput(geometries)}
out,contentType = outputAction.get(output)
return out,contentType
Modified: trunk/index.yaml
==============================================================================
--- trunk/index.yaml (original)
+++ trunk/index.yaml Tue Sep 30 18:13:44 2008
@@ -10,13 +10,19 @@
# automatically uploaded to the admin console when you next deploy
# your application using appcfg.py.
-# Used 5 times in query history.
+# Used once in query history.
+- kind: Geometry
+ properties:
+ - name: dateModified
+ direction: desc
+
+# Unused in query history -- copied from input.
- kind: Geometry
properties:
- name: type
- name: geohash
-# Used 6 times in query history.
+# Unused in query history -- copied from input.
- kind: Geometry
properties:
- name: type