Example #1
0
 def query(self, req, coords, types):
     ## FIXME: This seems crude; it feels like it should also be
     ## quoted, but is at the moment safe because the coordinates
     ## are coerced into decimal:
     point = "POINT(%s %s)" % (coords[1], coords[0])
     ## This is a failed attempt at the query (more GeoAlchmey
     ## based): (I think the problem is a bug in geoalchemy, with
     ## points that are constructed outside of the database/engine)
     #point = WKTSpatialElement(point)
     #s = select([Jurisdiction.__table__], expression.func.ST_Intersects(
     #    Jurisdiction.geom, point))
     #conn = engine.connect()
     #s = conn.execute(s, point=point, srid=4326)
     type_comparisons = []
     for type in types:
         type_comparisons.append(
             Jurisdiction.type_uri == unicode(type))
     s = session.query(Jurisdiction).filter(
         expression.and_(
             expression.func.ST_Intersects(Jurisdiction.geom, expression.func.GeomFromText(point, 4326)),
             expression.or_(*type_comparisons)))
     results = []
     for row in s:
         results.append(dict(
             type=row.type_uri,
             name=row.name,
             uri=row.uri,
             properties=row.properties,
             kml_uri="%s/api1/kml/%s" % (req.application_url, row.id)))
     return {'results': results}
Example #2
0
def reset_types(logger, types):
    for type in types:
        q = session.query(Jurisdiction).filter(
            Jurisdiction.type_uri == unicode(type))
        count = q.count()
        if not count:
            logger.notify('No items with type %s to delete' % type)
        else:
            logger.notify('Deleting all (%s) items with type %s' % (count, type))
            q.delete()
            session.commit()
Example #3
0
def reset_types(logger, types):
    for type in types:
        q = session.query(Jurisdiction).filter(
            Jurisdiction.type_uri == unicode(type))
        count = q.count()
        if not count:
            logger.notify('No items with type %s to delete' % type)
        else:
            logger.notify('Deleting all (%s) items with type %s' %
                          (count, type))
            q.delete()
            session.commit()