Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improved table usage.Added better transparent layer handling for exte…
…rnal apps.Started gdal bindings git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@65 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
- Loading branch information
volayaf
committed
Apr 6, 2012
1 parent
afdbb21
commit f499c85
Showing
105 changed files
with
672 additions
and
361 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from sextante.core.SextanteConfig import SextanteConfig | ||
from sextante.core.SextanteUtils import SextanteUtils | ||
from qgis.core import * | ||
from PyQt4.QtCore import * | ||
from PyQt4.QtGui import * | ||
|
||
class LayerExporter(): | ||
|
||
'''This class provides method to export layers so they can be used by third party applications. | ||
These method are used by the GeoAlgorithm class and allow the developer to use transparently | ||
any layer that is loaded into QGIS, without having to worry about its origin''' | ||
|
||
@staticmethod | ||
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 appplications, 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''' | ||
settings = QSettings() | ||
systemEncoding = settings.value( "/UI/encoding", "System" ).toString() | ||
output = SextanteUtils.getTempFilename("shp") | ||
provider = layer.dataProvider() | ||
allAttrs = provider.attributeIndexes() | ||
provider.select( allAttrs ) | ||
useSelection = SextanteConfig.getSetting(SextanteConfig.USE_SELECTED) | ||
if useSelection and layer.selectedFeatureCount() != 0: | ||
writer = QgsVectorFileWriter( output, systemEncoding,provider.fields(), provider.geometryType(), provider.crs() ) | ||
selection = layer.selectedFeatures() | ||
for feat in selection: | ||
writer.addFeature(feat) | ||
del writer | ||
return output | ||
else: | ||
if (not str(layer.source()).endswith("shp")): | ||
writer = QgsVectorFileWriter( output, systemEncoding,provider.fields(), provider.geometryType(), provider.crs() ) | ||
feat = QgsFeature() | ||
while provider.nextFeature(feat): | ||
writer.addFeature(feat) | ||
del writer | ||
return output | ||
else: | ||
return str(layer.source()) | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from sextante.script.ScriptAlgorithm import ScriptAlgorithm | ||
from PyQt4 import QtGui | ||
import os | ||
|
||
class GdalAlgorithm(ScriptAlgorithm): | ||
'''Just a ScriptAlgorithm that automatically takes its icon | ||
filename for the script filename''' | ||
|
||
def getIcon(self): | ||
filename = os.path.basename(self.descriptionFile[:-2] + "png") | ||
filepath = os.path.dirname(__file__) + "/icons/" + filename | ||
return QtGui.QIcon(filepath) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import os | ||
from PyQt4.QtCore import * | ||
from PyQt4.QtGui import * | ||
from sextante.core.AlgorithmProvider import AlgorithmProvider | ||
from sextante.script.WrongScriptException import WrongScriptException | ||
from sextante.core.SextanteLog import SextanteLog | ||
from sextante.gdal.GdalAlgorithm import GdalAlgorithm | ||
from sextante.gdal.nearblack import nearblack | ||
from sextante.gdal.information import information | ||
|
||
class GdalAlgorithmProvider(AlgorithmProvider): | ||
|
||
'''This provider incorporates GDAL-based algorithms into SEXTANTE. | ||
Algorithms have been implemented using two different mechanisms, | ||
which should serve as an example of different ways of extending | ||
SEXTANTE: | ||
1)when a python script exist for a given process, it has been adapted | ||
as a SEXTANTE python script and loaded using the ScriptAlgorithm class. | ||
This algorithms call GDAL using its Python bindings | ||
2)Other algorithms are called directly using the command line interface, | ||
These have been implemented individually extending the GeoAlgorithm class''' | ||
|
||
def __init__(self): | ||
AlgorithmProvider.__init__(self) | ||
self.createAlgsList() | ||
|
||
def scriptsFolder(self): | ||
'''The folder where script algorithms are stored''' | ||
return os.path.dirname(__file__) + "/scripts" | ||
|
||
def getName(self): | ||
return "Gdal" | ||
|
||
def getIcon(self): | ||
return QIcon(os.path.dirname(__file__) + "/icons/gdalicon.png") | ||
|
||
def _loadAlgorithms(self): | ||
'''This is called each time there is a change in the SEXTANTE set of algorithm, | ||
for instance, when the users adds a new model or script. Since this provider | ||
cannot be extended by the user, we create the list in advance and then just | ||
assign it to self.algs''' | ||
self.algs = self.preloadedAlgs | ||
|
||
def createAlgsList(self): | ||
#First we populate the list of algorihtms with those created extending | ||
#GeoAlgorithm directly (those that execute GDAL using the console) | ||
self.preloadedAlgs = [nearblack(), information()] | ||
#And then we add those that are created as python scripts | ||
folder = self.scriptsFolder() | ||
for descriptionFile in os.listdir(folder): | ||
if descriptionFile.endswith("py"): | ||
try: | ||
fullpath = os.path.join(self.scriptsFolder(), descriptionFile) | ||
alg = GdalAlgorithm(fullpath) | ||
self.preloadedAlgs.append(alg) | ||
except WrongScriptException,e: | ||
SextanteLog.addToLog(SextanteLog.LOG_ERROR,e.msg) |
Oops, something went wrong.