Example #1
0
    def POST(self, map_name, l_name, format):
        data = get_data(name="style", mandatory=["resource"],
                        authorized=["name", "title", "abstract", "resource"])

        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 (%s) is not handled by MRA." % url.path)

        try:
            _, map_name, _, s_name = path.rsplit("/", 3)
        except ValueError:
            raise webapp.NotFound(message="ressource '%s' was not found." % path)

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

        # Get the new style.
        mf = get_mapfile(map_name)

        try:
            style = open(tools.get_style_path(s_name)).read()
        except IOError, OSError:
            with webapp.mightNotFound("style", mapfile=map_name):
                style = mf.get_style_sld(s_name)
Example #2
0
 def GET(self, map_name, format, *args, **kwargs):
     mf = get_mapfile(map_name)
     return {"workspaces": [{
                 "name": ws.name,
                 "href": "%s/maps/%s/workspaces/%s.%s" % (web.ctx.home, map_name, ws.name, format)
                 } for ws in mf.iter_workspaces()]
             }
Example #3
0
 def DELETE(self, map_name, l_name, s_name, format):
     mf = get_mapfile(map_name)
     with webapp.mightNotFound("layer", mapfile=map_name):
         layer = mf.get_layer(l_name)
     with webapp.mightNotFound("style", layer=l_name):
         layer.remove_style(s_name)
     mf.save()
Example #4
0
 def GET(self, map_name, format):
     mf = get_mapfile(map_name)
     return {"layers": [{
                 "name": layer.ms.name,
                 "href": "%s/maps/%s/layers/%s.%s" % (web.ctx.home, map_name, layer.ms.name, format),
                 } for layer in mf.iter_layers()]
             }
Example #5
0
    def GET(self, map_name, l_name, format):
        mf = get_mapfile(map_name)
        with webapp.mightNotFound("layer", mapfile=map_name):
            layer = mf.get_layer(l_name)

        data_type, store_type = {
            "featuretype": ("featuretype", "datastore"),
            "coverage": ("coverage", "coveragestore")
            }[layer.get_mra_metadata("type")]

        return {"layer" : {
                    "name": l_name,
                    "path": "/", # TODO
                    "type": layer.get_type_name(),
                    "defaultStyle": {
                        "name": layer.ms.classgroup,
                        "href": "%s/maps/%s/styles/%s.%s" % (web.ctx.home, map_name, layer.ms.classgroup, format),
                        },
                    "styles": [{ # TODO: Add attr class="linked-hash-set"
                            "name": s_name,
                            "href": "%s/maps/%s/styles/%s.%s" % (web.ctx.home, map_name, s_name, format),
                            } for s_name in layer.iter_styles()],
                    "resource": { # TODO: Add attr class="featureType|coverage"
                        "name": layer.get_mra_metadata("name"),
                        "href": "%s/maps/%s/workspaces/%s/%ss/%s/%ss/%s.%s" % (
                            web.ctx.home, map_name, layer.get_mra_metadata("workspace"),
                            store_type, layer.get_mra_metadata("storage"), data_type, layer.get_mra_metadata("name"), format),
                        },
                    "enabled": bool(layer.ms.status),
                    "attribution": { # TODO
                        "logoWidth": 0, 
                        "logoHeight": 0,
                        },
                    }
                }
Example #6
0
    def GET(self, map_name, format):
        mf = get_mapfile(map_name)

        return {"layerGroups" : [{
                    "name": lg.name,
                    "href": "%s/maps/%s/layergroups/%s.%s" % (web.ctx.home, map_name, lg.name, format)
                    } for lg in mf.iter_layergroups()]
                }
Example #7
0
    def GET(self, map_name, format):
        mf = get_mapfile(map_name)

        return {"styles": [{
                    "name": os.path.basename(os.path.basename(s_name)),
                    "href": "%s/maps/%s/styles/%s.%s" % (web.ctx.home, map_name, os.path.basename(s_name), format)
                    } for s_name in tools.iter_styles(mf)]
                }
