Exemplo n.º 1
0
    def GET(self, map_name, ws_name, cs_name, format):
        mf, ws = get_mapfile_workspace(map_name, ws_name)

        with webapp.mightNotFound("coverageStore", workspace=ws_name):
            info = ws.get_coveragestore_info(cs_name)

        return {"coverageStore": {
                    "name": info["name"],
                    "type": None, # TODO
                    "enabled": True, # TODO
                    "__default": False, # TODO
                    "workspace": {
                        "name": ws.name,
                        "href": "%s/maps/%s/workspaces/%s.%s" % (
                            web.ctx.home, map_name, ws.name, format),
                        },
                    "coverages": href("%s/maps/%s/workspaces/%s/coveragestores/%s/coverages.%s" % (
                                    web.ctx.home, map_name, ws.name, cs_name, format)
                        ),
                    "connectionParameters": Entries({
                        "url": info["connectionParameters"]["url"],
                        "namespace": None, # TODO
                        }, tag_name="entry")
                    }
                }
Exemplo n.º 2
0
    def POST(self, map_name, format):
        data = get_data(name="layer",
                        mandatory=["name", "resource"],
                        authorized=["name", "title", "abstract", "resource", "enabled"])

        l_name = data.pop("name")
        l_enabled = data.pop("enabled", True)

        # This means we can have one mapfile for each workspace
        # and if eveything uses urls it should work *almost* as is.
        url = urlparse.urlparse(data["resource"]["href"])
        if url.path.startswith(web.ctx.homepath):
            path = url.path[len(web.ctx.homepath):]
        else:
            raise webapp.BadRequest(message="Resource href is not handled by MRA.")

        try:
            _, map_name, _, ws_name, st_type, st_name, r_type, r_name = path.rsplit("/", 7)
        except ValueError:
            raise webapp.NotFound(message="ressource '%s' was not found." % path)

        r_name = r_name.rsplit(".", 1)[0]

        mf, ws = get_mapfile_workspace(map_name, ws_name)
        with webapp.mightNotFound(r_type, workspace=ws_name):
            try:
                model = ws.get_model(r_name, r_type[:-1], st_name)
            except ValueError:
                webapp.NotFound("Invalid layer model '%s'" % r_type[:-1])

        with webapp.mightConflict("layer", mapfile=map_name):
            mf.create_layer(ws, model, l_name, l_enabled)
        mf.save()

        webapp.Created("%s/maps/%s/layers/%s%s" % (web.ctx.home, map_name, l_name, (".%s" % format) if format else ""))
Exemplo n.º 3
0
 def GET(self, map_name, ws_name, cs_name, format):
     mf, ws = get_mapfile_workspace(map_name, ws_name)
     return {"coverages": [{
                 "name": c.name,
                 "href": "%s/maps/%s/workspaces/%s/coveragestores/%s/coverages/%s.%s" % (
                     web.ctx.home, map_name, ws.name, cs_name, c.name, format)
                 } for c in ws.iter_coveragemodels(cs_name)]
             }
Exemplo n.º 4
0
 def GET(self, map_name, ws_name, ds_name, format):
     mf, ws = get_mapfile_workspace(map_name, ws_name)
     return {"featureTypes": [{
                 "name": ft.name,
                 "href": "%s/maps/%s/workspaces/%s/datastores/%s/featuretypes/%s.%s" % (
                     web.ctx.home, map_name, ws.name, ds_name, ft.name, format)
                 } for ft in ws.iter_featuretypemodels(ds_name)]
             }
Exemplo n.º 5
0
 def GET(self, map_name, ws_name, format, *args, **kwargs):
     mf, ws = get_mapfile_workspace(map_name, ws_name)
     return {"dataStores": [{
                 "name": ds_name,
                 "href": "%s/maps/%s/workspaces/%s/datastores/%s.%s" % (
                     web.ctx.home, map_name, ws.name, ds_name, format)
                 } for ds_name in ws.iter_datastore_names()]
             }
Exemplo n.º 6
0
    def DELETE(self, map_name, ws_name, ds_name, ft_name, format):
        mf, ws = get_mapfile_workspace(map_name, ws_name)

        # We need to check if there are any layers using this.
        assert_is_empty(mf.iter_layers(mra={"name":ft_name, "workspace":ws_name, "storage":ds_name, "type":"featuretype"}),"featuretype", ft_name)

        with webapp.mightNotFound("featureType", datastore=ds_name):
            ws.delete_featuretypemodel(ft_name, ds_name)
        ws.save()
