'Returns Rows of locations which intersect the given shape.
Relies on Shapely for wkt parsing and intersection.
@ToDo: provide an option to use PostGIS/Spatialite'

@staticmethod
def get_features_by_shape(shape):

    from shapely.geos import ReadingError
    from shapely.wkt import loads as wkt_loads
    try:
        from shapely import speedups
        speedups.enable()
    except:
        current.log.info('S3GIS', 'Upgrade    Shapely    for    Performance    enhancements')
    table = current.s3db.gis_location
    in_bbox = current.gis.query_features_by_bbox(*shape.bounds)
    has_wkt = ((table.wkt != None) & (table.wkt != ''))
    for loc in current.db((in_bbox & has_wkt)).select():
        try:
            location_shape = wkt_loads(loc.wkt)
            if location_shape.intersects(shape):
                (yield loc)
        except ReadingError:
            current.log.error('Error    reading    wkt    of    location    with    id', loc.id)