Example #8
0
    def GET(self, map_name, s_name, format):
        mf = get_mapfile(map_name)

        if format == "sld":
            # We look for styles on disk and in the mapfiles.
            try:
                return open(tools.get_style_path(s_name)).read()
            except IOError, OSError:
                with webapp.mightNotFound("style", mapfile=map_name):
                    return mf.get_style_sld(s_name)
Example #9
0
    def PUT(self, map_name, format):
        mf = get_mapfile(map_name)
        path = tools.mk_mapfile_path(map_name)

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

        mf.update(data)
        mf.save()
Example #10
0
    def GET(self, map_name, l_name, format):
        mf = get_mapfile(map_name)
        with webapp.mightNotFound("layer", mapfile=map_name):
            layer = mf.get_layer(l_name)

            return {"fields": [{
                    "name": layer.get_metadata("gml_%s_alias" % field, None),
                    "fieldType": layer.get_metadata("gml_%s_type" % field, None),
                    } for field in layer.iter_fields()]
                }
Example #11
0
    def DELETE(self, map_name, s_name, format):
        mf = get_mapfile(map_name)

        # OK check any(class.group == s_name for class in layer.iter_classes)
        layers_using = [layer.ms.name for layer in mf.iter_layers()
                        if any(clazz.ms.group == s_name for clazz in layer.iter_classes())]

        if layers_using:
            raise webapp.Forbidden(message="Can't remove style '%s' because it is beeing used by the folowing layers: %s."
                                   % (s_name, layers_using))

        path = tools.get_style_path(s_name)
        try:
            os.remove(path)
        except OSError:
            mf = get_mapfile(map_name)
            if s_name in mf.iter_styles():
                raise webapp.NotImplemented(message="Deleting manually added styles is not implemented.")
            else:
                raise webapp.NotFound("style '%s' not found in mapfile '%s'." % (s_name, map_name))
Example #12
0
    def GET(self, map_name, l_name, format):
        mf = get_mapfile(map_name)
        with webapp.mightNotFound("layer", mapfile=map_name):
            layer = mf.get_layer(l_name)

        if format == "sld":
            return layer.getSLD()

        return {"styles": [{
                    "name": s_name,
                    "href": "%s/maps/%s/styles/%s.%s" % (web.ctx.home, map_name, s_name, format),
                    } for s_name in layer.iter_styles()],
                }
Example #13
0
    def POST(self, map_name, format):
        mf = get_mapfile(map_name)

        data = get_data(name="layerGroup", mandatory=["name"], authorized=["name", "title", "abstract", "layers"])
        lg_name = data.pop("name")
        layers = [mf.get_layer(l_name) for l_name in data.pop("layers", [])]

        with webapp.mightConflict("layerGroup", mapfile=map_name):
            lg = mf.create_layergroup(lg_name, data)
        lg.add(*layers)

        mf.save()

        webapp.Created("%s/maps/%s/layergroups/%s%s" % (web.ctx.home, map_name, lg.name, (".%s" % format) if format else ""))
Example #14
0
    def PUT(self, map_name, s_name, format):
        path = tools.get_style_path(s_name)
        try:
            os.remove(path)
        except OSError:
            mf = get_mapfile(map_name)
            if s_name in mf.iter_styles():
                raise webapp.NotImplemented(message="Updating manually added styles is not implemented.")
            else:
                raise webapp.NotFound("style '%s' not found in mapfile '%s'." % (s_name, map_name))

        data = web.data()
        with open(path, "w") as f:
            f.write(data)
Example #15
0
    def POST(self, map_name, format):
        mf = get_mapfile(map_name)

        params = web.input(name=None)
        name = params.name
        if name == None:
            raise webapp.BadRequest(message="no parameter 'name' given.")
        with webapp.mightConflict(message="style {exception} already exists."):
            if name in tools.iter_styles(mf):
                raise webapp.KeyExists(name)

        data = web.data()
        path = tools.mk_style_path(name)

        with open(path, "w") as f:
            f.write(data)