Exemplo n.º 7
0
    def DELETE(self, map_name, ws_name, cs_name, format):
        mf, ws = get_mapfile_workspace(map_name, ws_name)

        # We need to check if this datatore is empty.
        assert_is_empty(ws.iter_coverages(cs_name=cs_name), "coveragestore", ds_name)

        with webapp.mightNotFound("coverageStore", workspace=ws_name):
            ws.delete_coveragestore(cs_name)
        ws.save()
Exemplo n.º 8
0
    def PUT(self, map_name, ws_name, st_type, st_name, f_type, format):
        import zipfile

        mf, ws = get_mapfile_workspace(map_name, ws_name)

        # TODO: According to geoserv's examples we might have to handle
        # directories as well as files, in that case we want to upload
        # all the files from the directory.

        # Lets first try to get the file.
        if f_type == "file":
            # Check if zip or not...
            data = web.data()
        elif f_type == "url":
            raise NotImplemented()
        elif f_type == "external":
            raise NotImplemented()

        # Now we make sure the store exists.
        with webapp.mightNotFound(message="Store {exception} does not exist "
                                  "and automatic creation is not yet suported."):
            ws.get_store_info(st_type, st_name)
            # TODO: Create the store if it does not exist.

        # Then we store the file.
        ext = web.ctx.env.get('CONTENT_TYPE', '').split("/")[-1]
        path = tools.mk_st_data_path(ws_name, st_type, st_name, st_name + (".%s" % ext) if ext else "")
        with open(path, "w") as f:
            f.write(data)

        # We also unzip it if its ziped.
        ctype = web.ctx.env.get('CONTENT_TYPE', None)
        if ctype == "application/zip":
            z = zipfile.ZipFile(path)
            for f in z.namelist():
                fp = tools.mk_st_data_path(ws_name, st_type, st_name, f)

                # If the file has the correct target we might want it.
                if format and fp.endswith(format) and not tools.is_hidden(fp):
                    path = fp

                z.extract(f, path=tools.get_st_data_path(ws_name, st_type, st_name))

        # Set new connection parameters:
        ws.update_store(st_type, st_name, {"connectionParameters":{"url":"file:"+tools.no_res_root(path)}})
        ws.save()

        # Finally we might have to configure it.
        params = web.input(configure="none")
        if params.configure == "first":
            raise NotImplemented()
        elif params.configure == "none":
            pass
        elif params.configure == "all":
            raise NotImplemented()
        else:
            raise webapp.BadRequest(message="configure must be one of first, none or all.")
Exemplo n.º 9
0
    def DELETE(self, map_name, ws_name, ds_name, format):
        mf, ws = get_mapfile_workspace(map_name, ws_name)

        # We need to check if this datatore is empty.
        assert_is_empty(ws.iter_featuretypemodels(ds_name=ds_name), "datastore", ds_name)

        with webapp.mightNotFound("dataStore", workspace=ws_name):
            ws.delete_datastore(ds_name)
        ws.save()
Exemplo n.º 10
0
    def PUT(self, map_name, ws_name, cs_name, format):
        mf, ws = get_mapfile_workspace(map_name, ws_name)

        data = get_data(name="coverageStore", mandatory=["name"], authorized=["name", "title", "abstract", "connectionParameters"])
        if cs_name != data.pop("name"):
            raise webapp.Forbidden("Can't change the name of a coverage store.")

        with webapp.mightNotFound("coverageStore", workspace=ws_name):
            ws.update_coveragestore(cs_name, data)
        ws.save()
Exemplo n.º 11
0
    def DELETE(self, map_name, ws_name, cs_name, c_name, format):
        mf, ws = get_mapfile_workspace(map_name, ws_name)

        # We need to check if there are any layers using this.
        assert_is_empty(mf.iter_layers(mra={"name":c_name, "workspace":ws_name, "storage":cs_name, "type":"coverage"}),
                        "coverage", ft_name)

        with webapp.mightNotFound("coverage", coveragestore=cs_name):
            ws.delete_coveragemodel(c_name, cs_name)
        ws.save()
