Some thoughts about read/write feature stores.

SQLAlchemy style

PCL users are having a good experience with SQLAlchemy, and we might be able to adapt its API to relational GIS data.

# Selection
source = store.select(typename)
results = source.execute()
for feature in results:
    # process feature

# Insertion
g = Point(x, y, z)
sink = store.insert(typename)
sink.execute(the_geom=g, value=10.0)

# Update
sink = store.update(typename, value=10.0)
sink.execute(value=11.0)

Django style

This is a higher-level option

# Get a feature by id
>>> feature_store = DiskFeatureStore('countries.shp')
>>> countries_type = feature_store.featuretype('countries')
>>> country = countries_type.getfeature('1')
>>> country.id
'1' 

# Get an iterator over features with filtering
>>> feature_iterator = countries_type.iterfeatures(bbox=BoundingBox(-10, 45, 10, 60))

# Create and store a new feature type

# Define the feature type
class ExampleFeature(Feature):
    __schema__ = PropertyTypeCollection([
        StringProperty('name'),
        GeometryProperty('the_geom', homotype='Point'),
        ])
    __typename__ = 'ExampleFeature'
    __srs__ = EPSG_4326

# or, programmatically
# ExampleFeature = type(...)

# set the storage
>>> feature_store = DiskFeatureStore('example.shp')
>>> ExampleFeature.setstorage(feature_store)
>>> 'ExampleFeature' in feature_store.typenames()
True
>>> ExampleFeature.count()
0

# create and save a feature
>>> feature = ExampleFeature(id='1', name='foo', the_geom=Point(-100.0, 40.0))
>>> feature.save()
>>> ExampleFeature.count()
1