Ticket #165 (feature request)
Opened 5 months ago
Added the ability to do an attribute filter on the collection
Status: new
| Reported by: | J.vanderVen | Assigned to: | seang |
|---|---|---|---|
| Priority: | minor | Milestone: | |
| Component: | WorldMill | Version: | |
| Keywords: | attributefilter | Cc: | |
I needed WorldMill to return a collection based on a Attribute and not on a geometry. To that end I created a derived class AttributeIterator?, that accepts a query instead of a bounding box. I do not quite know how this works together with the session, and how to make an Iterator that does both the bbox and the attribute(s).
This is collection.patch: 155a156,168 > cdef class AttributeIterator(Iterator): > > def init(self, collection, query=None, object_hook=None): > cdef Session session > self.collection = collection > session = Session() > session.start(collection) > if query: > ograpi.OGR_L_SetAttributeFilter( > session.cogr_layer, query > ) > self.object_hook = object_hook or collection.object_hook > self._session = session 222a236,238 > def attribute_filter(self, query=None, object_hook=None): > return AttributeIterator(self, query, object_hook) >
And this is ograpi.patch: 37c37 < --- > int OGR_L_SetAttributeFilter(void *layer, char *query)
And this is my example usage: from mill import workspace from mill.feature import Feature from shapely.wkb import loads
def shapely_feature(id, properties, wkb):
return Feature(id, properties.copy(), loads(wkb))
w=workspace('/home/plone/shp') c=w['akr_kri'] d=w['slokrimp'] c.object_hook = shapely_feature d.object_hook = shapely_feature giabdres='2861BB84' geslachtsn='RIJKAART' slootnr='38bz02184' percelen=c.attribute_filter("GIABADRES='"+giabdres+"' AND GESLACHTSN='"+geslachtsn+"'") for p in percelen:
dempingen=d.attribute_filter("SLOOTNR='" + slootnr + "'") for demping in dempingen:
if p.geometry.contains(demping.geometry):
print p.properties['ID'] + " bevat " + demping.properties['SLOOTNR']
Please let me know your thoughts
Attachments
Change History
06/10/08 12:43:38: Modified by J.vanderVen
- attachment worldmill.zip added.
