diff --git a/src/mapfile.py b/src/mapfile.py index dbe4ecf490c1e9c25999c240b15f0f8f373c4029..83ad13125ed97fcc3748794eb6bec8df4d9f151b 100644 --- a/src/mapfile.py +++ b/src/mapfile.py @@ -698,6 +698,99 @@ class MapfileWorkspace(Workspace): raise ValueError("Bad storage type '%s'." % s_type) +def create_mapfile(path, map_name, data): + if os.path.exists("%s.map" % path): + raise KeyExists(map_name) + + mf = mapscript.mapObj() + mf.name = map_name + + # The following could be defined in <mapfile.py>: + + mf.web.metadata.set("ows_name", map_name) + mf.web.metadata.set("ows_title", data.get("title", map_name)) + mf.web.metadata.set("ows_abstract", data.get("abstract", "")) + + # Set default values: + # It should be configurable to the future. + + # mf.web.metadata.set("ows_keywordlist", "") + # mf.web.metadata.set("ows_keywordlist_vocabulary", "") + # + ows_keywordlist_[vocabulary’s name]_items + # mf.web.metadata.set("wms_onlineresource", "") + # mf.web.metadata.set("wfs_onlineresource", "") + # mf.web.metadata.set("wms_service_onlineresource", "") + # mf.web.metadata.set("wfs_service_onlineresource", "") + mf.web.metadata.set("wms_srs", "EPSG:4326") + mf.web.metadata.set("wfs_srs", "EPSG:4326") + mf.web.metadata.set("wms_bbox_extended", "true") + # mf.web.metadata.set("wms_resx", "") + # mf.web.metadata.set("wms_resy", "") + + mf.web.metadata.set("ows_schemas_location", + "http://schemas.opengeospatial.net") + mf.web.metadata.set("ows_updatesequence", "foo") + mf.web.metadata.set("ows_addresstype", "foo") + mf.web.metadata.set("ows_address", "foo") + mf.web.metadata.set("ows_city", "foo") + mf.web.metadata.set("ows_stateorprovince", "foo") + mf.web.metadata.set("ows_postcode", "foo") + mf.web.metadata.set("ows_contactperson", "foo") + mf.web.metadata.set("ows_contactposition", "foo") + mf.web.metadata.set("ows_contactorganization", "foo") + mf.web.metadata.set("ows_contactelectronicmailaddress", "foo") + mf.web.metadata.set("ows_contactfacsimiletelephone", "foo") + mf.web.metadata.set("ows_contactvoicetelephone", "foo") + mf.web.metadata.set("wms_fees", "none") + mf.web.metadata.set("wfs_fees", "none") + mf.web.metadata.set("wms_accessconstraints", "none") + mf.web.metadata.set("wfs_accessconstraints", "none") + # mf.web.metadata.set("ows_attribution_logourl_format", "") + # mf.web.metadata.set("ows_attribution_logourl_height", "") + # mf.web.metadata.set("ows_attribution_logourl_href", "") + # mf.web.metadata.set("ows_attribution_logourl_width", "") + # mf.web.metadata.set("ows_attribution_onlineresource", "") + # mf.web.metadata.set("ows_attribution_title", "") + + mf.web.metadata.set("wms_enable_request", + "GetCapabilities GetMap GetFeatureInfo GetLegendGraphic") + mf.web.metadata.set("wfs_enable_request", + "GetCapabilities DescribeFeatureType GetFeature") + mf.web.metadata.set("ows_sld_enabled", "true") + mf.web.metadata.set("wms_getcapabilities_version", "1.3.0") + mf.web.metadata.set("wfs_getcapabilities_version", "1.0.0") + # mf.web.metadata.set("wms_getmap_formatlist", "") + # mf.web.metadata.set("wms_getlegendgraphic_formatlist", "") + mf.web.metadata.set("wms_feature_info_mime_type", + "application/vnd.ogc.gml,text/plain") + # TODO: text/html + mf.web.metadata.set("wms_encoding", "UTF-8") + mf.web.metadata.set("wfs_encoding", "UTF-8") + + # mf.web.metadata.set("wms_timeformat", "") + # mf.web.metadata.set("wms_languages", "") + # mf.web.metadata.set("wms_layerlimit", "") + # mf.web.metadata.set("wms_rootlayer_abstract", "") + # mf.web.metadata.set("wms_rootlayer_keywordlist", "") + # mf.web.metadata.set("wms_rootlayer_title", "") + # mf.web.metadata.set("wfs_maxfeatures", "") + # mf.web.metadata.set("wfs_feature_collection", "") + # mf.web.metadata.set("wfs_namespace_uri", "") + # mf.web.metadata.set("wfs_namespace_prefix", "") + + mf.status = mapscript.MS_ON + mf.setSize(256,256) + mf.maxsize = 4096 + mf.resolution = 96 + mf.imagetype = 'png' + mf.imagecolor.setRGB(255,255,255) + mf.setProjection("init=epsg:4326") + mf.setExtent(-180,-90,180,90) + mf.units = mapscript.MS_DD + + mf.save("%s.map" % path) + + class Mapfile(MetadataMixin): """ """ diff --git a/src/maptools.py b/src/maptools.py deleted file mode 100644 index 23b5e0ea24456d89bb0beafe09a2761ee9c0e285..0000000000000000000000000000000000000000 --- a/src/maptools.py +++ /dev/null @@ -1,123 +0,0 @@ -#!/usr/bin/env python2.7 -# -*- coding: utf-8 -*- - -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # -# MapServer REST API is a python wrapper around MapServer which # -# allows to manipulate a mapfile in a RESTFul way. It has been # -# developped to match as close as possible the way the GeoServer # -# REST API acts. # -# # -# Copyright (C) 2011-2013 Neogeo Technologies. # -# # -# This file is part of MapServer Rest API. # -# # -# MapServer Rest API is free software: you can redistribute it # -# and/or modify it under the terms of the GNU General Public License # -# as published by the Free Software Foundation, either version 3 of # -# the License, or (at your option) any later version. # -# # -# MapServer Rest API is distributed in the hope that it will be # -# useful, but WITHOUT ANY WARRANTY; without even the implied warranty # -# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # - -from webapp import KeyExists -import metadata - -import mapscript -import os.path - -def create_mapfile(path, map_name, data): - if os.path.exists("%s.map" % path): - raise KeyExists(map_name) - - mf = mapscript.mapObj() - mf.name = map_name - - # The following could be defined in <mapfile.py>: - - mf.web.metadata.set("ows_name", map_name) - mf.web.metadata.set("ows_title", data.get("title", map_name)) - mf.web.metadata.set("ows_abstract", data.get("abstract", "")) - - # Set default values: - # It should be configurable to the future. - - # mf.web.metadata.set("ows_keywordlist", "") - # mf.web.metadata.set("ows_keywordlist_vocabulary", "") - # + ows_keywordlist_[vocabulary’s name]_items - # mf.web.metadata.set("wms_onlineresource", "") - # mf.web.metadata.set("wfs_onlineresource", "") - # mf.web.metadata.set("wms_service_onlineresource", "") - # mf.web.metadata.set("wfs_service_onlineresource", "") - mf.web.metadata.set("wms_srs", "EPSG:4326") - mf.web.metadata.set("wfs_srs", "EPSG:4326") - mf.web.metadata.set("wms_bbox_extended", "true") - # mf.web.metadata.set("wms_resx", "") - # mf.web.metadata.set("wms_resy", "") - - mf.web.metadata.set("ows_schemas_location", - "http://schemas.opengeospatial.net") - mf.web.metadata.set("ows_updatesequence", "foo") - mf.web.metadata.set("ows_addresstype", "foo") - mf.web.metadata.set("ows_address", "foo") - mf.web.metadata.set("ows_city", "foo") - mf.web.metadata.set("ows_stateorprovince", "foo") - mf.web.metadata.set("ows_postcode", "foo") - mf.web.metadata.set("ows_contactperson", "foo") - mf.web.metadata.set("ows_contactposition", "foo") - mf.web.metadata.set("ows_contactorganization", "foo") - mf.web.metadata.set("ows_contactelectronicmailaddress", "foo") - mf.web.metadata.set("ows_contactfacsimiletelephone", "foo") - mf.web.metadata.set("ows_contactvoicetelephone", "foo") - mf.web.metadata.set("wms_fees", "none") - mf.web.metadata.set("wfs_fees", "none") - mf.web.metadata.set("wms_accessconstraints", "none") - mf.web.metadata.set("wfs_accessconstraints", "none") - # mf.web.metadata.set("ows_attribution_logourl_format", "") - # mf.web.metadata.set("ows_attribution_logourl_height", "") - # mf.web.metadata.set("ows_attribution_logourl_href", "") - # mf.web.metadata.set("ows_attribution_logourl_width", "") - # mf.web.metadata.set("ows_attribution_onlineresource", "") - # mf.web.metadata.set("ows_attribution_title", "") - - mf.web.metadata.set("wms_enable_request", - "GetCapabilities GetMap GetFeatureInfo GetLegendGraphic") - mf.web.metadata.set("wfs_enable_request", - "GetCapabilities DescribeFeatureType GetFeature") - mf.web.metadata.set("ows_sld_enabled", "true") - mf.web.metadata.set("wms_getcapabilities_version", "1.3.0") - mf.web.metadata.set("wfs_getcapabilities_version", "1.0.0") - # mf.web.metadata.set("wms_getmap_formatlist", "") - # mf.web.metadata.set("wms_getlegendgraphic_formatlist", "") - mf.web.metadata.set("wms_feature_info_mime_type", - "application/vnd.ogc.gml,text/plain") - # TODO: text/html - mf.web.metadata.set("wms_encoding", "UTF-8") - mf.web.metadata.set("wfs_encoding", "UTF-8") - - # mf.web.metadata.set("wms_timeformat", "") - # mf.web.metadata.set("wms_languages", "") - # mf.web.metadata.set("wms_layerlimit", "") - # mf.web.metadata.set("wms_rootlayer_abstract", "") - # mf.web.metadata.set("wms_rootlayer_keywordlist", "") - # mf.web.metadata.set("wms_rootlayer_title", "") - # mf.web.metadata.set("wfs_maxfeatures", "") - # mf.web.metadata.set("wfs_feature_collection", "") - # mf.web.metadata.set("wfs_namespace_uri", "") - # mf.web.metadata.set("wfs_namespace_prefix", "") - - mf.status = mapscript.MS_ON - mf.setSize(256,256) - mf.maxsize = 4096 - mf.resolution = 96 - mf.imagetype = 'png' - mf.imagecolor.setRGB(255,255,255) - mf.setProjection("init=epsg:4326") - mf.setExtent(-180,-90,180,90) - mf.units = mapscript.MS_DD - - mf.save("%s.map" % path) diff --git a/src/server.py b/src/server.py index de4ff1cdb7c16d1a7ff8580a78ff6af3725e5d31..87e6b8b069b0a29a8e1be595e7ceb0ed8ab67ef9 100755 --- a/src/server.py +++ b/src/server.py @@ -79,7 +79,7 @@ class mapfiles(object): path = tools.mk_mapfile_path(map_name) with webapp.mightConflict(message="Mapfile '{exception}' already exists."): - maptools.create_mapfile(path, map_name, data) + mapfile.create_mapfile(path, map_name, data) webapp.Created("%s/maps/%s%s" % (web.ctx.home, map_name, (".%s" % format) if format else ""))