Exemplo n.º 12
0
    def GET(self, map_name, ws_name, ds_name, ft_name, format):
        mf, ws = get_mapfile_workspace(map_name, ws_name)

        ds = ws.get_datastore(ds_name)
        with webapp.mightNotFound("dataStore", datastore=ds_name):
            dsft = ds[ft_name]

        with webapp.mightNotFound("featureType", datastore=ds_name):
            ft = ws.get_featuretypemodel(ft_name, ds_name)

        extent = ft.get_extent()
        latlon_extent = ft.get_latlon_extent()

        return {"featureType": ({
                    "name": ft.name,
                    "nativeName": ft.name,
                    "namespace": None, # TODO
                    "title": ft.get_mra_metadata("title", ft.name),
                    "abstract": ft.get_mra_metadata("abstract", None),
                    "keywords": ft.get_mra_metadata("keywords", []),
                    "srs": "%s:%s" % (ft.get_authority()[0], ft.get_authority()[1]),
                    "nativeCRS": ft.get_wkt(),
                    "attributes": [{
                            "name": f.get_name(),
                            "minOccurs": 0 if f.is_nullable() else 1,
                            "maxOccurs": 1,
                            "nillable": f.is_nullable(),
                            "binding": f.get_type_name(),
                            "length": f.get_width(),
                            } for f in dsft.iterfields()],
                    "nativeBoundingBox": {
                        "minx": extent.minX(),
                        "miny": extent.minY(),
                        "maxx": extent.maxX(),
                        "maxy": extent.maxY(),
                        "crs": "%s:%s" % (ft.get_authority_name(), ft.get_authority_code()),
                        },
                    "latLonBoundingBox": {
                        "minx": latlon_extent.minX(),
                        "miny": latlon_extent.minY(),
                        "maxx": latlon_extent.maxX(),
                        "maxy": latlon_extent.maxY(),
                        "crs": "EPSG:4326",
                        },
                    "projectionPolicy": None, # TODO
                    "enabled": True, # TODO
                    "store": { # TODO: add key: class="dataStore"
                        "name": ds_name,
                        "href": "%s/maps/%s/workspaces/%s/datastores/%s.%s" % (
                            web.ctx.home, map_name, ws_name, ds_name, format)
                        },
                    "maxFeatures": 0, # TODO
                    "numDecimals": 0, # TODO
                    })
                }
Exemplo n.º 13
0
 def GET(self, map_name, ws_name, format):
     mf, ws = get_mapfile_workspace(map_name, ws_name)
     return {"workspace": ({
                 "name": ws.name,
                 "dataStores":
                     href("%s/maps/%s/workspaces/%s/datastores.%s" % (web.ctx.home, map_name, ws.name, format)),
                 "coverageStores":
                     href("%s/maps/%s/workspaces/%s/coveragestores.%s" % (web.ctx.home, map_name, ws.name, format)),
                 "wmsStores": "", # TODO
                 })
             }
Exemplo n.º 14
0
    def POST(self, map_name, ws_name, ds_name, format):
        mf, ws = get_mapfile_workspace(map_name, ws_name)

        data = get_data(name="featureType", mandatory=["name"], authorized=["name", "title", "abstract"])
        with webapp.mightConflict("featureType", datastore=ds_name):
            with webapp.mightNotFound("featureType", datastore=ds_name):
                ws.create_featuretypemodel(data["name"], ds_name, data)
        ws.save()

        webapp.Created("%s/maps/%s/workspaces/%s/datastores/%s/featuretypes/%s%s" % (
                web.ctx.home, map_name, ws.name, ds_name, data["name"], (".%s" % format) if format else ""))
Exemplo n.º 15
0
    def POST(self, map_name, ws_name, cs_name, format):
        mf, ws = get_mapfile_workspace(map_name, ws_name)

        data = get_data(name="coverage", mandatory=["name"], authorized=["name", "title", "abstract"])

        with webapp.mightConflict("coverage", coveragestore=cs_name):
            ws.create_coveragemodel(data["name"], cs_name, data)
        ws.save()

        webapp.Created("%s/maps/%s/workspaces/%s/coveragestores/%s/coverages/%s%s" % (
                web.ctx.home, map_name, ws.name, cs_name, data["name"], (".%s" % format) if format else ""))
