def test_mapset_info(self):
        iface = ActiniaInterface(self.gconf)
        status, info = iface.mapset_info(location="latlong_wgs84",
                                         mapset="modis_ndvi_global")
        pprint(info)

        self.assertEqual(status, 200)
        self.assertTrue("region" in info)
        self.assertTrue("projection" in info)
Exemple #2
0
class CollectionInformationResource(Resource):

    def __init__(self):
        self.iface = ActiniaInterface()

    def get(self, name):

        # List strds maps from the GRASS location
        location, mapset, datatype, layer = self.iface.layer_def_to_components(
            name)

        if location == "stac":
            status_code, collection = self.iface.get_stac_collection(name=name)
            if status_code != 200:
                return make_response(
                    jsonify(
                        {
                            "id": "12345678",
                            "code": "Internal",
                            "message": "Server error: %s" %
                            (name),
                            "links": {}}),
                    500)

            # Not using CollectionInformation model here for now
            # as valid STAC collections comply.
            # Using it here might omit some properties
            # which are not modelled in this backend (e.g. assets)
            return make_response(collection, 200)

        status_code, layer_data = self.iface.layer_info(layer_name=name)
        if status_code != 200:
            return make_response(
                jsonify(
                    {
                        "id": "12345678",
                        "code": "CollectionNotFound",
                        "message": "Collection '%s' does not exist." %
                        (name),
                        "links": {}}),
                404)

        # Get the projection from the GRASS mapset
        status_code, mapset_info = self.iface.mapset_info(
            location=location, mapset=mapset)
        if status_code != 200:
            return make_response(
                jsonify(
                    {
                        "id": "12345678",
                        "code": "Internal",
                        "message": "Server error: %s" %
                        (mapset_info),
                        "links": {}}),
                500)

        extent = CollectionExtent(
            spatial=(
                float(
                    layer_data["west"]), float(
                    layer_data["south"]), float(
                    layer_data["east"]), float(
                        layer_data["north"])), temporal=(
                            "1900-01-01T00:00:00", "2100-01-01T00:00:00"))

        title = "Raster dataset"
        bands = []
        dimensions = {"x": {
            "type": "spatial",
            "axis": "x",
            "extent": [layer_data["west"], layer_data["east"]],
            "reference_system": mapset_info["projection"]
        },
            "y": {
            "type": "spatial",
            "axis": "y",
            "extent": [layer_data["south"], layer_data["north"]],
            "reference_system": mapset_info["projection"]
        },
        }
        platform = "unknown"
        instrument = "unknown"
        if datatype.lower() == "strds":
            title = "Space time raster dataset"

            start_time = layer_data["start_time"]
            end_time = layer_data["end_time"]

            if start_time:
                start_time = start_time.replace(
                    " ",
                    "T").replace(
                    "'",
                    "").replace(
                    '"',
                    '')

            if end_time:
                end_time = end_time.replace(
                    " ",
                    "T").replace(
                    "'",
                    "").replace(
                    '"',
                    '')

            dimensions['t'] = {"type": "temporal",
                               "extent": [start_time, end_time]
                               }

            extent = CollectionExtent(
                spatial=(
                    float(
                        layer_data["west"]), float(
                        layer_data["south"]), float(
                        layer_data["east"]), float(
                        layer_data["north"])), temporal=(
                            start_time, end_time))

            if "semantic_labels" in layer_data:
                bandlist = layer_data["semantic_labels"].split(',')
                dimensions['bands'] = {"type": "bands",
                                       "values": bandlist
                                       }
                for bandname in bandlist:
                    # not so nice, better use different name and common_name
                    # waiting for GRASS GIS
                    bands.append(EOBands(name=bandname, common_name=bandname))

                # get platform and sensor
                # see
                # https://github.com/radiantearth/stac-spec/blob/master/item-spec/common-metadata.md#platform
                # https://github.com/radiantearth/stac-spec/blob/master/item-spec/common-metadata.md#instruments
                if "_" in bandlist[0]:
                    sensor_abbr = bandlist[0].split('_')[0]
                    if sensor_abbr == "L5":
                        platform = "landsat-5"
                        instrument = "tm, mss"
                    elif sensor_abbr == "L7":
                        platform = "landsat-7"
                        instrument = "etm+"
                    elif sensor_abbr == "L8":
                        platform = "landsat-8"
                        instrument = "oli, trs"
                    elif sensor_abbr == "S1":
                        platform = "sentinel-1"
                        instrument = "c-sar"
                    elif sensor_abbr == "S2":
                        platform = "sentinel-2"
                        instrument = "msi"

        if datatype.lower() == "vector":
            title = "Vector dataset"

        description = "GRASS GIS location/mapset path: /%s/%s" % (
            location, mapset)
        crs = mapset_info["projection"]

        coordinate_transform_extent_to_EPSG_4326(crs=crs, extent=extent)

        # GRASS / actinia do not yet report platform and instrument
        properties = (CollectionProperties(eo_platform=platform,
                                           eo_instrument=instrument,
                                           eo_bands=bands))

        ci = CollectionInformation(id=name, title=title,
                                   description=description,
                                   extent=extent,
                                   properties=properties,
                                   dimensions=dimensions)

        return ci.as_response(http_status=200)
Exemple #3
0
class CollectionInformationResource(Resource):
    def __init__(self):
        self.iface = ActiniaInterface()

    def get(self, name):

        # List strds maps from the GRASS location
        location, mapset, datatype, layer = self.iface.layer_def_to_components(
            name)

        status_code, layer_data = self.iface.layer_info(layer_name=name)
        if status_code != 200:
            return make_response(
                jsonify(
                    {
                        "description":
                        "An internal error occurred "
                        "while catching GRASS GIS layer information "
                        "for layer <%s>!\n Error: %s"
                        "" % (name, str(layer_data))
                    }, 400))

        # Get the projection from the GRASS mapset
        status_code, mapset_info = self.iface.mapset_info(location=location,
                                                          mapset=mapset)
        if status_code != 200:
            return make_response(
                jsonify(
                    {
                        "description":
                        "An internal error occurred "
                        "while catching mapset info "
                        "for mapset <%s>!" % mapset
                    }, 400))

        extent = Extent(spatial=(float(layer_data["west"]),
                                 float(layer_data["south"]),
                                 float(layer_data["east"]),
                                 float(layer_data["north"])))

        title = "Raster dataset"
        if datatype.lower() == "strds":
            title = "Space time raster dataset"
            extent = Extent(spatial=(float(layer_data["west"]),
                                     float(layer_data["south"]),
                                     float(layer_data["east"]),
                                     float(layer_data["north"])),
                            temporal=(layer_data["start_time"],
                                      layer_data["end_time"]))
        if datatype.lower() == "vector":
            title = "Vector dataset"

        description = "GRASS GIS location/mapset path: /%s/%s" % (location,
                                                                  mapset)
        crs = mapset_info["projection"]

        coorindate_transform_extent_to_EPSG_4326(crs=crs, extent=extent)

        ci = CollectionInformation(name=name,
                                   title=title,
                                   description=description,
                                   extent=extent)

        return make_response(ci.to_json(), 200)