How to use the nansat.node.Node.create function in nansat

To help you get started, we’ve selected a few nansat examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nansencenter / nansat / nansat / mappers / mapper_radarsat2.py View on Github external
zz = zipfile.ZipFile(inputFileName)
            productXmlName = os.path.join(os.path.basename(inputFileName).split('.')[0],'product.xml')
            productXml = zz.open(productXmlName).read()
        else:
            # product.xml to get additionali metadata
            productXmlName = os.path.join(filename,'product.xml')
            if not os.path.isfile(productXmlName):
                raise WrongMapperError(filename)
            productXml = open(productXmlName).read()

        if not IMPORT_SCIPY:
            raise NansatReadError(' Radarsat-2 data cannot be read because scipy is not installed! '
                                  ' Please do: conda -c conda-forge install scipy ')

        # parse product.XML
        rs2_0 = Node.create(productXml)

        if xmlonly:
            self.init_from_xml(rs2_0)
            return

        # Get additional metadata from product.xml
        rs2_1 = rs2_0.node('sourceAttributes')
        rs2_2 = rs2_1.node('radarParameters')
        if rs2_2['antennaPointing'].lower() == 'right':
            antennaPointing = 90
        else:
            antennaPointing = -90
        rs2_3 = rs2_1.node('orbitAndAttitude').node('orbitInformation')
        passDirection = rs2_3['passDirection']

        # create empty VRT dataset with geolocation only
github nansencenter / nansat / nansat / mappers / mapper_landsat.py View on Github external
ySize = gdalDatasetTmp.RasterYSize
            elif (xSize != gdalDatasetTmp.RasterXSize or
                    ySize != gdalDatasetTmp.RasterYSize):
                sizeDiffBands.append(iFile)

        # create empty VRT dataset with geolocation only
        VRT.__init__(self, gdalDatasetTmp0)

        # add bands with metadata and corresponding values to the empty VRT
        self._create_bands(metaDict)

        # 8th band of LANDSAT8 is a double size band.
        # Reduce the size to same as the 1st band.
        if len(sizeDiffBands) != 0:
            vrtXML = self.read_xml()
            node0 = Node.create(vrtXML)
            for iBand in sizeDiffBands:
                iBandNode = node0.nodeList('VRTRasterBand')[iBand]
                iNodeDstRect = iBandNode.node('DstRect')
                iNodeDstRect.replaceAttribute('xSize', str(xSize))
                iNodeDstRect.replaceAttribute('ySize', str(ySize))

            self.write_xml(node0.rawxml())
github nansencenter / nansat / nansat / vrt.py View on Github external
def hardcopy_bands(self):
        """Make 'hardcopy' of bands: evaluate array from band and put into original band"""
        bands = range(1, self.dataset.RasterCount+1)
        for i in bands:
            self.band_vrts[i] = VRT.from_array(self.dataset.GetRasterBand(i).ReadAsArray())

        node0 = Node.create(str(self.xml))
        for i, iNode1 in enumerate(node0.nodeList('VRTRasterBand')):
            iNode1.node('SourceFilename').value = self.band_vrts[i+1].filename
            iNode1.node('SourceBand').value = str(1)
        self.write_xml(node0.rawxml())
github nansencenter / nansat / nansat / vrt.py View on Github external
def delete_band(self, band_num):
        """ Delete a band from the given VRT

        Parameters
        ----------
        band_num : int
            band number

        """
        node0 = Node.create(self.xml)
        node0.delNode('VRTRasterBand', options={'band': band_num})
        node0.delNode('BandMapping', options={'src': band_num})
        self.write_xml(node0.rawxml())
github nansencenter / nansat / nansat / node.py View on Github external
"""
        if isinstance(dom, str):
            if os.path.exists(dom):
                # parse input file
                dom = xdm.parse(dom)
            else:
                # Strip all extraneous whitespace so that
                # text input is handled consistently:
                dom = re.sub('\s+', ' ', dom)
                dom = dom.replace('> ', '>')
                dom = dom.replace(' <', '<')
                return Node.create(xdm.parseString(str(dom)))

        # To pass test for python3, decoding of bytes object is requested
        if dom.nodeType == dom.DOCUMENT_NODE:
            return Node.create(dom.childNodes[0])
        if dom.nodeName == '#text':
            return
        node = Node(dom.nodeName)
        if dom.attributes:
            for name, val in dom.attributes.items():
                node.setAttribute(name, val)
        for n in dom.childNodes:
            if n.nodeType == n.TEXT_NODE and n.wholeText.strip():
                node.value = n.wholeText
            else:
                subnode = Node.create(n)
                if subnode:
                    node += subnode
        return node
github nansencenter / nansat / nansat / vrt.py View on Github external
# read xml and create the node
        node0 = Node.create(shift_vrt.xml)

        # divide into two bands and switch the bands
        for i in range(len(node0.nodeList('VRTRasterBand'))):
            # create i-th 'VRTRasterBand' node
            node1 = node0.node('VRTRasterBand', i)
            # modify the 1st band
            shift_str = str(shift_pixel)
            size_str = str(shift_vrt.vrt.dataset.RasterXSize - shift_pixel)
            node1.node('ComplexSource').node('DstRect').replaceAttribute('xOff', shift_str)
            node1.node('ComplexSource').node('DstRect').replaceAttribute('xSize', size_str)
            node1.node('ComplexSource').node('SrcRect').replaceAttribute('xSize', size_str)

            # add the 2nd band
            clone_node = Node.create(node1.rawxml()).node('ComplexSource')
            clone_node.node('SrcRect').replaceAttribute('xOff', size_str)
            clone_node.node('DstRect').replaceAttribute('xOff', str(0))
            clone_node.node('SrcRect').replaceAttribute('xSize', shift_str)
            clone_node.node('DstRect').replaceAttribute('xSize', shift_str)

            # get VRTRasterBand with inserted ComplexSource
            node1 = node1.insert(clone_node.rawxml())
            node0.replaceNode('VRTRasterBand', i, node1)

        # write down XML contents
        shift_vrt.write_xml(node0.rawxml())

        return shift_vrt
github nansencenter / nansat / nansat / vrt.py View on Github external
# apply thin-spline-transformation option
        if self.tps:
            warped_vrt.write_xml(warped_vrt.xml.replace('GCPTransformer', 'TPSTransformer'))

        # if given, add dst GCPs
        if len(dst_gcps) > 0:
            warped_vrt.dataset.SetGCPs(dst_gcps, dst_srs)
            warped_vrt._remove_geotransform()
            warped_vrt.dataset.SetProjection(str(''))

        # Copy self to warpedVRT
        warped_vrt.vrt = self.copy()

        # replace the reference from src_vrt to warped_vrt.vrt
        node0 = Node.create(str(warped_vrt.xml))
        node1 = node0.node('GDALWarpOptions')
        node1.node('SourceDataset').value = '/vsimem/' + str(os.path.basename(warped_vrt.vrt.filename))
        warped_vrt.write_xml(node0.rawxml())

        return warped_vrt