Example #1
0
 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')
Example #2
0
    def test_protocol_create_and_update(self):
        """Create a new point and also update an already existing point"""
        
        old_spot = session.query(Spot).filter(Spot.spot_height==102.34).one()
        
        proto = Protocol(session, Spot)
        
        request = FakeRequest({})
        request.body = '{"type": "FeatureCollection", "features": [\
            {"type": "Feature", "properties": {"spot_height": 12.0}, "geometry": {"type": "Point", "coordinates": [45, 5]}},\
            {"type": "Feature", "id": ' + str(old_spot.spot_id) + ', "properties": {}, "geometry": {"type": "Point", "coordinates": [1, 1]}}]}'       
        
        response = FakeResponse()
        collection = proto.create(request, response)
        eq_(response.status, 201)
        eq_(len(collection.features), 2)
        feature0 = collection.features[0]
        eq_(feature0.id, 10)
        eq_(feature0.geometry.coordinates, (45.0, 5.0))
        eq_(feature0.properties["spot_height"], 12)
        feature1 = collection.features[1]
        eq_(feature1.id, old_spot.spot_id)
        eq_(feature1.geometry.coordinates, (1, 1))

        new_spot = session.query(Spot).filter(Spot.spot_height==12.0).one()
        ok_(new_spot is not None)
        eq_(session.scalar(new_spot.spot_location.wkt), u'POINT(45 5)')
        
        updated_spot = session.query(Spot).filter(Spot.spot_height==102.34).one()
        ok_(updated_spot is not None)
        ok_(old_spot is updated_spot)
        eq_(updated_spot.spot_height, 102.34)
        eq_(session.scalar(updated_spot.spot_location.wkt), u'POINT(1 1)')
Example #3
0
    def test_protocol_create_fails(self):
        """Try to create a feature without geometry"""
        proto = Protocol(session, Spot)

        request = FakeRequest({})
        request.body = '{"type": "FeatureCollection", "features": [{"type": "Feature", "properties": {"spot_height": 12.0}}]}'

        proto.create(request, FakeResponse())
Example #4
0
 def test_protocol_create_fails(self):
     """Try to create a feature without geometry"""
     proto = Protocol(session, Spot)
     
     request = FakeRequest({})
     request.body = '{"type": "FeatureCollection", "features": [{"type": "Feature", "properties": {"spot_height": 12.0}}]}'
     
     proto.create(request, FakeResponse())
Example #5
0
 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')
Example #6
0
    def test_protocol_read_all(self):
        """Return all features"""
        proto = Protocol(session, Spot)

        collection = proto.read(FakeRequest({}))
        ok_(collection is not None)
        ok_(isinstance(collection, FeatureCollection))
        eq_(len(collection.features), 9)
Example #7
0
    def test_protocol_read_all(self):
        """Return all features"""
        proto = Protocol(session, Spot)

        collection = proto.read(FakeRequest({}))
        ok_(collection is not None)
        ok_(isinstance(collection, FeatureCollection))
        eq_(len(collection.features), 9)
Example #8
0
    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')
Example #9
0
 def test_protocol_update_fails(self):
     """Try to update a not-existing feature"""
     proto = Protocol(session, Spot)
     id = -1
     
     request = FakeRequest({})
     request.body = '{"type": "Feature", "id": ' + str(id) + ', "properties": {}, "geometry": {"type": "Point", "coordinates": [1, 1]}}'
     
     response = FakeResponse()
     proto.update(request, response, id)
Example #10
0
    def test_protocol_read_one(self):
        """Return one feature"""
        proto = Protocol(session, Spot)

        feature = proto.read(FakeRequest({}), id=1)
        ok_(feature is not None)
        ok_(isinstance(feature, Feature))
        eq_(feature.id, 1)
        eq_(feature.geometry.coordinates, (0.0, 0.0))
        eq_(feature.properties["spot_height"], 420.39999999999998)