Example #16
0
    def PUT(self, map_name, lg_name, format):
        mf = get_mapfile(map_name)

        with webapp.mightNotFound("layerGroup", mapfile=map_name):
            lg = mf.get_layergroup(lg_name)

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

        layers = data.pop("layers", [])
        if not isinstance(layers, list) or any(not isinstance(x, basestring) for x in layers):
            raise webapp.BadRequest("layers must be a list of layer names.")

        lg.clear()
        lg.add(*layers)

        mf.save()
Example #17
0
    def GET(self, map_name, format, *args, **kwargs):

        mf = get_mapfile(map_name)
        with open(mf.path, "r") as f:
            data = f.read()
        return {"mapfile": ({
                "name": map_name,
                "href": "%s/maps/%s.map" % (web.ctx.home, map_name),
                "workspaces": href("%s/maps/%s/workspaces.%s" % (web.ctx.home, map_name, format)),
                "layers": href("%s/maps/%s/layers.%s" % (web.ctx.home, map_name, format)),
                "layergroups": href("%s/maps/%s/layergroups.%s" % (web.ctx.home, map_name, format)),
                "styles": href("%s/maps/%s/styles.%s" % (web.ctx.home, map_name, format)),
                "wms_capabilities": href("%smap=%s&REQUEST=GetCapabilities&VERSION=%s&SERVICE=WMS" % (
                            get_config("mapserver")["url"], mf.path, get_config("mapserver")["wms_version"])),
                "wfs_capabilities": href("%smap=%s&REQUEST=GetCapabilities&VERSION=%s&SERVICE=WFS" % (
                            get_config("mapserver")["url"], mf.path, get_config("mapserver")["wfs_version"])),
                "wcs_capabilities": href("%smap=%s&REQUEST=GetCapabilities&VERSION=%s&SERVICE=WCS" % (
                            get_config("mapserver")["url"], mf.path, get_config("mapserver")["wcs_version"])),
                    })
            } if format != "map" else data
Example #18
0
    def GET(self, map_name, lg_name, format):
        mf = get_mapfile(map_name)
        with webapp.mightNotFound("layerGroup", mapfile=map_name):
            lg = mf.get_layergroup(lg_name)

        latlon_extent = lg.get_latlon_extent()

        return {"layerGroup": ({
                    "name": lg.name,
                    "mode": None, # TODO
                    "publishables": [{
                            "name": layer.ms.name,
                            "href": "%s/maps/%s/layers/%s.%s" % (web.ctx.home, map_name, layer.ms.name, format),
                            } for layer in lg.iter_layers()],
                    "bounds": {
                        "minx": latlon_extent.minX(),
                        "miny": latlon_extent.minY(),
                        "maxx": latlon_extent.maxX(),
                        "maxy": latlon_extent.maxY(),
                        "crs": "EPSG:4326",
                        },
                    "styles": [],
                    })
                }
Example #19
0
    def PUT(self, map_name, l_name, format):
        mf = get_mapfile(map_name)

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

        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.
        r_href = data["resource"]["href"]
        try:
            _, map_name, _, ws_name, st_type, st_name, r_type, r_name = r_href.rsplit("/", 7)
        except ValueError:
            raise webapp.NotFound(message="ressource '%s' was not found." % r_href)

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

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

        with webapp.mightNotFound("layer", mapfile=map_name):
            layer = mf.get_layer(l_name)

            if layer.get_mra_metadata("type") != r_type:
                raise webapp.BadRequest("Can't change a '%s' layer into a '%s'." % (
                        layer.get_mra_metadata("type"), r_type))

            model.configure_layer(ws, layer, l_enabled)
        mf.save()
Example #20
0
    def DELETE(self, map_name, lg_name, format):

        mf = get_mapfile(map_name)
        with webapp.mightNotFound("layerGroup", mapfile=map_name):
            mf.delete_layergroup(lg_name)
        mf.save()
Example #21
0
    def DELETE(self, map_name, format):
        mf = get_mapfile(map_name)

        # TODO: We need to check if this mapfile is empty.
        with webapp.mightNotFound("Mapfile", mapfile=map_name):
            os.remove(mf.path)