Пример #1
0
def get_features_function(parcelGeom, params):

    # split the layer list string into proper python list
    csvReader = csv.reader([params['layerList']], skipinitialspace=True)

    # iterate over layer and make intersects queries
    itemList = []
    for item in csvReader:
        itemList.append(item)
    layerList = itemList[0]

#    test = 'empty'
#    # retrieve models from table2model
#    for layer in layerList:
#        model = table2model_match[layer]

    # spatial analysis
    featureList = []
    for layer in layerList:
        targetModel = table2model_match[layer]
        intersectResult = DBSession.query(targetModel).filter(or_(targetModel.geom.ST_Intersects(parcelGeom), targetModel.geom.ST_Within(parcelGeom))).all()
        if intersectResult:
            # create geojson output with custom attributes
            for feature in intersectResult:
                geometryType = DBSession.scalar(feature.geom.ST_GeometryType())
                geomType = ''
                intersectionMeasure = -9999
                intersectionMeasureTxt = ''
                if geometryType == 'ST_Polygon' or geometryType == 'ST_MultiPolygon':
                    intersectionMeasure = DBSession.scalar(feature.geom.ST_Intersection(parcelGeom).ST_Area())
                    if intersectionMeasure >= 1:
                        intersectionMeasureTxt = ' : ' + str(int(round(intersectionMeasure, 0))) + ' [m2]'
                        geomType = 'Polygone'
                        jsonFeature = sloads(dumps(feature))
                        jsonFeature['properties']['layerName'] = layer
                        jsonFeature['properties']['intersectionMeasure'] = intersectionMeasureTxt
                        jsonFeature['properties']['geomType'] = 'area'
                        featureList.append(jsonFeature)
                elif geometryType == 'ST_Line' or geometryType == 'ST_MultiLineString' or geometryType == 'ST_LineString':
                    intersectionMeasure = DBSession.scalar(feature.geom.ST_Intersection(parcelGeom).ST_Length())
                    if intersectionMeasure >= 1:
                        intersectionMeasureTxt = ' : ' + str(int(round(intersectionMeasure, 0))) + ' [m]'
                        geomType = 'Ligne'
                        jsonFeature = sloads(dumps(feature))
                        jsonFeature['properties']['layerName'] = layer
                        jsonFeature['properties']['intersectionMeasure'] = intersectionMeasureTxt
                        jsonFeature['properties']['geomType'] = 'line'
                        featureList.append(jsonFeature)
                elif geometryType == 'ST_Point' or geometryType == 'ST_MultiPoint':
                    featureMeasure = -9999
                    geomType = 'Point'
                    intersectionMeasureTxt = ' '    # ' : point'
                    jsonFeature = sloads(dumps(feature))
                    jsonFeature['properties']['layerName'] = layer
                    jsonFeature['properties']['intersectionMeasure'] = intersectionMeasureTxt
                    jsonFeature['properties']['geomType'] = 'point'
                    featureList.append(jsonFeature)

    return featureList
Пример #2
0
    def _test_geo_interface_declarative_shape_unset(self, mapped_class):
        from geojson import Feature, Point
        from papyrus.geojsonencoder import dumps

        mapped_class = self._get_mapped_class_declarative()
        feature = Feature(
            id=1,
            properties={"text": "foo", "child": "foo", "children": ["foo", "foo"]},
            geometry=Point(coordinates=[53, -4]),
        )
        obj = mapped_class(feature)
        # we want to simulate the case where the geometry is read from
        # the database, so we delete _shape
        del (obj._shape)
        obj_json = dumps(obj)
        json_parsed = json.loads(obj_json)
        self.assertEqual(
            json_parsed,
            {
                "geometry": {"type": "Point", "coordinates": [53.0, -4.0]},
                "type": "Feature",
                "id": 1,
                "properties": {"text": "foo", "children": ["foo", "foo"], "child": "foo"},
            },
        )  # NOQA
Пример #3
0
 def _test_geo_interface_declarative_shape_unset(self, mapped_class):
     from geojson import Feature, Point
     from papyrus.geojsonencoder import dumps
     mapped_class = self._get_mapped_class_declarative()
     feature = Feature(id=1,
                       properties={
                           'text': 'foo',
                           'child': 'foo',
                           'children': ['foo', 'foo']
                       },
                       geometry=Point(coordinates=[53, -4]))
     obj = mapped_class(feature)
     # we want to simulate the case where the geometry is read from
     # the database, so we delete _shape
     del (obj._shape)
     obj_json = dumps(obj)
     json_parsed = json.loads(obj_json)
     self.assertEqual(
         json_parsed, {
             "geometry": {
                 "type": "Point",
                 "coordinates": [53.0, -4.0]
             },
             "type": "Feature",
             "id": 1,
             "properties": {
                 "text": "foo",
                 "children": ["foo", "foo"],
                 "child": "foo"
             }
         })
