Changeset 3715 for framework

Show
Ignore:
Timestamp:
01/05/11 12:17:19 (17 months ago)
Author:
bbinet
Message:

fix error 500 when geometry is null and update mapfish protocol to allow to send features with null geometry, r=elemoine (closes #607)

Location:
framework/server/trunk/mapfish
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • framework/server/trunk/mapfish/protocol.py

    r3659 r3715  
    279279            ret = FeatureCollection( 
    280280                    [self._filter_attrs(o.toFeature(), request) \ 
    281                         for o in objs if o.geometry is not None]) 
     281                        for o in objs]) 
    282282        return ret 
    283283 
     
    311311        response.status = 201 
    312312        if len(objects) > 0: 
    313             features = [o.toFeature() for o in objects \ 
    314                             if o.geometry is not None] 
     313            features = [o.toFeature() for o in objects] 
    315314            return FeatureCollection(features) 
    316315        return 
  • framework/server/trunk/mapfish/sqlalchemygeom.py

    r3659 r3715  
    212212            # we already have the geometry as Shapely geometry (when updating/inserting) 
    213213            geometry = self.geometry.shape 
    214         else: 
     214        elif hasattr(self.geometry, 'geom_wkb') and self.geometry.geom_wkb is not None: 
    215215            # create a Shapely geometry from the WKB geometry returned from the database 
    216216            geometry = loads(str(self.geometry.geom_wkb)) 
     217        else: 
     218            geometry = None 
    217219 
    218220        return Feature(id=self.fid,  
    219221                       geometry=geometry, 
    220222                       properties=attributes, 
    221                        bbox=geometry.bounds) 
     223                       bbox=None if geometry is None else geometry.bounds) 
    222224 
    223225 
  • framework/server/trunk/mapfish/tests/test_mysql.py

    r3659 r3715  
    6060    spot_id = Column(Integer, primary_key=True) 
    6161    spot_height = Column(Numeric(precision=10, scale=2, asdecimal=False)) 
    62     spot_location = GeometryColumn(Point(2)) 
     62    spot_location = GeometryColumn(Point(2, spatial_index=False), nullable=True) 
    6363 
    6464GeometryDDL(Spot.__table__) 
     
    9191            Spot(spot_height=783.55, spot_location='POINT(38 34)'), 
    9292            Spot(spot_height=3454.67, spot_location='POINT(-134 45)'), 
    93             Spot(spot_height=6454.23, spot_location='POINT(-135 56)') 
     93            Spot(spot_height=6454.23, spot_location=None) 
    9494            ]) 
    9595         
     
    337337        eq_(feature.geometry.coordinates, (0.0, 0.0)) 
    338338        eq_(feature.properties["spot_height"], 420.39999999999998) 
     339 
     340 
     341    def test_protocol_read_one_null(self): 
     342        """Return one null feature""" 
     343        proto = Protocol(session, Spot) 
     344 
     345        feature = proto.read(FakeRequest({}), id=9) 
     346        ok_(feature is not None) 
     347        ok_(isinstance(feature, Feature)) 
     348        eq_(feature.id, 9) 
     349        # make use of __geo_interface__ property since 'geometry' 
     350        # value is not the same in various versions of geojson lib 
     351        ok_(feature.__geo_interface__['geometry'] is None) 
     352        ok_(feature.__geo_interface__['bbox'] is None) 
    339353 
    340354 
  • framework/server/trunk/mapfish/tests/test_oracle.py

    r3659 r3715  
    3737 
    3838from geoalchemy import (Point, Polygon, GeometryColumn, GeometryDDL) 
     39from geoalchemy.oracle import ORACLE_NULL_GEOMETRY 
    3940 
    4041from mapfish.sqlalchemygeom import GeometryTableMixIn 
     
    107108            Spot(spot_height=783.55, spot_location='POINT(38 34)'), 
    108109            Spot(spot_height=3454.67, spot_location='POINT(-134 45)'), 
    109             Spot(spot_height=6454.23, spot_location='POINT(-135 56)') 
     110            Spot(spot_height=6454.23, spot_location=ORACLE_NULL_GEOMETRY) 
    110111            ]) 
    111112         
     
    295296         
    296297        filter = create_default_filter(request, Spot, additional_params={'params': 'unit=KM'}) 
    297         eq_(proto.count(request, filter=filter), '9') 
     298        eq_(proto.count(request, filter=filter), '8') 
    298299         
    299300 
     
    367368 
    368369 
     370    def test_protocol_read_one_null(self): 
     371        """Return one null feature""" 
     372        proto = Protocol(session, Spot) 
     373 
     374        feature = proto.read(FakeRequest({}), id=9) 
     375        ok_(feature is not None) 
     376        ok_(isinstance(feature, Feature)) 
     377        eq_(feature.id, 9) 
     378        # make use of __geo_interface__ property since 'geometry' 
     379        # value is not the same in various versions of geojson lib 
     380        ok_(feature.__geo_interface__['geometry'] is None) 
     381        ok_(feature.__geo_interface__['bbox'] is None) 
     382 
     383 
    369384    @raises(HTTPNotFound) 
    370385    def test_protocol_read_one_fails(self): 
  • framework/server/trunk/mapfish/tests/test_postgis.py

    r3659 r3715  
    9191            Spot(spot_height=783.55, spot_location='POINT(38 34)'), 
    9292            Spot(spot_height=3454.67, spot_location='POINT(-134 45)'), 
    93             Spot(spot_height=6454.23, spot_location='POINT(-135 56)') 
     93            Spot(spot_height=6454.23, spot_location=None) 
    9494            ]) 
    9595         
     
    329329        eq_(feature.geometry.coordinates, (0.0, 0.0)) 
    330330        eq_(feature.properties["spot_height"], 420.39999999999998) 
     331 
     332 
     333    def test_protocol_read_one_null(self): 
     334        """Return one null feature""" 
     335        proto = Protocol(session, Spot) 
     336 
     337        feature = proto.read(FakeRequest({}), id=9) 
     338        ok_(feature is not None) 
     339        ok_(isinstance(feature, Feature)) 
     340        eq_(feature.id, 9) 
     341        # make use of __geo_interface__ property since 'geometry' 
     342        # value is not the same in various versions of geojson lib 
     343        ok_(feature.__geo_interface__['geometry'] is None) 
     344        ok_(feature.__geo_interface__['bbox'] is None) 
    331345 
    332346 
  • framework/server/trunk/mapfish/tests/test_spatialite.py

    r3659 r3715  
    110110            Spot(spot_height=783.55, spot_location='POINT(38 34)'), 
    111111            Spot(spot_height=3454.67, spot_location='POINT(-134 45)'), 
    112             Spot(spot_height=6454.23, spot_location='POINT(-135 56)') 
     112            Spot(spot_height=6454.23, spot_location=None) 
    113113            ]) 
    114114         
     
    349349        eq_(feature.properties["spot_height"], 420.39999999999998) 
    350350        proto = Protocol(session, Spot) 
     351 
     352 
     353    def test_protocol_read_one_null(self): 
     354        """Return one null feature""" 
     355        proto = Protocol(session, Spot) 
     356 
     357        feature = proto.read(FakeRequest({}), id=9) 
     358        ok_(feature is not None) 
     359        ok_(isinstance(feature, Feature)) 
     360        eq_(feature.id, 9) 
     361        # make use of __geo_interface__ property since 'geometry' 
     362        # value is not the same in various versions of geojson lib 
     363        ok_(feature.__geo_interface__['geometry'] is None) 
     364        ok_(feature.__geo_interface__['bbox'] is None) 
    351365 
    352366