def _identify_grid(params, layerBodIds): features = [] if len(layerBodIds) == 0: return features geometry = params.geometry # TODO support min/max scale and min/max resolution? # For select by rectangle if params.geometryType == 'esriGeometryEnvelope': coords = list(geometry.exterior.coords) minx = miny = float('inf') maxx = maxy = float('-inf') for x, y in coords: minx = min(minx, x) miny = min(miny, y) maxx = max(maxx, x) maxy = max(maxy, y) bbox = [minx, miny, maxx, maxy] pointCoordinates = center_from_box2d(bbox) else: pointCoordinates = list(list(geometry.coords)[0]) if params.srid == 2056: pointCoordinates = shift_to(pointCoordinates, 21781) bucketName = params.request.registry.settings['vector_bucket'] bucket = get_bucket(bucketName) for layer in layerBodIds: [layerBodId, gridSpec] = next(layer.iteritems()) params.layerId = layerBodId layerProperties = get_grid_layer_properties(layerBodId) timestamp = layerProperties.get('timestamp') grid = Grid(gridSpec.get('extent'), gridSpec.get('resolutionX'), gridSpec.get('resolutionY')) [col, row] = grid.cellAddressFromPointCoordinate(pointCoordinates) if col is not None and row is not None: feature, none = _get_feature_grid(col, row, timestamp, grid, bucket, params) if feature and not none: feature['bbox'] = grid.cellExtent(col, row) # For some reason we define the id twice.. feature['featureId'] = feature['id'] feature['properties']['label'] = feature['id'] if params.srid == 2056: feature['bbox'] = shift_to(feature['bbox'], 2056) # Coords are always simple polygons coords = feature['geometry']['coordinates'] coords = [[shift_to(c, 2056) for c in coords[0]]] feature['geometry']['coordinates'] = coords features.append(feature) return features
def layerConfig(self, params): config = {} translate = params.translate settings = params.request.registry.settings wmsHost = settings['wmshost'] defaultResolution = 0.5 for k in self.__dict__.keys(): val = self.__dict__[k] if not k.startswith("_") and not k.startswith('geojsonUrl') and \ val is not None and k not in ('staging', 'srid'): if k == 'maps': config['topics'] = val elif k == 'layerBodId': config['label'] = translate(val) elif k == 'attribution': config[k] = translate(val) elif k == 'tilematrix_resolution_max': if val != defaultResolution and \ self.__dict__['srid'] != u'4326': config[ 'resolutions'] = self._getResolutionsFromMatrixSet( val, params.srid) elif k == 'extent': # Used for the shop, are still in lv03 if val and params.srid == 2056: config['extent'] = shift_to(val, 2056) else: config['extent'] = val else: config[k] = val if config['type'] in ('wmts', 'aggregate', 'geojson'): del config['singleTile'] if not config['timeEnabled']: del config['timeBehaviour'] if config['type'] == 'wms': config['wmsUrl'] = 'https://%s' % wmsHost elif config['type'] == 'geojson': api_url = params.request.registry.settings['api_url'] config['styleUrl'] = make_agnostic(api_url + '/static/vectorStyles/' + self.layerBodId + '.json') config['geojsonUrl'] = self._getGeoJsonUrl(params.lang) if 'format' in config: del config['format'] # sublayers don't have attributions if 'attribution' in config: config['attributionUrl'] = translate(self.__dict__['attribution'] + '.url') # adding __queryable_attributes__ if they have them models = models_from_bodid(self.layerBodId) if models is not None: queryable_attributes = get_models_attributes_keys( models, params.lang, True) if len(queryable_attributes) > 0: config['queryableAttributes'] = queryable_attributes return {self.layerBodId: config}
def layerConfig(self, params): config = {} translate = params.translate settings = params.request.registry.settings wmsHost = settings['wmshost'] defaultResolution = 0.5 for k in self.__dict__.keys(): val = self.__dict__[k] if not k.startswith("_") and not k.startswith('geojsonUrl') and \ val is not None and k not in ('staging', 'srid'): if k == 'maps': config['topics'] = val elif k == 'layerBodId': config['label'] = translate(val) elif k == 'attribution': config[k] = translate(val) elif k == 'tilematrix_resolution_max': if val != defaultResolution and \ self.__dict__['srid'] != u'4326': config['resolutions'] = self._getResolutionsFromMatrixSet( val, params.srid) elif k == 'extent': # Used for the shop, are still in lv03 if val and params.srid == 2056: config['extent'] = shift_to(val, 2056) else: config['extent'] = val else: config[k] = val if config['type'] in ('wmts', 'aggregate', 'geojson'): del config['singleTile'] if not config['timeEnabled']: del config['timeBehaviour'] if config['type'] == 'wms': config['wmsUrl'] = 'https://%s' % wmsHost elif config['type'] == 'geojson': api_url = params.request.registry.settings['api_url'] config['styleUrl'] = make_agnostic( api_url + '/static/vectorStyles/' + self.layerBodId + '.json') config['geojsonUrl'] = self._getGeoJsonUrl(params.lang) if 'format' in config: del config['format'] # sublayers don't have attributions if 'attribution' in config: config['attributionUrl'] = translate(self.__dict__['attribution'] + '.url') # adding __queryable_attributes__ if they have them models = models_from_bodid(self.layerBodId) if models is not None: queryable_attributes = get_models_attributes_keys(models, params.lang, True) if len(queryable_attributes) > 0: config['queryableAttributes'] = queryable_attributes return {self.layerBodId: config}
def _identify_grid(params, layerBodIds): features = [] if len(layerBodIds) == 0: return features geometry = params.geometry # TODO support min/max scale and min/max resolution? # For select by rectangle if params.geometryType == 'esriGeometryEnvelope': coords = list(geometry.exterior.coords) minx = miny = float('inf') maxx = maxy = float('-inf') for x, y in coords: minx = min(minx, x) miny = min(miny, y) maxx = max(maxx, x) maxy = max(maxy, y) bbox = [minx, miny, maxx, maxy] pointCoordinates = center_from_box2d(bbox) else: pointCoordinates = list(list(geometry.coords)[0]) bucketName = params.request.registry.settings['vector_bucket'] bucket = get_bucket(bucketName) for layer in layerBodIds: [layerBodId, gridSpec] = next(layer.iteritems()) params.layerId = layerBodId layerProperties = get_grid_layer_properties(layerBodId) timestamp = layerProperties.get('timestamp') grid = Grid(gridSpec.get('extent'), gridSpec.get('resolutionX'), gridSpec.get('resolutionY')) if params.srid == 2056 and gridSpec.get('srid') == '21781': pointCoordinates = shift_to(pointCoordinates, 21781) elif params.srid == 21781 and gridSpec.get('srid') == '2056': pointCoordinates = shift_to(pointCoordinates, 2056) [col, row] = grid.cellAddressFromPointCoordinate(pointCoordinates) if col is not None and row is not None: feature, none = _get_feature_grid(col, row, timestamp, grid, bucket, params) if feature and not none: feature['bbox'] = grid.cellExtent(col, row) # For some reason we define the id twice.. feature['featureId'] = feature['id'] feature['properties']['label'] = feature['id'] if params.srid == 2056 and gridSpec.get('srid') == '21781': feature['bbox'] = shift_to(feature['bbox'], 2056) coords = feature['geometry']['coordinates'] coords = [[shift_to(c, 2056) for c in coords[0]]] feature['geometry']['coordinates'] = coords if params.srid == 21781 and gridSpec.get('srid') == '2056': feature['bbox'] = shift_to(feature['bbox'], 21781) coords = feature['geometry']['coordinates'] coords = [[shift_to(c, 21781) for c in coords[0]]] feature['geometry']['coordinates'] = coords features.append(feature) return features
def _bbox_intersection(self, ref, result): def _is_point(bbox): return bbox[0] == bbox[2] and bbox[1] == bbox[3] # We always keep the bbox in 21781 if self.srid == 2056: ref = shift_to(ref, 2056) try: refbox = box(ref[0], ref[1], ref[2], ref[3]) if not _is_point(ref) else Point(ref[0], ref[1]) arr = parse_box2d(result) resbox = box(arr[0], arr[1], arr[2], arr[3]) if not _is_point(arr) else Point(arr[0], arr[1]) except: # pragma: no cover # We bail with True to be conservative and # not exclude this geometry from the result # set. Only happens if result does not # have a bbox return True return refbox.intersects(resbox)
def bbox(self, value): if value is not None and value != '': values = value.split(',') if len(values) != 4: raise HTTPBadRequest("Please provide 4 coordinates in a comma separated list") try: values = map(float_raise_nan, values) except ValueError: raise HTTPBadRequest("Please provide numerical values for the parameter bbox") if self._srid == 2056: values = shift_to(values, 21781) # Swiss extent if values[0] >= 420000 and values[1] >= 30000: if values[0] < values[1]: raise HTTPBadRequest("The first coordinate must be higher than the second") if values[2] >= 420000 and values[3] >= 30000: if values[2] < values[3]: raise HTTPBadRequest("The third coordinate must be higher than the fourth") self._bbox = values
def _bbox_intersection(self, ref, result): def _is_point(bbox): return bbox[0] == bbox[2] and bbox[1] == bbox[3] # We always keep the bbox in 21781 if self.srid == 2056: ref = shift_to(ref, 2056) try: refbox = box(ref[0], ref[1], ref[2], ref[3]) if not _is_point(ref) else Point( ref[0], ref[1]) arr = parse_box2d(result) resbox = box(arr[0], arr[1], arr[2], arr[3]) if not _is_point(arr) else Point( arr[0], arr[1]) except Exception: # pragma: no cover # We bail with True to be conservative and # not exclude this geometry from the result # set. Only happens if result does not # have a bbox return True return refbox.intersects(resbox)
def bbox(self, value): if value is not None and value != '': values = value.split(',') if len(values) != 4: raise HTTPBadRequest( "Please provide 4 coordinates in a comma separated list") try: values = map(float_raise_nan, values) except ValueError: raise HTTPBadRequest( "Please provide numerical values for the parameter bbox") if self._srid == 2056: values = shift_to(values, 21781) # Swiss extent if values[0] >= 420000 and values[1] >= 30000: if values[0] < values[1]: raise HTTPBadRequest( "The first coordinate must be higher than the second") if values[2] >= 420000 and values[3] >= 30000: if values[2] < values[3]: raise HTTPBadRequest( "The third coordinate must be higher than the fourth") self._bbox = values