Пример #4
0
 def _test_geo_interface(self, mapped_class):
     from geojson import Feature, Point
     from papyrus.geojsonencoder import dumps
     mapped_class = self._get_mapped_class_declarative()
     feature = Feature(id=1,
                       properties={
                           'text': 'foo',
                           'child': 'bar',
                           'children': ['foo', 'bar']
                       },
                       geometry=Point(coordinates=[53, -4]))
     obj = mapped_class(feature)
     obj_json = dumps(obj)
     json_parsed = json.loads(obj_json)
     self.assertEqual(
         json_parsed, {
             "geometry": {
                 "type": "Point",
                 "coordinates": [53.0, -4.0]
             },
             "type": "Feature",
             "id": 1,
             "properties": {
                 "text": "foo",
                 "children": ["foo", "bar"],
                 "child": "bar"
             }
         })
Пример #5
0
    def _test_geo_interface_no_feature(self, mapped_class):
        from papyrus.geojsonencoder import dumps

        obj = mapped_class()
        obj_json = dumps(obj)
        json_parsed = json.loads(obj_json)
        self.assertEqual(
            json_parsed,
            {"geometry": None, "type": "Feature", "properties": {"text": None, "children": [], "child": None}},
        )  # NOQA
Пример #6
0
 def _test_geo_interface(self, mapped_class):
     from geojson import Feature, Point
     from papyrus.geojsonencoder import dumps
     mapped_class = self._get_mapped_class_declarative()
     feature = Feature(id=1, properties={'text': 'foo', 'child': 'bar',
                                         'children': ['foo', 'bar']},
                       geometry=Point(coordinates=[53, -4]))
     obj = mapped_class(feature)
     json = dumps(obj)
     self.assertEqual(json, '{"geometry": {"type": "Point", "coordinates": [53.0, -4.0]}, "type": "Feature", "properties": {"text": "foo", "children": ["foo", "bar"], "child": "bar"}, "id": 1}')  # NOQA
Пример #7
0
 def _test_geo_interface_declarative_shape_unset(self, mapped_class):
     from geojson import Feature, Point
     from papyrus.geojsonencoder import dumps
     mapped_class = self._get_mapped_class_declarative()
     feature = Feature(id=1, properties={'text': 'foo', 'child': 'foo',
                                         'children': ['foo', 'foo']},
                       geometry=Point(coordinates=[53, -4]))
     obj = mapped_class(feature)
     # we want to simulate the case where the geometry is read from
     # the database, so we delete _shape and set geom.geom_wkb
     del(obj._shape)
     obj.geom.geom_wkb = obj.geom.desc
     json = dumps(obj)
     self.assertEqual(json, '{"geometry": {"type": "Point", "coordinates": [53.0, -4.0]}, "type": "Feature", "properties": {"text": "foo", "children": ["foo", "foo"], "child": "foo"}, "id": 1}')  # NOQA
Пример #8
0
 def _test_geo_interface_no_feature(self, mapped_class):
     from papyrus.geojsonencoder import dumps
     obj = mapped_class()
     obj_json = dumps(obj)
     json_parsed = json.loads(obj_json)
     self.assertEqual(
         json_parsed, {
             u"geometry": None,
             u"type": u"Feature",
             u"properties": {
                 u"text": None,
                 u"children": [],
                 u"child": None
             }
         })  # NOQA
Пример #9
0
 def _render(value, system):
     if isinstance(value, (list, tuple)):
         value = self.collection_type(value)
     ret = dumps(value)
     request = system.get("request")
     if request is not None:
         response = request.response
         ct = response.content_type
         if ct == response.default_content_type:
             callback = request.params.get(self.jsonp_param_name)
             if callback is None:
                 response.content_type = "application/json"
             else:
                 response.content_type = "text/javascript"
                 ret = "%(callback)s(%(json)s);" % {"callback": callback, "json": ret}
     return ret
