Пример #1
0
def makeWmsDetailsFile(exportParams):
    """Generates a WMS export containing the URLs for the map, capabilities and legend for the current map.
    """

    # Create the export XML file.
    domImpl = xml.dom.minidom.getDOMImplementation()
    doc = domImpl.createDocument(None, "WmsDetails", None)
    rootEl = doc.documentElement

    # Construct a WMS GetMap URL for each layer.
    layerNumber = 1
    for layerInfo in exportParams.layerInfoList:
        wmsURL = wmc_util.parseEndpointString(layerInfo.endpoint, layerInfo.params)
        wmsUrlEl = doc.createElement("wmsURL")
        wmsUrlEl.setAttribute("layer", layerNumber.__str__())
        wmsUrlTextEl = doc.createTextNode(wmsURL)
        wmsUrlEl.appendChild(wmsUrlTextEl)
        rootEl.appendChild(wmsUrlEl)
        layerNumber += 1

    # Include the legend URL if included in the layer data.
    layerInfo = exportParams.layerInfoList[exportParams.animationLayerNumber - 1]
    if layerInfo.legendURL != None:
        log.debug("legendURL %s" % (layerInfo.legendURL))
        xml_util.appendElement(doc, rootEl, "legendURL", layerInfo.legendURL);

    outFile = tempfile.NamedTemporaryFile(prefix=exportParams.fileNamePrefix, suffix=".xml", delete=False,
                                          dir=exportParams.exportDir)
    log.debug("File: %s" % (outFile.name))
    doc.writexml(outFile, addindent="  ", newl="\n", encoding="utf-8")
    outFile.close()

    return ExportResult(True, fileName = os.path.basename(outFile.name))
Пример #2
0
def makeSVSExchangeFormatFile(exportParams):
    """Generates a SVS export. If multiple time values are specified, the result will contain a WMS URL for each.
    """
    layerInfo = exportParams.layerInfoList[exportParams.animationLayerNumber - 1]

    # Make a set of parameters that excludes the dimension over which animation is to occur.
    baseParams = layerInfo.params.copy()
    if (exportParams.animationDimension != None) and (exportParams.animationDimension in baseParams):
        del baseParams[exportParams.animationDimension]

    baseUrl = wmc_util.parseEndpointString(layerInfo.endpoint, baseParams)

    # Create the export XML file.
    domImpl = xml.dom.minidom.getDOMImplementation()
    doc = domImpl.createDocument(None, "MovieExport", None)
    rootEl = doc.documentElement
    movieEl = doc.createElement("Movie")
    movieEl.setAttribute("framesPerSecond", exportParams.frameRate)
    rootEl.appendChild(movieEl)

    # Add a "wmsURL" for each dimension value.
    if exportParams.animationDimension == None:
        requestUrl = baseUrl
        xml_util.appendElement(doc, movieEl, "wmsURL", baseUrl)
    else:
        for val in exportParams.dimensionValues:
            requestUrl = baseUrl + "&" + urllib.urlencode({exportParams.animationDimension: val})
            log.debug("URL: %s" % (requestUrl))
            xml_util.appendElement(doc, movieEl, "wmsURL", requestUrl)

    # Include the outline URL.
    outlineLayerNumber = exportParams.getOutlineLayerNumber()
    if outlineLayerNumber != None:
        outlineInfo = exportParams.layerInfoList[outlineLayerNumber - 1]
        outlineUrl = wmc_util.parseEndpointString(outlineInfo.endpoint, outlineInfo.params)
        xml_util.appendElement(doc, movieEl, "outlineURL", outlineUrl)

    # Include the legend URL if included in the layer data.
    if layerInfo.legendURL != None:
        log.debug("legendURL %s" % (layerInfo.legendURL))
        xml_util.appendElement(doc, movieEl, "legendURL", layerInfo.legendURL)

    # Include the capabilities URL if included in the layer data.
    if layerInfo.capabilitiesURL != None:
        log.debug("capabilitiesURL %s" % (layerInfo.capabilitiesURL))
        xml_util.appendElement(doc, movieEl, "capabilitiesURL", layerInfo.capabilitiesURL)

    outFile = tempfile.NamedTemporaryFile(
        prefix=exportParams.fileNamePrefix, suffix=".xml", delete=False, dir=exportParams.exportDir
    )
    log.debug("File: %s" % (outFile.name))
    doc.writexml(outFile, addindent="  ", newl="\n", encoding="utf-8")
    outFile.close()

    return ExportResult(True, fileName=os.path.basename(outFile.name))