Example #11
0
    def test_protocol_read_one(self):
        """Return one feature"""
        proto = Protocol(session, Spot)

        feature = proto.read(FakeRequest({}), id=1)
        ok_(feature is not None)
        ok_(isinstance(feature, Feature))
        eq_(feature.id, 1)
        eq_(feature.geometry.coordinates, (0.0, 0.0))
        eq_(feature.properties["spot_height"], 420.39999999999998)
Example #12
0
 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')
Example #13
0
 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')
Example #14
0
    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')
Example #15
0
    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')
Example #16
0
 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)
Example #17
0
    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')
Example #18
0
 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')
Example #19
0
    def test_protocol_update_fails(self):
        """Try to update a not-existing feature"""
        proto = Protocol(session, Spot)
        id = -1

        request = FakeRequest({})
        request.body = '{"type": "Feature", "id": ' + str(
            id
        ) + ', "properties": {}, "geometry": {"type": "Point", "coordinates": [1, 1]}}'

        response = FakeResponse()
        proto.update(request, response, id)
Example #20
0
    def test_protocol_read_one_null(self):
        """Return one null feature"""
        proto = Protocol(session, Spot)

        feature = proto.read(FakeRequest({}), id=9)
        ok_(feature is not None)
        ok_(isinstance(feature, Feature))
        eq_(feature.id, 9)
        # make use of __geo_interface__ property since 'geometry'
        # value is not the same in various versions of geojson lib
        ok_(feature.__geo_interface__['geometry'] is None)
        ok_(feature.__geo_interface__['bbox'] is None)
Example #21
0
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)
Example #22
0
    def test_protocol_read_one_null(self):
        """Return one null feature"""
        proto = Protocol(session, Spot)

        feature = proto.read(FakeRequest({}), id=9)
        ok_(feature is not None)
        ok_(isinstance(feature, Feature))
        eq_(feature.id, 9)
        # make use of __geo_interface__ property since 'geometry'
        # value is not the same in various versions of geojson lib
        ok_(feature.__geo_interface__['geometry'] is None)
        ok_(feature.__geo_interface__['bbox'] is None)
Example #23
0
    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)
Example #24
0
 def test_protocol_delete(self):
     """Delete an existing point"""
     proto = Protocol(session, Spot)
     id = 1
     
     request = FakeRequest({})
     response = FakeResponse()
     
     proto.delete(request, response, id)
     eq_(response.status, 204)
     
     spot = session.query(Spot).get(id)
     ok_(spot is None)
Example #25
0
    def test_protocol_delete(self):
        """Delete an existing point"""
        proto = Protocol(session, Spot)
        id = 1

        request = FakeRequest({})
        response = FakeResponse()

        proto.delete(request, response, id)
        eq_(response.status, 204)

        spot = session.query(Spot).get(id)
        ok_(spot is None)
Example #26
0
 def test_protocol_create(self):
     from mapfish.protocol import Protocol
     proto = Protocol(Session, MappedClass)
     request = FakeRequest({})
     request.body = '{"type": "FeatureCollection", "features": [{"type": "Feature", "properties": {"text": "foo"}, "geometry": {"type": "Point", "coordinates": [45, 5]}}, {"type": "Feature", "properties": {"text": "foo"}, "geometry": {"type": "Point", "coordinates": [45, 5]}}]}'
     response = FakeResponse()
     proto.create(request, response, execute=False)
     assert response.status == 201
     assert len(Session.new) == 2
     for obj in Session.new:
         assert obj["text"] == "foo"
         assert obj._mf_shape.x == 45
         assert obj._mf_shape.y == 5
     Session.rollback()
Example #27
0
 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')