Пример #10
0
 def _render(value, system):
     if isinstance(value, (list, tuple)):
         value = self.collection_type(value)
     ret = dumps(value)
     request = system.get('request')
     if request is not None:
         response = request.response
         ct = response.content_type
         if ct == response.default_content_type:
             callback = request.params.get(self.jsonp_param_name)
             if callback is None:
                 response.content_type = 'application/geo+json'
             else:
                 response.content_type = 'text/javascript'
                 ret = ('%(callback)s(%(json)s);' %
                        {'callback': callback, 'json': ret})
     return ret
Пример #11
0
 def _render(value, system):
     if isinstance(value, (list, tuple)):
         value = self.collection_type(value)
     ret = dumps(value)
     request = system.get('request')
     if request is not None:
         response = request.response
         ct = response.content_type
         if ct == response.default_content_type:
             callback = request.params.get(self.jsonp_param_name)
             if callback is None:
                 response.content_type = 'application/json'
             else:
                 response.content_type = 'text/javascript'
                 ret = '%(callback)s(%(json)s);' % {
                     'callback': callback,
                     'json': ret
                 }
     return ret
Пример #12
0
    def _test_geo_interface(self, mapped_class):
        from geojson import Feature, Point
        from papyrus.geojsonencoder import dumps

        mapped_class = self._get_mapped_class_declarative()
        feature = Feature(
            id=1,
            properties={"text": "foo", "child": "bar", "children": ["foo", "bar"]},
            geometry=Point(coordinates=[53, -4]),
        )
        obj = mapped_class(feature)
        obj_json = dumps(obj)
        json_parsed = json.loads(obj_json)
        self.assertEqual(
            json_parsed,
            {
                "geometry": {"type": "Point", "coordinates": [53.0, -4.0]},
                "type": "Feature",
                "id": 1,
                "properties": {"text": "foo", "children": ["foo", "bar"], "child": "bar"},
            },
        )  # NOQA
Пример #13
0
def get_features_function(parcelGeom, params):

    # split the layer list string into proper python list
    csvReader = csv.reader([params['layerList']], skipinitialspace=True)

    # iterate over layer and make intersects queries
    itemList = []
    for item in csvReader:
        itemList.append(item)
    layerList = itemList[0]

    #    test = 'empty'
    #    # retrieve models from table2model
    #    for layer in layerList:
    #        model = table2model_match[layer]

    # spatial analysis
    featureList = []
    for layer in layerList:
        targetModel = table2model_match[layer]
        intersectResult = DBSession.query(targetModel).filter(
            or_(targetModel.geom.ST_Intersects(parcelGeom),
                targetModel.geom.ST_Within(parcelGeom))).all()
        if intersectResult:
            # create geojson output with custom attributes
            for feature in intersectResult:
                geometryType = DBSession.scalar(feature.geom.ST_GeometryType())
                geomType = ''
                intersectionMeasure = -9999
                intersectionMeasureTxt = ''
                if geometryType == 'ST_Polygon' or geometryType == 'ST_MultiPolygon':
                    intersectionMeasure = DBSession.scalar(
                        feature.geom.ST_Intersection(parcelGeom).ST_Area())
                    if intersectionMeasure >= 1:
                        intersectionMeasureTxt = ' : ' + str(
                            int(round(intersectionMeasure, 0))) + ' [m2]'
                        geomType = 'Polygone'
                        jsonFeature = sloads(dumps(feature))
                        jsonFeature['properties']['layerName'] = layer
                        jsonFeature['properties'][
                            'intersectionMeasure'] = intersectionMeasureTxt
                        jsonFeature['properties']['geomType'] = 'area'
                        featureList.append(jsonFeature)
                elif geometryType == 'ST_Line' or geometryType == 'ST_MultiLineString' or geometryType == 'ST_LineString':
                    intersectionMeasure = DBSession.scalar(
                        feature.geom.ST_Intersection(parcelGeom).ST_Length())
                    if intersectionMeasure >= 1:
                        intersectionMeasureTxt = ' : ' + str(
                            int(round(intersectionMeasure, 0))) + ' [m]'
                        geomType = 'Ligne'
                        jsonFeature = sloads(dumps(feature))
                        jsonFeature['properties']['layerName'] = layer
                        jsonFeature['properties'][
                            'intersectionMeasure'] = intersectionMeasureTxt
                        jsonFeature['properties']['geomType'] = 'line'
                        featureList.append(jsonFeature)
                elif geometryType == 'ST_Point' or geometryType == 'ST_MultiPoint':
                    featureMeasure = -9999
                    geomType = 'Point'
                    intersectionMeasureTxt = ' '  # ' : point'
                    jsonFeature = sloads(dumps(feature))
                    jsonFeature['properties']['layerName'] = layer
                    jsonFeature['properties'][
                        'intersectionMeasure'] = intersectionMeasureTxt
                    jsonFeature['properties']['geomType'] = 'point'
                    featureList.append(jsonFeature)

    return featureList
