def form_layerGroup(cur, Nlayer): capabilities = "<Layer>\n\t" # Requested tag Name from "Capabilities" # SELECT xpath_nodeset(LayerCapabilites, '/Layer/Name') WHERE Nlayer = Nlayer; res = BD.interset_request(cur, "KnownLayers", "LayerCapabilites",\ "/Layer/Name", "Nlayer", Nlayer) if res: for Name in res: capabilities = capabilities + "%s\n"%Name # Requested tag Title from "Capabilities" # SELECT xpath_nodeset(LayerCapabilites, '/Layer/Title') WHERE Nlayer = Nlayer; res = BD.interset_request(cur, "KnownLayers", "LayerCapabilites",\ "/Layer/Title", "Nlayer", Nlayer) if res: for Title in res: capabilities = capabilities + "%s\n"%Title # Requested tag Abstract from "Capabilities" # SELECT xpath_nodeset(LayerCapabilites, '/Layer/Abstract') WHERE Nlayer = Nlayer; res = BD.interset_request(cur, "KnownLayers", "LayerCapabilites",\ "/Layer/Abstract", "Nlayer", Nlayer) if res: for Abstract in res: capabilities = capabilities + "%s\n"%Abstract # Requested tag KeywordList from "Capabilities" # SELECT xpath_nodeset(LayerCapabilites, '/Layer/KeywordList') WHERE Nlayer = Nlayer; res = BD.interset_request(cur, "KnownLayers", "LayerCapabilites",\ "/Layer/KeywordList", "Nlayer", Nlayer) if res: for KeywordList in res: capabilities = capabilities + "%s\n"%KeywordList return capabilities
def form_layerInfo(cur, layer_id, capabilities): # Requested by the parent layer "parent_id" values = {} values["Nlayer"] = layer_id res = BD.ifselect_table(cur, "KnownLayers", "Nlayer", values, "Nl_group") for Nlayer, parent_id in res: # Requested tag SRS from "Capabilities" # SELECT xpath_nodeset(LayerCapabilites, '/Layer/SRS') WHERE Nlayer = Nlayer; result = BD.interset_request(cur, "KnownLayers", "LayerCapabilites", "/Layer/SRS", "Nlayer", Nlayer) if result: capabilities = insert_tag(result[0][0], capabilities, "<SRS>", "</SRS>", 1) # Requested tag LatLonBoundingBox from "Capabilities" # SELECT xpath_nodeset(LayerCapabilites, '/Layer/LatLonBoundingBox') WHERE Nlayer = Nlayer; result = BD.interset_request(cur, "KnownLayers", "LayerCapabilites", "/Layer/LatLonBoundingBox", "Nlayer", Nlayer) if result: capabilities = insert_tag(result[0][0], capabilities, "<LatLonBoundingBox", "</LatLonBoundingBox>", 0) # Requested tag BoundingBox from "Capabilities" # SELECT xpath_nodeset(LayerCapabilites, '/Layer/BoundingBox') WHERE Nlayer = Nlayer; result = BD.interset_request(cur, "KnownLayers", "LayerCapabilites", "/Layer/BoundingBox", "Nlayer", Nlayer) if result: capabilities = insert_tag(result[0][0], capabilities, "<BoundingBox", "</BoundingBox>", 0) # Requested tag Style from "Capabilities" # SELECT xpath_nodeset(LayerCapabilites, '/Layer/Style') WHERE Nlayer = Nlayer; result = BD.interset_request(cur, "KnownLayers", "LayerCapabilites", "/Layer/Style", "Nlayer", Nlayer) if result: capabilities = insert_tag(result[0][0], capabilities, "<Style>", "</Style>", 1) if parent_id != -1: capabilities = form_layerInfo(cur, parent_id, capabilities) return capabilities
def get_tagRequest(dom, nametag, request_dom, server_URL, cur, list_WMSservers, nameset, needPost): # Create a sub tree with name "nametag" getdom = dom.createElement("%s"%nametag) request_dom.appendChild(getdom) Nwms_used = -1 oldlist_formats = [] count_servers = 0 for server_id in list_WMSservers: # Enumerates all used servers # Check their recurrence if Nwms_used == server_id: continue Nwms_used = server_id # Requested format of the tag with the name "nametag" of the server server_id # SELECT xpath_nodeset(Capabilities, '"//Capability/Request/%s/Format"%nametag') # FROM WMSresources WHERE Nwms = server_id; res = BD.interset_request(cur, "WMSresources", "Capabilites",\ "//Capability/Request/%s/Format"%nametag, "Nwms", server_id) # Stores intersection lists formats result = [] if res: # If there is a format for tag_Format in res: strformat = tag_Format.replace("</Format>", "</Format>\n") if count_servers: # If this is not the first list of formats oldlist_formats = list_formats # The string format is divided into a list list_formats = strformat.split("\n") # Created by the intersection of the lists of formats belonging to two servers for m in oldlist_formats: for j in list_formats: if m == j: result.append(m) break # The result of suppresion of record in the list of formats list_formats = result else: # If this is the first list of formats # The string format is divided into a list list_formats = strformat.split("\n") count_servers += 1 # Formed a string from the list of formats strformat = " " for k in list_formats: strformat = strformat + "%s\n\t"%k # Create tag "Format" format = dom.createTextNode("%s" % strformat) getdom.appendChild(format) DCP = dom.createElement("DCPType") getdom.appendChild(DCP) HTTP = dom.createElement("HTTP") DCP.appendChild(HTTP) Gettag = dom.createElement("Get") HTTP.appendChild(Gettag) Resource = dom.createElement("OnlineResource") Resource.setAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink') Resource.setAttribute('xlink:type', 'simple') Resource.setAttribute('xlink:href', "%s?Set=%s" % (server_URL, nameset)) Gettag.appendChild(Resource) if needPost: Post = dom.createElement("Post") HTTP.appendChild(Post) Resource = dom.createElement("OnlineResource") Resource.setAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink') Resource.setAttribute('xlink:type', 'simple') Resource.setAttribute('xlink:href', "%s?Set=%s&SERVICE=WMS&" % (server_URL, nameset)) Post.appendChild(Resource) return request_dom
def gather_capabilities(Nset, nameSet, cur, set_layers, list_WMSservers, server_URL): # Generated file name name_file = nameSet + ".xml" # Product of an object class Document - dom dom = xml.dom.minidom.Document() # DTD schema takes one of the servers Nwms_dtd = list_WMSservers[0] # create service tag with need information (see Service.py).Return subtree dom tag_service = Service.get_tag(dom, server_URL, nameSet, Nwms_dtd) # create tag Capability. capability = dom.createElement("Capability") tag_service.appendChild(capability) # create tag in Capability: Request request_dom = dom.createElement("Request") capability.appendChild(request_dom) # Formated a tag Request with the intersection of all formats by all used servers request_dom = Service.get_tagRequest(dom, "GetCapabilities", request_dom,\ server_URL, cur, list_WMSservers, nameSet, 0) request_dom = Service.get_tagRequest(dom, "GetMap", request_dom, server_URL,\ cur, list_WMSservers, nameSet, 0) request_dom = Service.get_tagRequest(dom, "GetFeatureInfo", request_dom, \ server_URL, cur, list_WMSservers, nameSet, 0) request_dom = Service.get_tagRequest(dom, "DescribeLayer", request_dom, \ server_URL, cur, list_WMSservers, nameSet, 0) request_dom = Service.get_tagRequest(dom, "GetLegendGraphic", request_dom, \ server_URL, cur, list_WMSservers, nameSet, 0) Nwms_used = -1 count_servers = 0 oldlist_formats = [] for server_id in list_WMSservers: # Enumerates all used servers # Check their recurrence if Nwms_used == server_id: continue Nwms_used = server_id # Requested format of the tag with the name "Exception" of the server server_id # SELECT xpath_nodeset(Capabilites, '"//Capability/Exception/Format"') # FROM WMSresources # WHERE Nwms = server_id; res = BD.interset_request(cur, "WMSresources", "Capabilites",\ "//Capability/Exception/Format", "Nwms", server_id) # Stores intersection list formats result = [] if res: # If there is a format for tagFormat in res: strformat = tagFormat.replace("</Format>", "</Format>\n") if count_servers: # This is not the first list of formats oldlist_formats = list_formats # The string format is divided into a list list_formats = strformat.split("\n") # Created by the intersection of the lists of formats belonging to two servers for m in oldlist_formats: for j in list_formats: if m == j: result.append(m) break # The result of suppresion of record in the list of formats list_formats = result else: # This is the first list of formats # The string format is divided into a list list_formats = strformat.split("\n") count_servers += 1 # Formed a string from the list of formats strformat = " " for k in list_formats: strformat = strformat + "%s\n\t"%k # Create tag "Exception" exception = dom.createElement("Exception") capability.appendChild(exception) except_format = dom.createTextNode("%s" % strformat) exception.appendChild(except_format) count_servers = 0 Nwms_used = -1 oldlist_formats = " " for server_id in list_WMSservers: # Enumerates all used servers result = " " # Check their recurrence if Nwms_used == server_id: continue Nwms_used = server_id # Requested format of the tag with the name "Exception" of the server server_id # SELECT xpath_nodeset(Capabilites, '"//Capability/UserDefinedSymbolization"') # FROM WMSresources # WHERE Nwms = server_id; res = BD.interset_request(cur, "WMSresources", "Capabilites",\ "//Capability/UserDefinedSymbolization",\ "Nwms", server_id) if res: # If there is a UserDefinedSymbolization for tagSymbolization in res: if count_servers: # This is not the first string UserDefinedSymbolization oldlist_formats = list_formats list_formats = tagSymbolization if oldlist_formats == list_formats: result = list_formats else: list_formats = tagSymbolization count_servers += 1 list_formats = result # Create tag UserDefinedSymbolization symb = dom.createTextNode("%s" % list_formats) capability.appendChild(symb) # External layer - layer containing all the layers set external_Layer = dom.createElement("Layer") capability.appendChild(external_Layer) Name_exLayer = dom.createElement("Name") Name_exLayer.appendChild(dom.createTextNode("%s"%nameSet)) external_Layer.appendChild(Name_exLayer) Title_exLayer = dom.createElement("Title") Title_exLayer.appendChild(dom.createTextNode("WMS Resource Manager of SB RAS")) external_Layer.appendChild(Title_exLayer) # Requested a list of layers which don't display in "Capabilities" tables = [] keywords = {} tables.append("AuthorsSets.layer_noset") keywords["AuthorsSets.Nset"] = Nset res = BD.ifsome_tables(cur, tables, keywords, "AuthorsSets") if res: list_layernoset = res[0][0] else: list_layernoset = "" # For all layers of the set for Nlayer, Nwms in set_layers.items(): # Checking whether to display the layer in "Capabilities" place_instr = list_layernoset.find("%d"%Nlayer + ";") if (place_instr != -1): if ((place_instr != 0 and (list_layernoset[place_instr-1:place_instr])!='_') or (place_instr == 0)): # If the layer is not necessary to display, then its inner layers too continue; # Requested by the parent layer, a list of internal layers and Capabilities. tables = [] keywords = {} tables.append("KnownLayers.Nl_group") tables.append("KnownLayers.LayerCapabilites") tables.append("SetLayer.sub_group") keywords["KnownLayers.Nwms"] = Nwms keywords["SetLayer.Nlayer"] = Nlayer keywords["KnownLayers.Nlayer"] = "SetLayer.Nlayer" keywords["SetLayer.Nset"] = Nset res = BD.ifsome_tables(cur, tables, keywords, "KnownLayers", "SetLayer") for parent_id, capabilities, subgroup_layers in res: if not subgroup_layers: # If there is no internal layers capabilities = form_layer(capabilities, Nlayer, server_URL) if parent_id != -1: # If the layer has a parent capabilities = form_layerInfo(cur, parent_id, capabilities) else: # Another group is formed from layer capabilities = form_layerGroup(cur, Nlayer) # Is the formation of sublayers capabilities = form_sublayers(cur, Nwms, subgroup_layers, capabilities,\ server_URL, list_layernoset, Nlayer) capabilities = capabilities + "</Layer>\t" # Create new node "Layer" text = dom.createTextNode("%s" % capabilities) external_Layer.appendChild(text) # transform tree in string texts = tag_service.toprettyxml(indent=' ', newl='\n') # transform psevdo codes in symbols texts = texts.replace("<", "<") texts = texts.replace(">", ">") texts = texts.replace(""", "\"") texts = texts.replace("&amp;", "&") print texts