Example #28
0
 def test_protocol_create(self):
     from mapfish.protocol import Protocol
     proto = Protocol(Session, MappedClass)
     request = FakeRequest({})
     request.body = '{"type": "FeatureCollection", "features": [{"type": "Feature", "properties": {"text": "foo"}, "geometry": {"type": "Point", "coordinates": [45, 5]}}, {"type": "Feature", "properties": {"text": "foo"}, "geometry": {"type": "Point", "coordinates": [45, 5]}}]}'
     response = FakeResponse()
     proto.create(request, response, execute=False)
     assert response.status ==  201
     assert len(Session.new) == 2
     for obj in Session.new:
         assert obj["text"] == "foo"
         assert obj._mf_shape.x == 45
         assert obj._mf_shape.y == 5
     Session.rollback()
Example #29
0
    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')
Example #30
0
 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')
Example #31
0
 def test_protocol_query(self):
     from mapfish.protocol import Protocol, create_attr_filter
     proto = Protocol(Session, MappedClass)
 
     request = FakeRequest({})
     query = proto._query(request, execute=False)
     stmt = query.statement
     stmtm_str = stmt.compile(engine)
     assert "SELECT" in query_to_str(query)
 
     request = FakeRequest({"queryable": "id", "id__eq": "1"})
     query = proto._query(request, execute=False)
     assert "WHERE" in query_to_str(query)
 
     request = FakeRequest({"queryable": "id", "id__eq": "1"})
     filter = create_attr_filter(request, MappedClass)
     query = proto._query(FakeRequest({}), filter=filter, execute=False)
     assert "WHERE" in query_to_str(query)
 
     request = FakeRequest({"limit": "2"})
     query = proto._query(request, execute=False)
     print query_to_str(query)
     assert "LIMIT" in query_to_str(query)
 
     request = FakeRequest({"maxfeatures": "2"})
     query = proto._query(request, execute=False)
     assert "LIMIT" in query_to_str(query)
 
     request = FakeRequest({"limit": "2", "offset": "10"})
     query = proto._query(request, execute=False)
     assert "OFFSET" in query_to_str(query)
 
     request = FakeRequest({"order_by": "text"})
     query = proto._query(request, execute=False)
     assert "ORDER BY" in query_to_str(query)
     assert "ASC" in query_to_str(query)
 
     request = FakeRequest({"sort": "text"})
     query = proto._query(request, execute=False)
     assert "ORDER BY" in query_to_str(query)
     assert "ASC" in query_to_str(query)
 
     request = FakeRequest({"order_by": "text", "dir": "DESC"})
     query = proto._query(request, execute=False)
     assert "ORDER BY" in query_to_str(query)
     assert "DESC" in query_to_str(query)
Example #32
0
    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')
Example #33
0
 def test_protocol_update(self):
     """Update an existing point"""
     proto = Protocol(session, Spot)
     id = 1
     
     request = FakeRequest({})
     request.body = '{"type": "Feature", "id": ' + str(id) + ', "properties": {}, "geometry": {"type": "Point", "coordinates": [1, 1]}}'
     
     response = FakeResponse()
     feature = proto.update(request, response, id)
     eq_(response.status, 201)
     eq_(feature.id, 1)
     eq_(feature.geometry.coordinates, (1.0, 1.0))
     
     spot = session.query(Spot).get(id)
     ok_(spot is not None)
     eq_(session.scalar(spot.spot_location.wkt), u'POINT(1 1)')
Example #34
0
    def test_protocol_create(self):
        """Create a new point"""
        proto = Protocol(session, Spot)
        
        request = FakeRequest({})
        request.body = '{"type": "FeatureCollection", "features": [{"type": "Feature", "properties": {"spot_height": 12.0}, "geometry": {"type": "Point", "coordinates": [45, 5]}}]}'
        
        response = FakeResponse()
        collection = proto.create(request, response)
        eq_(response.status, 201)
        eq_(len(collection.features), 1)
        feature0 = collection.features[0]
        eq_(feature0.id, 10)
        eq_(feature0.geometry.coordinates, (45.0, 5.0))
        eq_(feature0.properties["spot_height"], 12)

        new_spot = session.query(Spot).filter(Spot.spot_height==12.0).one()
        ok_(new_spot is not None)
        eq_(session.scalar(new_spot.spot_location.wkt), u'POINT (45.0 5.0)')