Пример #14
0
def get_features_function(params):
    # for dev purposes: matching dictionnary model-table name
    table2model = {
        'at39_itineraires_pedestres':PedestrianWays,
        'at14_zones_communales': CommunalArea,
        'at08_zones_cantonales': StateArea,
        'clo_couloirs': Corridors,
        'clo_cotes_altitude_surfaces': AltitudeRatings,
        'en07_canepo_accidents': PollutedSitesAccidents,
        'en07_canepo_decharges': PollutedSitesLandDumps,
        'en07_canepo_decharges_points': PollutedSitesLandDumpsPts,
        'en07_canepo_decharges_polygones': PollutedSitesLandDumpsPoly,
        'en07_canepo_entreprises': PollutedSitesCompanies,
        'en07_canepo_entreprises_points': PollutedSitesCompaniesPts,
        'en07_canepo_entreprises_polygones': PollutedSitesCompaniesPoly,
        'at28_limites_constructions': ConstructionsLimits,
        'en05_degres_sensibilite_bruit': RoadNoise,
        'en01_zone_sect_protection_eaux': Zoneprotection
    }

    parcelId = params['id']
    # get the parcel geometry
    queryParcel =DBSession.query(ImmeublesCanton).filter_by(idemai=parcelId).first()
    parcelGeom = queryParcel.geom
    # split the layer list string into proper python list
    csvReader = csv.reader([params['layerList']], skipinitialspace=True)

    # iterate over layer and make intersects queries
    itemList = []
    for item in csvReader:
        itemList.append(item)
    layerList = itemList[0]

    test = 'empty'
    # retrieve models from table2model
    for layer in layerList:
        model = table2model[layer]

    # spatial analysis
    featureList = []
    for layer in layerList:
        targetModel = table2model[layer]
        intersectResult = DBSession.query(targetModel).filter(or_(targetModel.geom.intersects(parcelGeom), targetModel.geom.within(parcelGeom))).all()
        if intersectResult:
            # create geojson output with custom attributes
            for feature in intersectResult:
                geometryType = DBSession.scalar(feature.geom.geometry_type())
                geomType = ''
                featureClass = ''
                featureMeasure = -9999
                intersectionMeasure = -9999
                intersectionMeasureTxt = ''
                if geometryType == 'ST_Polygon' or geometryType == 'ST_MultiPolygon':
                    intersectionMeasure = DBSession.scalar(feature.geom.intersection(parcelGeom).area())
                    intersectionMeasureTxt = ' - ' + str(math.ceil(intersectionMeasure*10)/10) + ' [m2]'
                    featureMeasure = 100 * intersectionMeasure / DBSession.scalar(parcelGeom.area())
                    geomType = 'Polygone'
                    if featureMeasure >= 99:
                        featureClass = 'within'
                    elif featureMeasure < 99 and featureMeasure >= 0:
                        featureClass = 'intersects'
                    elif featureMeasure < 0:
                        featureClass = 'adjacent'

                elif geometryType == 'ST_Line' or geometryType == 'ST_MultiLineString' or geometryType == 'ST_LineString':
                    intersectionMeasure = intersectionMeasure = DBSession.scalar(feature.geom.intersection(parcelGeom).length())
                    intersectionMeasureTxt = ' - ' + str(math.ceil(intersectionMeasure*10)/10) + ' [m]'
                    geomType = 'Ligne'
                elif geometryType == 'ST_Point' or geometryType == 'ST_MultiPoint':
                    featureMeasure = -9999
                    geomType = 'Point'
                    intersectionMeasureTxt = ' - point'
                    
                jsonFeature = sloads(dumps(feature))
                jsonFeature['properties']['layerName'] = layer
                jsonFeature['properties']['featureClass'] = featureClass
                jsonFeature['properties']['intersectionMeasure'] = intersectionMeasureTxt
                featureList.append(jsonFeature)

    return featureList