It's possible to use FeatureServer as an "API", rather than using it as a web service. This is an example of how to do so. >>> from FeatureServer.Server import Server >>> from FeatureServer.DataSource.SQLite import SQLite >>> db = "/tmp/scribble_test.db" >>> import os >>> if os.path.exists(db): os.remove(db) create the datasource, and the fs service to call it. >>> datasource = SQLite('scribble', layer="scribble", dsn=db) >>> featureserver = Server({'scribble': datasource }) some fake data. >>> data = '{"type":"FeatureCollection","features":[{"type":"Feature","id":"OpenLayers.Feature.Vector_217","properties" :{"title":"Feature 3","strokeColor":"red","author":"Your Name Here"},"geometry":{"type":"Point","coordinates" :[-92.8125,35.15625]}}],"crs":{"type":"OGC","properties":{"urn":"urn:ogc:def:crs:OGC:1.3:CRS84"}}}' see whats in there, request the result in format json >>> featureserver.dispatchRequest({'format':'json'}, "/scribble", "") ('text/plain', '{"features": []}') then POST some new data >>> featureserver.dispatchRequest({'format':'geojson'}, "/scribble", "", data, "POST") ('text/plain', '{"crs": {"type": "none", "properties": {"info": "No CRS information has been provided with this data."}}, "type": "FeatureCollection", "features": [{"geometry": {"type": "Point", "coordinates": [-92.8125, 35.15625]}, "type": "Feature", "id": 1, "properties": {"strokeColor": "red", "title": "Feature 3", "author": "Your Name Here"}}]}') yep, it's there >>> featureserver.dispatchRequest({'format':'json'}, "/scribble", "") ('text/plain', '{"features": [{"geometry": {"type": "Point", "coordinates": [[-92.8125, 35.15625]]}, "id": 1, "properties": {"strokeColor": "red", "title": "Feature 3", "author": "Your Name Here"}}]}') see in in KML >>> featureserver.dispatchRequest({'format':'kml'}, "/scribble", "") ('application/vnd.google-earth.kml+xml', u'\n\n\n \n\n \n\n \n Feature 3\n strokeColor: red
author: Your Name Here]]>
\n #allstyle\n \n \n red\nYour Name Here\n \n -92.8125,35.15625\n
\n
\n
') do something with the json >>> import simplejson >>> format, json = featureserver.dispatchRequest({'format':'json'}, "/scribble", "") >>> features = simplejson.loads(json) >>> features {u'features': [{u'geometry': {u'type': u'Point', u'coordinates': [[-92.8125, 35.15625]]}, u'id': 1, u'properties': {u'strokeColor': u'red', u'author': u'Your Name Here', u'title': u'Feature 3'}}]} it's a point, only one coord >>> features['features'][0]['geometry']['coordinates'] [[-92.8125, 35.15625]] change it: >>> pts = features['features'][0]['geometry']['coordinates'] >>> pts[0] = [-121.232, 42.123] >>> new_json = simplejson.dumps(features) >>> "-121.232" in new_json True overwrite the old 1 by add "/scribble/1" >>> featureserver.dispatchRequest({}, "/scribble/1", "", new_json, "POST") ('text/plain', '{"features": [{"geometry": {"type": "Point", "coordinates": [[-121.232, 42.122999999999998]]}, "id": 1, "properties": {"strokeColor": "red", "title": "Feature 3", "author": "Your Name Here"}}]}') >>> format, features_json = featureserver.dispatchRequest({'format':'json'}, "/scribble", "") >>> features = simplejson.loads(features_json) >>> features {u'features': [{u'geometry': {u'type': u'Point', u'coordinates': [[-121.232, 42.122999999999998]]}, u'id': 1, u'properties': {u'strokeColor': u'red', u'author': u'Your Name Here', u'title': u'Feature 3'}}]} >>> len(features['features']) 1 add a new feature by just using "/scribble" >>> features['features'][0]['id'] = 2 >>> pts = features['features'][0]['geometry']['coordinates'] change a property >>> features['features'][0]['properties']['strokeColor'] = 'blue' >>> features['features'][0]['properties']['author'] = 'bsp' >>> new_json = simplejson.dumps(features) >>> _ = featureserver.dispatchRequest({}, "/scribble/create", "", new_json, "POST") >>> format, features_json = featureserver.dispatchRequest({'format':'json'}, "/scribble", "") >>> features = simplejson.loads(features_json) >>> len(features['features']) 2 >>> features {u'features': [{u'geometry': {u'type': u'Point', u'coordinates': [[-121.232, 42.122999999999998]]}, u'id': 1, u'properties': {u'strokeColor': u'red', u'author': u'Your Name Here', u'title': u'Feature 3'}}, {u'geometry': {u'type': u'Point', u'coordinates': [[-121.232, 42.122999999999998]]}, u'id': 2, u'properties': {u'strokeColor': u'blue', u'author': u'bsp', u'title': u'Feature 3'}}]} DELETE a record: >>> _ = featureserver.dispatchRequest({}, "/scribble/1", "", "", "DELETE") >>> format, features_json = featureserver.dispatchRequest({'format':'json'}, "/scribble", "") >>> features_json '{"features": [{"geometry": {"type": "Point", "coordinates": [[-121.232, 42.122999999999998]]}, "id": 2, "properties": {"strokeColor": "blue", "title": "Feature 3", "author": "bsp"}}]}' QUERY by attribute: {'service': 'WFS', 'format': 'WFS', 'maxfeatures': '100', 'request': 'GetFeature', 'fred': '222', 'srs': 'EPSG:4326', 'version': '1.0.0', 'queryable': 'fred,asdf'}, '/scribble', 'http://75.51.135.218/featureserver-svn/featureserver.cgi', None, 'GET', 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5') >>> format, features_json = featureserver.dispatchRequest({'format':'json', 'request': 'GetFeature', 'queryable': 'author', 'author': 'bsp'}, "/scribble", "" , "GET") >>> features_json '{"features": [{"geometry": {"type": "Point", "coordinates": [[-121.232, 42.122999999999998]]}, "id": 2, "properties": {"strokeColor": "blue", "title": "Feature 3", "author": "bsp"}}]}'