Exemplo n.º 16
0
    def PUT(self, map_name, ws_name, ds_name, ft_name, format):
        mf, ws = get_mapfile_workspace(map_name, ws_name)

        data = get_data(name="featureType", mandatory=["name"], authorized=["name", "title", "abstract"])
        if ft_name != data["name"]:
            raise webapp.Forbidden("Can't change the name of a feature type.")

        metadata = dict((k, v) for k, v in data.iteritems() if k in ["title", "abstract"])

        with webapp.mightNotFound("featureType", datastore=ds_name):
            ws.update_featuretypemodel(ft_name, ds_name, metadata)
        ws.save()
Exemplo n.º 17
0
    def POST(self, map_name, ws_name, format):
        mf, ws = get_mapfile_workspace(map_name, ws_name)

        data = get_data(name="coverageStore", mandatory=["name"], authorized=["name", "title", "abstract", "connectionParameters"])
        cs_name = data.pop("name")

        with webapp.mightConflict("coverageStore", workspace=ws_name):
            ws.create_coveragestore(cs_name, data)
        ws.save()

        webapp.Created("%s/maps/%s/workspaces/%s/coveragestores/%s%s" % (
                web.ctx.home, map_name, ws_name, cs_name, (".%s" % format) if format else ""))
Exemplo n.º 18
0
    def PUT(self, map_name, ws_name, cs_name, c_name, format):
        mf, ws = get_mapfile_workspace(map_name, ws_name)

        data = get_data(name="coverage", mandatory=["name"], authorized=["name", "title", "abstract"])
        if c_name != data["name"]:
            raise webapp.Forbidden("Can't change the name of a coverage.")


        metadata = dict((k, v) for k, v in data.iteritems() if k in ["title", "abstract"])

        with webapp.mightNotFound("coverage", coveragestore=cs_name):
            ws.update_coveragemodel(c_name, cs_name, metadata)
        ws.save()
Exemplo n.º 19
0
    def GET(self, map_name, ws_name, cs_name, c_name, format):
        mf, ws = get_mapfile_workspace(map_name, ws_name)

        # with webapp.mightNotFound("coveragestore", workspace=ws_name):
        #     cs = ws.get_coveragestore(cs_name)

        with webapp.mightNotFound("coverage", coveragestore=cs_name):
            c = ws.get_coveragemodel(c_name, cs_name)

        extent = c.get_extent()
        latlon_extent = c.get_latlon_extent()

        return {"coverage": ({
                    "name": c.name,
                    "nativeName": c.name,
                    "namespace": None, # TODO
                    "title": c.get_mra_metadata("title", c.name),
                    "abstract": c.get_mra_metadata("abstract", None),
                    "keywords": c.get_mra_metadata("keywords", []),
                    "nativeCRS": c.get_wkt(), # TODO: Add key class="projected" if projected...
                    "srs": "%s:%s" % (c.get_authority_name(), c.get_authority_code()),
                    "nativeBoundingBox": {
                        "minx": extent.minX(),
                        "miny": extent.minY(),
                        "maxx": extent.maxX(),
                        "maxy": extent.maxY(),
                        "crs": "%s:%s" % (c.get_authority_name(), c.get_authority_code()), # TODO: Add key class="projected" if projected...
                        },
                    "latLonBoundingBox":{
                        "minx": latlon_extent.minX(),
                        "miny": latlon_extent.minY(),
                        "maxx": latlon_extent.maxX(),
                        "maxy": latlon_extent.maxY(),
                        "crs": "EPSG:4326"
                        },
                    "enabled": True, # TODO
                    "metadata": None, # TODO
                    "store": { # TODO: Add attr class="coverageStore"
                        "name": cs_name,
                        "href": "%s/maps/%s/workspaces/%s/coveragestores/%s.%s" % (
                            web.ctx.home, map_name, ws_name, cs_name, format)
                        },
                    "nativeFormat": None, # TODO
                    "grid": { # TODO: Add attr dimension
                        "range": {
                            "low": None, # TODO
                            "high": None, # TODO
                            },
                        "transform": {
                            "scaleX": None, # TODO
                            "scaleY": None, # TODO
                            "shearX": None, # TODO
                            "shearY": None, # TODO
                            "translateX": None, # TODO
                            "translateY": None, # TODO
                            },
                        "crs": None,
                        },
                    "supportedFormats": [], # TODO
                    "interpolationMethods": [], # TODO
                    "defaultInterpolationMethod": None,
                    "dimensions": [], # TODO
                    "projectionPolicy": None, # TODO
                    "requestSRS": None, # TODO
                    "responseSRS": None, # TODO
                    })
                }