Exemple #1
0
 def exportRasterLayer(self, layer):
     destFilename = SextanteUtils.getTempFilenameInTempFolder(os.path.basename(layer)[0:5] + ".sgrd")
     self.exportedLayers[layer] = destFilename
     if SextanteUtils.isWindows() or SextanteUtils.isMac():
         return 'io_gdal 0 -GRIDS "' + destFilename + '" -FILES "' + layer + '"'
     else:
         return 'libio_gdal 0 -GRIDS "' + destFilename + '" -FILES "' + layer + '"'
Exemple #2
0
 def exportRasterLayer(self, layer):
     destFilename = SextanteUtils.getTempFilenameInTempFolder(os.path.basename(layer)[0:5] + ".sgrd")
     self.exportedLayers[layer]= destFilename
     if SextanteUtils.isWindows():
         return "io_gdal 0 -GRIDS \"" + destFilename + "\" -FILES \"" + layer+"\""
     else:
         return "libio_gdal 0 -GRIDS \"" + destFilename + "\" -FILES \"" + layer + "\""
Exemple #3
0
 def exportRasterLayer(self, layer):
     destFilename = SextanteUtils.getTempFilenameInTempFolder(os.path.basename(layer)[0:5] + ".sgrd")
     self.exportedLayers[layer]= destFilename
     if SextanteUtils.isWindows():
         return "io_gdal 0 -GRIDS \"" + destFilename + "\" -FILES \"" + layer+"\""
     else:
         return "libio_gdal 0 -GRIDS \"" + destFilename + "\" -FILES \"" + layer + "\""
Exemple #4
0
    def exportVectorLayer(layer):
        '''Takes a QgsVectorLayer and returns the filename to refer to it, which allows external
        apps which support only file-based layers to use it. It performs the necessary export
        in case the input layer is not in a standard format suitable for most applications, it is
        a remote one or db-based (non-file based) one, or if there is a selection and it should be
        used, exporting just the selected features.
        Currently, the output is restricted to shapefiles, so anything that is not in a shapefile
        will get exported.
        It also export to a new file if the original one contains non-ascii characters'''
        settings = QSettings()
        systemEncoding = settings.value("/UI/encoding", "System")

        filename = os.path.basename(unicode(layer.source()))
        idx = filename.rfind(".")
        if idx != -1:
            filename = filename[:idx]

        filename = str(layer.name())
        validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:"
        filename = ''.join(c for c in filename if c in validChars)
        if len(filename) == 0:
            filename = "layer"
        output = SextanteUtils.getTempFilenameInTempFolder(filename + ".shp")
        provider = layer.dataProvider()
        useSelection = SextanteConfig.getSetting(SextanteConfig.USE_SELECTED)
        if useSelection and layer.selectedFeatureCount() != 0:
            writer = QgsVectorFileWriter(output, systemEncoding,
                                         layer.pendingFields(),
                                         provider.geometryType(), layer.crs())
            selection = layer.selectedFeatures()
            for feat in selection:
                writer.addFeature(feat)
            del writer
            return output
        else:
            isASCII = True
            try:
                unicode(layer.source()).decode("ascii")
            except UnicodeEncodeError:
                isASCII = False
            if (not unicode(layer.source()).endswith("shp") or not isASCII):
                writer = QgsVectorFileWriter(output, systemEncoding,
                                             layer.pendingFields(),
                                             provider.geometryType(),
                                             layer.crs())
                for feat in layer.getFeatures():
                    writer.addFeature(feat)
                del writer
                return output
            else:
                return unicode(layer.source())
    def exportVectorLayer(layer):
        '''Takes a QgsVectorLayer and returns the filename to refer to it, which allows external
        apps which support only file-based layers to use it. It performs the necessary export
        in case the input layer is not in a standard format suitable for most applications, it is
        a remote one or db-based (non-file based) one, or if there is a selection and it should be
        used, exporting just the selected features.
        Currently, the output is restricted to shapefiles, so anything that is not in a shapefile
        will get exported.
        It also export to a new file if the original one contains non-ascii characters'''
        settings = QSettings()
        systemEncoding = settings.value( "/UI/encoding", "System" )

        filename = os.path.basename(unicode(layer.source()))
        idx = filename.rfind(".")
        if idx != -1:
            filename = filename[:idx]

        filename = str(layer.name())
        validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:"
        filename = ''.join(c for c in filename if c in validChars)
        if len(filename) == 0:
             filename = "layer"
        output = SextanteUtils.getTempFilenameInTempFolder(filename + ".shp")
        provider = layer.dataProvider()
        useSelection = SextanteConfig.getSetting(SextanteConfig.USE_SELECTED)
        if useSelection and layer.selectedFeatureCount() != 0:
            writer = QgsVectorFileWriter(output, systemEncoding, layer.pendingFields(), provider.geometryType(), layer.crs())
            selection = layer.selectedFeatures()
            for feat in selection:
                writer.addFeature(feat)
            del writer
            return output
        else:
            isASCII=True
            try:
                unicode(layer.source()).decode("ascii")
            except UnicodeEncodeError:
                isASCII=False
            if (not unicode(layer.source()).endswith("shp") or not isASCII):
                writer = QgsVectorFileWriter( output, systemEncoding, layer.pendingFields(), provider.geometryType(), layer.crs() )
                for feat in layer.getFeatures():
                    writer.addFeature(feat)
                del writer
                return output
            else:
                return unicode(layer.source())