Example #35
0
    def test_protocol_update(self):
        """Update an existing point"""
        proto = Protocol(session, Spot)
        id = 1

        request = FakeRequest({})
        request.body = '{"type": "Feature", "id": ' + str(
            id
        ) + ', "properties": {}, "geometry": {"type": "Point", "coordinates": [1, 1]}}'

        response = FakeResponse()
        feature = proto.update(request, response, id)
        eq_(response.status, 201)
        eq_(feature.id, 1)
        eq_(feature.geometry.coordinates, (1.0, 1.0))

        spot = session.query(Spot).get(id)
        ok_(spot is not None)
        eq_(session.scalar(spot.spot_location.wkt), u'POINT(1 1)')
Example #36
0
    def test_protocol_create(self):
        """Create a new point"""
        proto = Protocol(session, Spot)

        request = FakeRequest({})
        request.body = '{"type": "FeatureCollection", "features": [{"type": "Feature", "properties": {"spot_height": 12.0}, "geometry": {"type": "Point", "coordinates": [45, 5]}}]}'

        response = FakeResponse()
        collection = proto.create(request, response)
        eq_(response.status, 201)
        eq_(len(collection.features), 1)
        feature0 = collection.features[0]
        eq_(feature0.id, 10)
        eq_(feature0.geometry.coordinates, (45.0, 5.0))
        eq_(feature0.properties["spot_height"], 12)

        new_spot = session.query(Spot).filter(Spot.spot_height == 12.0).one()
        ok_(new_spot is not None)
        eq_(session.scalar(new_spot.spot_location.wkt), u'POINT(45 5)')
Example #37
0
    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')
Example #38
0
    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')
Example #39
0
    def test_protocol_create_and_update(self):
        """Create a new point and also update an already existing point"""

        old_spot = session.query(Spot).filter(Spot.spot_height == 102.34).one()

        proto = Protocol(session, Spot)

        request = FakeRequest({})
        request.body = '{"type": "FeatureCollection", "features": [\
            {"type": "Feature", "properties": {"spot_height": 12.0}, "geometry": {"type": "Point", "coordinates": [45, 5]}},\
            {"type": "Feature", "id": ' + str(
            old_spot.spot_id
        ) + ', "properties": {}, "geometry": {"type": "Point", "coordinates": [1, 1]}}]}'

        response = FakeResponse()
        collection = proto.create(request, response)
        eq_(response.status, 201)
        eq_(len(collection.features), 2)
        feature0 = collection.features[0]
        eq_(feature0.id, 10)
        eq_(feature0.geometry.coordinates, (45.0, 5.0))
        eq_(feature0.properties["spot_height"], 12)
        feature1 = collection.features[1]
        eq_(feature1.id, old_spot.spot_id)
        eq_(feature1.geometry.coordinates, (1, 1))

        new_spot = session.query(Spot).filter(Spot.spot_height == 12.0).one()
        ok_(new_spot is not None)
        eq_(session.scalar(new_spot.spot_location.wkt), u'POINT(45 5)')

        updated_spot = session.query(Spot).filter(
            Spot.spot_height == 102.34).one()
        ok_(updated_spot is not None)
        ok_(old_spot is updated_spot)
        eq_(updated_spot.spot_height, 102.34)
        eq_(session.scalar(updated_spot.spot_location.wkt), u'POINT(1 1)')
Example #40
0
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)
Example #41
0
    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 __init__(self):
     self.protocol = Protocol(Session, BroadbandSpeed, self.readonly)
 def __init__(self):
     self.protocol = Protocol(Session, Cellular, self.readonly)
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)
Example #45
0
 def __init__(self):
     self.protocol = Protocol(Session, Restaurant, self.readonly)
