def test_protocol_count_filter_box(self): """Get the feature count with a box as filter""" proto = Protocol(session, Spot) request = FakeRequest({}) request.params['bbox'] = '-10,-10,10,10' eq_(proto.count(request), '4') request.params['tolerance'] = '200000' eq_(proto.count(request), '5') # query features that are inside a bbox that uses a different CRS # note that we either have to specify a tolerance ('tol') or # dimension information ('dim1' and 'dim2') filter = create_default_filter(request, Spot, additional_params={'tol': '0.005'}) request.params['bbox'] = '-12.3364241712925,-10.0036833569465,7.66304367998925,9.9979519038951' request.params['epsg'] = '2210' request.params['tolerance'] = '0' eq_(proto.count(request, filter=filter), '5') # dimension information array for 54004 # see http://download.oracle.com/docs/cd/E11882_01/appdev.112/e11830/sdo_objrelschema.htm#i1010905 diminfo = "MDSYS.SDO_DIM_ARRAY("\ "MDSYS.SDO_DIM_ELEMENT('LONGITUDE', -20037508, 20037508, 0.005),"\ "MDSYS.SDO_DIM_ELEMENT('LATITUDE', -19929239, 19929239, 0.005)"\ ")" request.params['bbox'] = '-975862.822682856,-999308.345117013,1027887.98627823,999373.702609189' request.params['epsg'] = '54004' # Oracles SRID number for World Mercator filter = create_default_filter(request, Spot, additional_params={'dim1': text(diminfo), 'dim2' : text(diminfo)}) eq_(proto.count(request, filter=filter), '3')
def test_protocol_count_filter_geometry(self): """Get the feature count with a geometry as filter""" proto = Protocol(session, Spot) request = FakeRequest({}) request.params['geometry'] = '{"type": "Polygon", "coordinates": [[ [-10, -1], [10, -1], [0, 10], [-10, -1] ]]}' eq_(proto.count(request), '2') request.params['tolerance'] = '10' eq_(proto.count(request), '5')
def test_protocol_count_filter_box(self): """Get the feature count with a box as filter""" proto = Protocol(session, Spot) request = FakeRequest({}) request.params['bbox'] = '-10,-10,10,10' eq_(proto.count(request), '4') request.params['tolerance'] = '1' eq_(proto.count(request), '5')
def test_protocol_count_filter_geometry(self): """Get the feature count with a geometry as filter""" proto = Protocol(session, Spot) request = FakeRequest({}) request.params[ 'geometry'] = '{"type": "Polygon", "coordinates": [[ [-10, -1], [10, -1], [0, 10], [-10, -1] ]]}' eq_(proto.count(request), '2') request.params['tolerance'] = '10' eq_(proto.count(request), '5')
def test_protocol_count_filter_within(self): """Get the feature count with a point as filter""" proto = Protocol(session, Spot) request = FakeRequest({}) request.params['lat'] = '0' request.params['lon'] = '0' eq_(proto.count(request), '1') request.params['tolerance'] = '10' eq_(proto.count(request), '3')
def test_protocol_count_filter_box_reproject(self): """Try to get the feature count with a box that has to be reprojected (MySQL does not support transform() yet)""" proto = Protocol(session, Spot) request = FakeRequest({}) # reproject the bbox request.params['bbox'] = '-12.3364241712925,-10.0036833569465,7.66304367998925,9.9979519038951' request.params['epsg'] = '4807' request.params['tolerance'] = '0' proto.count(request)
def test_protocol_count_filter_box_reproject(self): """Try to get the feature count with a box that has to be reprojected (MySQL does not support transform() yet)""" proto = Protocol(session, Spot) request = FakeRequest({}) # reproject the bbox request.params[ 'bbox'] = '-12.3364241712925,-10.0036833569465,7.66304367998925,9.9979519038951' request.params['epsg'] = '4807' request.params['tolerance'] = '0' proto.count(request)
def test_protocol_count_filter_within(self): """Get the feature count with a point as filter""" proto = Protocol(session, Spot) request = FakeRequest({}) request.params['lat'] = '0' request.params['lon'] = '0' eq_(proto.count(request), '1') request.params['tolerance'] = '400000' eq_(proto.count(request), '2') filter = create_default_filter(request, Spot, additional_params={'params': 'unit=KM'}) eq_(proto.count(request, filter=filter), '8')
def test_protocol_count_filter_box(self): """Get the feature count with a box as filter""" proto = Protocol(session, Spot) request = FakeRequest({}) request.params['bbox'] = '-10,-10,10,10' eq_(proto.count(request), '4') request.params['tolerance'] = '1' eq_(proto.count(request), '5') # reproject the bbox request.params['bbox'] = '-12.3364241712925,-10.0036833569465,7.66304367998925,9.9979519038951' request.params['epsg'] = '4807' request.params['tolerance'] = '0' eq_(proto.count(request), '4')
def test_protocol_count_queryable(self): """Count all features that match a filter""" proto = Protocol(session, Spot) request = FakeRequest({}) request.params['queryable'] = 'spot_height' request.params['spot_height__gte'] = '1454.66' eq_(proto.count(request), '3')
def test_protocol_count_filter_box(self): """Get the feature count with a box as filter""" proto = Protocol(session, Spot) request = FakeRequest({}) request.params['bbox'] = '-10,-10,10,10' eq_(proto.count(request), '4') request.params['tolerance'] = '1' eq_(proto.count(request), '5') # reproject the bbox request.params[ 'bbox'] = '-12.3364241712925,-10.0036833569465,7.66304367998925,9.9979519038951' request.params['epsg'] = '4807' request.params['tolerance'] = '0' eq_(proto.count(request), '4')
def test_protocol_count_filter_box(self): """Get the feature count with a box as filter""" proto = Protocol(session, Spot) request = FakeRequest({}) request.params['bbox'] = '-10,-10,10,10' eq_(proto.count(request), '4') request.params['tolerance'] = '200000' eq_(proto.count(request), '5') # query features that are inside a bbox that uses a different CRS # note that we either have to specify a tolerance ('tol') or # dimension information ('dim1' and 'dim2') filter = create_default_filter(request, Spot, additional_params={'tol': '0.005'}) request.params[ 'bbox'] = '-12.3364241712925,-10.0036833569465,7.66304367998925,9.9979519038951' request.params['epsg'] = '2210' request.params['tolerance'] = '0' eq_(proto.count(request, filter=filter), '5') # dimension information array for 54004 # see http://download.oracle.com/docs/cd/E11882_01/appdev.112/e11830/sdo_objrelschema.htm#i1010905 diminfo = "MDSYS.SDO_DIM_ARRAY("\ "MDSYS.SDO_DIM_ELEMENT('LONGITUDE', -20037508, 20037508, 0.005),"\ "MDSYS.SDO_DIM_ELEMENT('LATITUDE', -19929239, 19929239, 0.005)"\ ")" request.params[ 'bbox'] = '-975862.822682856,-999308.345117013,1027887.98627823,999373.702609189' request.params[ 'epsg'] = '54004' # Oracles SRID number for World Mercator filter = create_default_filter(request, Spot, additional_params={ 'dim1': text(diminfo), 'dim2': text(diminfo) }) eq_(proto.count(request, filter=filter), '3')
class ZonesController(BaseController): readonly = True # if set to True, only GET is supported def __init__(self): self.protocol = Protocol(Session, Zone, self.readonly) @geojsonify def index(self, format='json'): """GET /: return all features.""" # If no filter argument is passed to the protocol index method # then the default MapFish filter is used. # # If you need your own filter with application-specific params # taken into acount, create your own filter and pass it to the # protocol read method. # # E.g. # # from sqlalchemy.sql import and_ # # default_filter = create_default_filter(request, Zone) # filter = and_(default_filter, Zone.columname.ilike('%value%')) # return self.protocol.read(request, filter=filter) if format != 'json': abort(404) return self.protocol.read(request) @geojsonify def show(self, id, format='json'): """GET /id: Show a specific feature.""" if format != 'json': abort(404) return self.protocol.read(request, response, id=id) #@geojsonify #def create(self): # """POST /: Create a new feature.""" # return self.protocol.create(request, response) # #@geojsonify #def update(self, id): # """PUT /id: Update an existing feature.""" # return self.protocol.update(request, response, id) # #def delete(self, id): # """DELETE /id: Delete an existing feature.""" # return self.protocol.delete(request, response, id) def count(self): """GET /count: Count all features.""" return self.protocol.count(request)
class BicycleRentalController(BaseController): readonly = False # if set to True, only GET is supported def __init__(self): self.protocol = Protocol(Session, BicycleRental, self.readonly) @geojsonify def index(self, format='json'): """GET /: return all features.""" # If no filter argument is passed to the protocol index method # then the default MapFish filter is used. # # If you need your own filter with application-specific params # taken into acount, create your own filter and pass it to the # protocol read method. # # E.g. # # from sqlalchemy.sql import and_ # # default_filter = create_default_filter(request, BicycleRental) # filter = and_(default_filter, BicycleRental.columname.ilike('%value%')) # return self.protocol.read(request, filter=filter) if format != 'json': abort(404) return self.protocol.read(request) @geojsonify def show(self, id, format='json'): """GET /id: Show a specific feature.""" if format != 'json': abort(404) return self.protocol.read(request, response, id=id) @geojsonify def create(self): """POST /: Create a new feature.""" return self.protocol.create(request, response) @geojsonify def update(self, id): """PUT /id: Update an existing feature.""" return self.protocol.update(request, response, id) def delete(self, id): """DELETE /id: Delete an existing feature.""" return self.protocol.delete(request, response, id) def count(self): """GET /count: Count all features.""" return self.protocol.count(request)
def test_protocol_count_custom_filter(self): """Count all features that match a custom filter""" session.add_all([ Lake( depth=20, geom= 'POLYGON((-88.7968950764331 43.2305732929936,-88.7935511273885 43.1553344394904,-88.716640299363 43.1570064140127,-88.7250001719745 43.2339172420382,-88.7968950764331 43.2305732929936))' ), Lake( depth=5, geom= 'POLYGON((-88.1147292993631 42.7540605095542,-88.1548566878981 42.7824840764331,-88.1799363057325 42.7707802547771,-88.188296178344 42.7323248407643,-88.1832802547771 42.6955414012739,-88.1565286624204 42.6771496815287,-88.1448248407643 42.6336783439491,-88.131449044586 42.5718152866242,-88.1013535031847 42.565127388535,-88.1080414012739 42.5868630573248,-88.1164012738854 42.6119426751592,-88.1080414012739 42.6520700636943,-88.0980095541401 42.6838375796178,-88.0846337579618 42.7139331210191,-88.1013535031847 42.7423566878981,-88.1147292993631 42.7540605095542))' ), Lake( depth=120, geom= 'POLYGON((-89.0694267515924 43.1335987261147,-89.1078821656051 43.1135350318471,-89.1329617834395 43.0884554140127,-89.1312898089172 43.0466560509554,-89.112898089172 43.0132165605096,-89.0694267515924 42.9898089171975,-89.0343152866242 42.953025477707,-89.0209394904459 42.9179140127389,-89.0042197452229 42.8961783439491,-88.9774681528663 42.8644108280255,-88.9440286624204 42.8292993630573,-88.9072452229299 42.8142515923567,-88.8687898089172 42.815923566879,-88.8687898089172 42.815923566879,-88.8102707006369 42.8343152866242,-88.7734872611465 42.8710987261147,-88.7517515923567 42.9145700636943,-88.7433917197452 42.9730891719745,-88.7517515923567 43.0299363057325,-88.7734872611465 43.0867834394905,-88.7885352038217 43.158678388535,-88.8738057324841 43.1620222929936,-88.947372611465 43.1937898089172,-89.0042197452229 43.2138535031847,-89.0410031847134 43.2389331210191,-89.0710987261147 43.243949044586,-89.0660828025478 43.2238853503185,-89.0543789808917 43.203821656051,-89.0376592356688 43.175398089172,-89.0292993630573 43.1519904458599,-89.0376592356688 43.1369426751592,-89.0393312101911 43.1386146496815,-89.0393312101911 43.1386146496815,-89.0510350318471 43.1335987261147,-89.0694267515924 43.1335987261147))' ), Lake( depth=450, geom= 'POLYGON((-88.9122611464968 43.038296178344,-88.9222929936306 43.0399681528663,-88.9323248407643 43.0282643312102,-88.9206210191083 43.0182324840764,-88.9105891719745 43.0165605095542,-88.9005573248408 43.0232484076433,-88.9072452229299 43.0282643312102,-88.9122611464968 43.038296178344))' ) ]) session.commit() proto = Protocol(session, Lake) from sqlalchemy.sql import and_ request = FakeRequest({}) request.params['bbox'] = '-90,40,-80,45' filter = create_geom_filter(request, Lake) compare_filter = Lake.geom.area >= 0.1 filter = and_(filter, compare_filter) eq_(proto.count(request, filter=filter), '1')
def test_protocol_count_custom_filter(self): """Count all features that match a custom filter""" session.add_all([ Lake(depth=20, geom='POLYGON((-88.7968950764331 43.2305732929936,-88.7935511273885 43.1553344394904,-88.716640299363 43.1570064140127,-88.7250001719745 43.2339172420382,-88.7968950764331 43.2305732929936))'), Lake(depth=5, geom='POLYGON((-88.1147292993631 42.7540605095542,-88.1548566878981 42.7824840764331,-88.1799363057325 42.7707802547771,-88.188296178344 42.7323248407643,-88.1832802547771 42.6955414012739,-88.1565286624204 42.6771496815287,-88.1448248407643 42.6336783439491,-88.131449044586 42.5718152866242,-88.1013535031847 42.565127388535,-88.1080414012739 42.5868630573248,-88.1164012738854 42.6119426751592,-88.1080414012739 42.6520700636943,-88.0980095541401 42.6838375796178,-88.0846337579618 42.7139331210191,-88.1013535031847 42.7423566878981,-88.1147292993631 42.7540605095542))'), Lake(depth=120, geom='POLYGON((-89.0694267515924 43.1335987261147,-89.1078821656051 43.1135350318471,-89.1329617834395 43.0884554140127,-89.1312898089172 43.0466560509554,-89.112898089172 43.0132165605096,-89.0694267515924 42.9898089171975,-89.0343152866242 42.953025477707,-89.0209394904459 42.9179140127389,-89.0042197452229 42.8961783439491,-88.9774681528663 42.8644108280255,-88.9440286624204 42.8292993630573,-88.9072452229299 42.8142515923567,-88.8687898089172 42.815923566879,-88.8687898089172 42.815923566879,-88.8102707006369 42.8343152866242,-88.7734872611465 42.8710987261147,-88.7517515923567 42.9145700636943,-88.7433917197452 42.9730891719745,-88.7517515923567 43.0299363057325,-88.7734872611465 43.0867834394905,-88.7885352038217 43.158678388535,-88.8738057324841 43.1620222929936,-88.947372611465 43.1937898089172,-89.0042197452229 43.2138535031847,-89.0410031847134 43.2389331210191,-89.0710987261147 43.243949044586,-89.0660828025478 43.2238853503185,-89.0543789808917 43.203821656051,-89.0376592356688 43.175398089172,-89.0292993630573 43.1519904458599,-89.0376592356688 43.1369426751592,-89.0393312101911 43.1386146496815,-89.0393312101911 43.1386146496815,-89.0510350318471 43.1335987261147,-89.0694267515924 43.1335987261147))'), Lake(depth=450, geom='POLYGON((-88.9122611464968 43.038296178344,-88.9222929936306 43.0399681528663,-88.9323248407643 43.0282643312102,-88.9206210191083 43.0182324840764,-88.9105891719745 43.0165605095542,-88.9005573248408 43.0232484076433,-88.9072452229299 43.0282643312102,-88.9122611464968 43.038296178344))') ]) session.commit(); proto = Protocol(session, Lake) from sqlalchemy.sql import and_ request = FakeRequest({}) request.params['bbox'] = '-90,40,-80,45' filter = create_geom_filter(request, Lake) compare_filter = Lake.geom.area >= 0.1 filter = and_(filter, compare_filter) eq_(proto.count(request, filter=filter), '1')
class BroadbandSpeedsController(BaseController): readonly = False # if set to True, only GET is supported def __init__(self): self.protocol = Protocol(Session, BroadbandSpeed, self.readonly) @geojsonify def index(self, format='json'): """GET /: return all features.""" # If no filter argument is passed to the protocol index method # then the default MapFish filter is used. # # If you need your own filter with application-specific params # taken into acount, create your own filter and pass it to the # protocol read method. # # E.g. # # from sqlalchemy.sql import and_ # # default_filter = create_default_filter(request, BroadbandSpeed) # filter = and_(default_filter, BroadbandSpeed.columname.ilike('%value%')) # return self.protocol.read(request, filter=filter) default_filter = create_default_filter(request, BroadbandSpeed) if "zones_f" in request.params: #zones will be a javascript list zones_q = request.params["zones_f"].split(",") #zones = Session.query(functions.geometry_type(functions.collect(Zone.geom))).filter(and_(Zone.zone_general.in_(zones_q), # Zone.geom != None)).scalar() zones = Session.query(functions.union(Zone.geom)).filter(Zone.zone_general.in_(zones_q)).first() filter = and_(default_filter, BroadbandSpeed.geom.within(zones)) else: filter = default_filter if format != 'json': abort(404) return self.protocol.read(request, filter=filter) @geojsonify def show(self, id, format='json'): """GET /id: Show a specific feature.""" if format != 'json': abort(404) return self.protocol.read(request, response, id=id) #@geojsonify #def create(self): # """POST /: Create a new feature.""" # return self.protocol.create(request, response) # #@geojsonify #def update(self, id): # """PUT /id: Update an existing feature.""" # return self.protocol.update(request, response, id) # #def delete(self, id): # """DELETE /id: Delete an existing feature.""" # return self.protocol.delete(request, response, id) def count(self): """GET /count: Count all features.""" return self.protocol.count(request)
def test_protocol_count(self): """Get the feature count""" proto = Protocol(session, Spot) eq_(proto.count(FakeRequest({})), '9')