fiona SQL filter

Loïc Dutrieux

Hi everyone,

I'm trying to do some attribute filtering of a fiona feature collection using the where clause but I cannot find out the right syntax. Here's what I've tried.

Thanks for any help,
Kind regards,

import string
import tempfile, os

import fiona
from import from_epsg
from shapely.geometry import Point, mapping

# Generate test data and save to tmp geopackage
gpkg = os.path.join(tempfile.gettempdir(), 'fiona_sql_test.gpkg')
sc = [Point(1,2), Point(3,4), Point(5,6)]
fc = [{'geometry': mapping(s),
'properties': {'letter': string.ascii_lowercase[idx]}}
for idx,s in enumerate(sc)]
schema = {'geometry': 'Point',
'properties': {'letter': 'str'}}
with, 'w', driver='GPKG', schema=schema, crs=from_epsg(4326),
layer='test') as dst:

# Filter using OGR SQL dialect
with, layer='test') as src:
fc = src.filter(where='"letter" = "a"')
for feat in fc:

Alan Snow

I think the feature you want is slated for 2.0:

Loïc Dutrieux

Thanks Alan, you're right. I wrongly assumed that this was an old or at least already existing feature since it is in the online doc.

From: <> on behalf of Alan Snow <>
Sent: 03 June 2021 20:05:29
Subject: Re: [fiona] fiona SQL filter

I think the feature you want is slated for 2.0:<;!!DOxrgLBm!UB5tJPQHin0tXeTB6cruOVmD3nIa-Dq8tSRv6xve6RsrgL5eedhcf0yBmtwj9Z5O8Cik8ns$>