Exemplo n.º 1
0
    def tilejson(model_id, prediction_id):
        """
        Get the TileJSON of the prediction id given

        :params model_id
        :params prediction_id
        :returns dict
        """

        tiles = PredictionTile.count(prediction_id)

        if tiles.count == 0:
            raise PredictionsNotFound('No Prediction Tiles exist')

        ml_model = MLModel.get(model_id)
        prediction = Prediction.get(prediction_id)

        tilejson = {
            "tilejson":
            "2.1.0",
            "name":
            ml_model.name,
            "description":
            ml_model.project_url,
            "inferences":
            PredictionTile.inferences(prediction_id),
            "token":
            CONFIG.EnvironmentConfig.MAPBOX_TOKEN,
            "attribution":
            ml_model.source,
            "version":
            prediction.version,
            "scheme":
            "xyz",
            "type":
            "vector",
            "tiles": [
                "/v1/model/{0}/prediction/{1}/tiles/{{z}}/{{x}}/{{y}}.mvt".
                format(model_id, prediction_id)
            ],
            "minzoom":
            0,
            "maxzoom":
            prediction.tile_zoom,
            "bounds":
            PredictionTile.bbox(prediction_id)
        }

        return tilejson
Exemplo n.º 2
0
    def get_aggregated_tiles(model_id: int, bbox: list, zoom: int):
        """
        Get aggregated predictions at the specified zoom level for the supplied bbox
        :params model_id, bbox, zoom
        :returns list of tiles with predictions
        """
        # get predictions within this bbox
        boundingBox = bbox_str_to_list(bbox)
        predictions = PredictionService.get(model_id, boundingBox, latest=True)
        # find quadkeys for the given bbox
        boundingBox = bbox_str_to_list(bbox)
        quadkeys = bbox_to_quadkeys(boundingBox, zoom)
        prediction_tiles = {}
        for prediction in predictions:
            # query all tiles within those quadkeys and aggregate
            if int(prediction['tileZoom']) < int(zoom):
                raise ValueError(
                    'Aggregate zoom level is greater than prediction zoom')

            tiles = list(
                map(
                    tuple_to_dict,
                    PredictionTile.get_tiles_by_quadkey(
                        prediction['predictionsId'], tuple(quadkeys), zoom)))
            prediction_tiles[prediction['predictionsId']] = tiles

        return prediction_tiles
Exemplo n.º 3
0
    def inferences(prediction_id):
        """
        Get an array of inference names for a given prediction

        :params prediction_id
        :returns list
        """

        return PredictionTile.inferences(prediction_id)
Exemplo n.º 4
0
    def mvt(model_id, prediction_id, z, x, y):
        """
        :params model_id
        :params prediction_id
        :params z
        :params x
        :params y
        """

        return PredictionTile.mvt(prediction_id, z, x, y)
Exemplo n.º 5
0
    def get_aggregated_tiles_geojson(model_id: int, bbox: list, geojson: dict):
        """
        For the given geojson, find predictions for each polygon and return the geojson
        :param model_id, bbox, geojson
        :returns geojson
        """
        # get the latest prediction
        prediction = PredictionService.get(model_id, bbox, latest=True)
        # for each geojson feature, find the tiles and aggregate
        for feature in geojson['features']:
            tile_aggregate = PredictionTile.get_aggregate_for_polygon(
                prediction[0]['predictionsId'],
                polygon_to_wkt(feature['geometry']))
            if (len(tile_aggregate) > 0):
                feature['properties']['ml_prediction'] = tile_aggregate[0]
                feature['properties']['osm_building_area'] = tile_aggregate[1]

        return geojson
Exemplo n.º 6
0
 def validity(predictiontile_id, validity):
     tile = PredictionTile.get(predictiontile_id)
     tile.update(validity)
Exemplo n.º 7
0
 def get(predictiontile_id):
     return PredictionTile.get(predictiontile_id)