Пример #3
0
def makeKmlFile(exportParams):
    """Generates a KML export. If multiple dimension values are specified, the result will contain an overlay for each.
    """
    layerInfo = exportParams.layerInfoList[exportParams.animationLayerNumber - 1]

    # Make a set of parameters that excludes the dimension over which animation is to occur.
    baseParams = layerInfo.params.copy()

    # Determine if animation over multiple values is to occur.
    do_animation = ((exportParams.animationDimension != None) and
        (exportParams.dimensionValues != None) and (len(exportParams.dimensionValues) > 1))

    if do_animation and (exportParams.animationDimension in baseParams):
        del baseParams[exportParams.animationDimension]

    # Get the bounding box values [W, S, E, N].
    bounds = exportParams.commonLayerParams['BBOX'].split(',')

    baseUrl = wmc_util.parseEndpointString(layerInfo.endpoint, baseParams)

    # Create the export XML file.
    domImpl = xml.dom.minidom.getDOMImplementation()
    doc = domImpl.createDocument("http://earth.google.com/kml/2.2", "kml", None)
    rootEl = doc.documentElement

    folderEl = doc.createElement("Folder")
    rootEl.appendChild(folderEl)
    xml_util.appendElement(doc, folderEl, "name", layerInfo.layerName)
    xml_util.appendElement(doc, folderEl, "open", "1")

    # Add a "wmsURL" for each dimension value.
    layerIndex = 0
    if do_animation:
        itr = iter(exportParams.dimensionValues)
        val = itr.next()
        for nextVal in itr:
            makeKmlGroundOverlayFile(doc, folderEl, layerInfo.layerName, baseUrl, exportParams.animationDimension,
                                     val, val, nextVal, bounds, layerIndex)
            val = nextVal
            layerIndex += 1
        makeKmlGroundOverlayFile(doc, folderEl, layerInfo.layerName, baseUrl, exportParams.animationDimension,
                                 val, val, None, bounds, layerIndex)
    else:
        makeKmlGroundOverlayFile(doc, folderEl, layerInfo.layerName, baseUrl, None, None, None, None, bounds, layerIndex)

    outFile = tempfile.NamedTemporaryFile(prefix=exportParams.fileNamePrefix, suffix=".kml", delete=False, dir=exportParams.exportDir)
    log.debug("File: %s" % (outFile.name))
    doc.writexml(outFile, addindent="  ", newl="\n", encoding="utf-8")
    outFile.close()

    return ExportResult(True, fileName = os.path.basename(outFile.name))
Пример #4
0
def makeKmlGroundOverlayFile(doc, parentEl, name, baseUrl, animationDimension, dimensionValue, begin, end, bounds, layerIndex):
    """Adds a GroundOverlay element for the specified dimension value.
    """
    isTimeAnimation = (animationDimension != None and animationDimension.lower() == "time")
    goEl = doc.createElement("GroundOverlay")
    parentEl.appendChild(goEl)
    xml_util.appendElement(doc, goEl, "name", (dimensionValue if dimensionValue != None else name))
    # If animating over time, make all layers visible since only one applies at a given time, otherwise just the first layer.
    xml_util.appendElement(doc, goEl, "visibility", ("1" if (isTimeAnimation or (layerIndex == 0)) else "0"))

    # Include time span if data supplied.
    if isTimeAnimation and (begin != None or end != None):
        tsEl = doc.createElement("TimeSpan")
        goEl.appendChild(tsEl)
        if begin != None:
            xml_util.appendElement(doc, tsEl, "begin", begin)
        if end != None:
            xml_util.appendElement(doc, tsEl, "end", end)

    # Include the URL for the image.
    if animationDimension == None:
        requestUrl = baseUrl
    else:
        requestUrl = baseUrl + "&" + urllib.urlencode({animationDimension: dimensionValue})
    iconEl = doc.createElement("Icon")
    goEl.appendChild(iconEl)
    xml_util.appendElement(doc, iconEl, "href", requestUrl)
    xml_util.appendElement(doc, iconEl, "refreshMode", "onExpire")

    # Add the bounding box.
    llEl = doc.createElement("LatLonBox")
    goEl.appendChild(llEl)

    xml_util.appendElement(doc, llEl, "north", bounds[3])
    xml_util.appendElement(doc, llEl, "south", bounds[1])
    xml_util.appendElement(doc, llEl, "east", bounds[2])
    xml_util.appendElement(doc, llEl, "west", bounds[0])