Example #46
0
File: areas.py Project: neolf/ole
 def __init__(self):
     self.protocol = Protocol(Session, Area, self.readonly)
Example #47
0
    def test_protocol_delete_fails(self):
        """Try to delete a not-existing point"""
        proto = Protocol(session, Spot)

        proto.delete(FakeRequest({}), FakeResponse(), -1)
Example #48
0
 def __init__(self):
     self.protocol = Protocol(Session, Point, self.readonly)
Example #49
0
    def test_protocol_read_one_fails(self):
        """Try to get a single point with a wrong primary key"""
        proto = Protocol(session, Spot)

        proto.read(FakeRequest({}), id=-1)
 def __init__(self):
     self.protocol = Protocol(Session, BicycleRental, self.readonly)
Example #51
0
 def __init__(self):
     self.protocol = Protocol(Session, Cafe, self.readonly)
Example #52
0
 def __init__(self):
     self.protocol = Protocol(Session, BarPub, self.readonly)
Example #53
0
 def test_protocol_delete_fails(self):
     """Try to delete a not-existing point"""
     proto = Protocol(session, Spot)
     
     proto.delete(FakeRequest({}), FakeResponse(), -1)
Example #54
0
 def test_protocol_count(self):
     """Get the feature count"""
     proto = Protocol(session, Spot)
     
     eq_(proto.count(FakeRequest({})), '9')
Example #55
0
 def test_protocol_read_one_fails(self):
     """Try to get a single point with a wrong primary key"""
     proto = Protocol(session, Spot)
     
     proto.read(FakeRequest({}), id=-1)
Example #56
0
    def test_protocol_query(self):
        from mapfish.protocol import Protocol, create_attr_filter
        proto = Protocol(Session, MappedClass)

        request = FakeRequest({})
        query = proto._query(request, execute=False)
        stmt = query.statement
        stmtm_str = stmt.compile(engine)
        assert "SELECT" in query_to_str(query)

        request = FakeRequest({"queryable": "id", "id__eq": "1"})
        query = proto._query(request, execute=False)
        assert "WHERE" in query_to_str(query)

        request = FakeRequest({"queryable": "id", "id__eq": "1"})
        filter = create_attr_filter(request, MappedClass)
        query = proto._query(FakeRequest({}), filter=filter, execute=False)
        assert "WHERE" in query_to_str(query)

        request = FakeRequest({"limit": "2"})
        query = proto._query(request, execute=False)
        print query_to_str(query)
        assert "LIMIT" in query_to_str(query)

        request = FakeRequest({"maxfeatures": "2"})
        query = proto._query(request, execute=False)
        assert "LIMIT" in query_to_str(query)

        request = FakeRequest({"limit": "2", "offset": "10"})
        query = proto._query(request, execute=False)
        assert "OFFSET" in query_to_str(query)

        request = FakeRequest({"order_by": "text"})
        query = proto._query(request, execute=False)
        assert "ORDER BY" in query_to_str(query)
        assert "ASC" in query_to_str(query)

        request = FakeRequest({"sort": "text"})
        query = proto._query(request, execute=False)
        assert "ORDER BY" in query_to_str(query)
        assert "ASC" in query_to_str(query)

        request = FakeRequest({"order_by": "text", "dir": "DESC"})
        query = proto._query(request, execute=False)
        assert "ORDER BY" in query_to_str(query)
        assert "DESC" in query_to_str(query)
Example #57
0
 def __init__(self):
     self.protocol = Protocol(Session, FreeBus, self.readonly)
Example #58
0
 def __init__(self):
     self.protocol = Protocol(Session, BicycleRental, self.readonly)
Example #59
0
    def test_protocol_count(self):
        """Get the feature count"""
        proto = Protocol(session, Spot)

        eq_(proto.count(FakeRequest({})), '9')