Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
more API updates to the python plugins
  • Loading branch information
jef-n committed Jan 4, 2013
1 parent a572f3c commit 28ca48c
Show file tree
Hide file tree
Showing 17 changed files with 33 additions and 33 deletions.
9 changes: 4 additions & 5 deletions python/plugins/GdalTools/tools/dialogSRS.py
Expand Up @@ -44,18 +44,17 @@ def __init__(self, title, parent=None):
self.connect(buttonBox, SIGNAL("accepted()"), self.accept)
self.connect(buttonBox, SIGNAL("rejected()"), self.reject)

def epsg(self):
return "EPSG:" + str(self.selector.selectedEpsg())
def authid(self):
return str(self.selector.selectedAuthId()

def proj4string(self):
return self.selector.selectedProj4String()

def getProjection(self):
if self.selector.selectedEpsg() != 0:
return self.epsg()
if self.authid().startsWith("EPSG:", Qt.CaseInsensitive):
return self.authid()

if not self.selector.selectedProj4String().isEmpty():
return self.proj4string()

return QString()

4 changes: 2 additions & 2 deletions python/plugins/db_manager/layer_preview.py
Expand Up @@ -105,14 +105,14 @@ def _loadTablePreview(self, table, limit=False):
if not vl.isValid():
self.setLayerSet( [] )
else:
newLayerId = vl.id() if hasattr(vl, 'id') else vl.getLayerID()
newLayerId = vl.id() if hasattr(vl, 'id') else vl.id()
self.setLayerSet( [ QgsMapCanvasLayer(vl) ] )
QgsMapLayerRegistry.instance().addMapLayers([vl], False)
self.zoomToFullExtent()

# remove old layer (if any) and set new
if self.currentLayerId:
QgsMapLayerRegistry.instance().removeMapLayer(self.currentLayerId, False)
QgsMapLayerRegistry.instance().removeMapLayers([self.currentLayerId], False)
self.currentLayerId = newLayerId

self.setRenderFlag(True)
Expand Down
3 changes: 2 additions & 1 deletion python/plugins/fTools/tools/doGeometry.py
Expand Up @@ -992,7 +992,7 @@ def simpleMeasure( self, inGeom, calcType, ellips, crs ):
if calcType == 2:
measure.setSourceCrs( crs )
measure.setEllipsoid( ellips )
measure.setProjectionsEnabled( True )
measure.setEllipsoidalMode( True )

attr1 = measure.measure( inGeom )
if inGeom.type() == QGis.Polygon:
Expand Down Expand Up @@ -1174,6 +1174,7 @@ def findOrCreateFields( self, vlayer ):
else:
index2 = len( fieldKeys ) + 1
newFields.append( field )
# FIXME: addAttributes was deprecated and removed
vprovider.addAttributes( newFields )
vlayer.updateFieldMap()
return ( index1, index2 )
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/fTools/tools/doRandPoints.py
Expand Up @@ -128,7 +128,7 @@ def accept(self):
self.tr("Created output point shapefile:\n%1\n\nWould you like to add the new layer to the TOC?").arg(outPath), QMessageBox.Yes, QMessageBox.No, QMessageBox.NoButton)
if addToTOC == QMessageBox.Yes:
self.vlayer = QgsVectorLayer(outPath, unicode(outName), "ogr")
QgsMapLayerRegistry.instance().addMapLayer([self.vlayer])
QgsMapLayerRegistry.instance().addMapLayers([self.vlayer])
self.populateLayers()
self.progressBar.setValue(0)
self.buttonOk.setEnabled( True )
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/fTools/tools/doRegPoints.py
Expand Up @@ -92,7 +92,7 @@ def accept(self):
addToTOC = QMessageBox.question(self, self.tr("Generate Regular Points"), self.tr("Created output point shapefile:\n%1\n\nWould you like to add the new layer to the TOC?").arg( outPath ), QMessageBox.Yes, QMessageBox.No, QMessageBox.NoButton)
if addToTOC == QMessageBox.Yes:
self.vlayer = QgsVectorLayer(outPath, unicode(outName), "ogr")
QgsMapLayerRegistry.instance().addMapLayer([self.vlayer])
QgsMapLayerRegistry.instance().addMapLayers([self.vlayer])
self.populateLayers()
self.progressBar.setValue(0)
self.buttonOk.setEnabled( True )
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/fTools/tools/doSpatialJoin.py
Expand Up @@ -109,7 +109,7 @@ def accept(self):
.arg(unicode(outPath)), QMessageBox.Yes, QMessageBox.No, QMessageBox.NoButton)
if addToTOC == QMessageBox.Yes:
self.vlayer = QgsVectorLayer(outPath, unicode(outName), "ogr")
QgsMapLayerRegistry.instance().addMapLayer([self.vlayer])
QgsMapLayerRegistry.instance().addMapLayers([self.vlayer])
self.progressBar.setValue(0)
self.buttonOk.setEnabled( True )

Expand Down
2 changes: 1 addition & 1 deletion python/plugins/fTools/tools/ftools_utils.py
Expand Up @@ -104,7 +104,7 @@ def writeVectorLayerToShape( vlayer, outputPath, encoding ):
if not mCodec:
return False
#Here we should check that the output path is valid
QgsVectorFileWriter.writeAsShapefile( vlayer, outputPath, encoding, vlayer.dataProvider().crs(), False )
QgsVectorFileWriter.writeAsVectorFormat( vlayer, outputPath, encoding, vlayer.dataProvider().crs(), "ESRI Shapefile", False )
return True

# For use with memory provider/layer, converts QGis vector type definition to simple string
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/osm/OsmLoadDlg.py
Expand Up @@ -156,7 +156,7 @@ def onOK(self):

if replacing:
# remove layers of current data first
QgsMapLayerRegistry.instance().removeMapLayer(self.canvas.currentLayer().id(),True)
QgsMapLayerRegistry.instance().removeMapLayers([self.canvas.currentLayer().id()],True)

if self.chkCustomRenderer.isChecked():
styleFile=self.styleFiles[self.styleCombo.currentIndex()]
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/sextante/algs/ftools/ExportGeometryInfo.py
Expand Up @@ -151,7 +151,7 @@ def simpleMeasure(self, geom, method, ellips, crs):
if method == 2:
measure.setSourceCrs(crs)
measure.setEllipsoid(ellips)
measure.setProjectionsEnabled(True)
measure.setEllipsoidalMode(True)

attr1 = measure.measure(geom)
if geom.type() == QGis.Polygon:
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/sextante/algs/ftools/ftools_utils.py
Expand Up @@ -96,7 +96,7 @@ def writeVectorLayerToShape( vlayer, outputPath, encoding ):
if not mCodec:
return False
#Here we should check that the output path is valid
QgsVectorFileWriter.writeAsShapefile( vlayer, outputPath, encoding, vlayer.dataProvider().crs(), False )
QgsVectorFileWriter.writeAsVectorFormat( vlayer, outputPath, encoding, vlayer.dataProvider().crs(), "ESRI Shapefile", False )
return True

# For use with memory provider/layer, converts QGis vector type definition to simple string
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/sextante/algs/mmqgisx/mmqgisx_library.py
Expand Up @@ -1387,7 +1387,7 @@ def mmqgisx_hub_distance(progress, sourcelayer, hubslayer, nameattributename, un
source = feature.geometry().boundingBox().center()
distance = QgsDistanceArea()
distance.setSourceCrs(sourcelayer.dataProvider().crs().srsid())
distance.setProjectionsEnabled(1)
distance.setEllipsoidalMode(True)

closest = hubs[0]
hubdist = distance.measureLine(source, closest.point)
Expand Down
1 change: 1 addition & 0 deletions python/plugins/sextante/core/SextanteVectorWriter.py
Expand Up @@ -57,6 +57,7 @@ def __init__(self, fileName, encoding, fields, geometryType, crs, options=None):
uri += "?crs=" + crs.authid()
self.memLayer = QgsVectorLayer(uri, self.fileName, "memory")
self.writer = self.memLayer.dataProvider()
# FIXME: addAttributes was deprecated and removed
self.writer.addAttributes(fields.values())
self.memLayer.updateFieldMap()
else:
Expand Down
8 changes: 4 additions & 4 deletions python/plugins/sextante/gdal/warp.py
Expand Up @@ -50,8 +50,8 @@ def defineCharacteristics(self):
self.name = "Warp (reproject)"
self.group = "[GDAL] Projections"
self.addParameter(ParameterRaster(warp.INPUT, "Input layer", False))
self.addParameter(ParameterCrs(warp.SOURCE_SRS, "Source SRS (EPSG Code)", "4326"))
self.addParameter(ParameterCrs(warp.DEST_SRS, "Destination SRS (EPSG Code)", "4326"))
self.addParameter(ParameterCrs(warp.SOURCE_SRS, "Source SRS (EPSG Code)", "EPSG:4326"))
self.addParameter(ParameterCrs(warp.DEST_SRS, "Destination SRS (EPSG Code)", "EPSG:4326"))
self.addParameter(ParameterSelection(warp.METHOD, "Resampling method", warp.METHOD_OPTIONS))
self.addOutput(OutputRaster(warp.OUTPUT, "Output layer"))

Expand All @@ -60,9 +60,9 @@ def processAlgorithm(self, progress):
self.crs = QgsCoordinateReferenceSystem(int(srs))
commands = ["gdalwarp"]
commands.append("-s_srs")
commands.append("EPSG:" + str(self.getParameterValue(warp.SOURCE_SRS)))
commands.append(str(self.getParameterValue(warp.SOURCE_SRS)))
commands.append("-t_srs")
commands.append("EPSG:" + str(srs))
commands.append(str(srs))
commands.append("-r")
commands.append(warp.METHOD_OPTIONS[self.getParameterValue(warp.METHOD)])
commands.append("-of")
Expand Down
8 changes: 4 additions & 4 deletions python/plugins/sextante/gui/CrsSelectionDialog.py
Expand Up @@ -32,7 +32,7 @@ class CrsSelectionDialog(QDialog):

def __init__(self):
QDialog.__init__(self)
self.epsg = None
self.authid = None
layout = QVBoxLayout()
self.selector = QgsProjectionSelector(self)
buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Close)
Expand All @@ -44,9 +44,9 @@ def __init__(self):
self.connect(buttonBox, SIGNAL("rejected()"), self.cancelPressed)

def okPressed(self):
self.epsg = self.selector.selectedEpsg()
self.authid = self.selector.selectedAuthId()
self.close()

def cancelPressed(self):
self.epsg = None
self.close()
self.authid = None
self.close()
10 changes: 5 additions & 5 deletions python/plugins/sextante/gui/CrsSelectionPanel.py
Expand Up @@ -30,7 +30,7 @@ class CrsSelectionPanel(QtGui.QWidget):

def __init__(self, default):
super(CrsSelectionPanel, self).__init__(None)
self.epsg = default
self.authid = default
self.horizontalLayout = QtGui.QHBoxLayout(self)
self.horizontalLayout.setSpacing(2)
self.horizontalLayout.setMargin(0)
Expand All @@ -48,12 +48,12 @@ def __init__(self, default):
def showSelectionDialog(self):
dialog = CrsSelectionDialog()
dialog.exec_()
if dialog.epsg:
self.epsg = str(dialog.epsg)
if dialog.authid:
self.authid = str(dialog.authid)
self.setText()

def setText(self):
self.text.setText("EPSG:" + str(self.epsg))
self.text.setText(str(self.authid))

def getValue(self):
return self.epsg
return self.authid
4 changes: 2 additions & 2 deletions python/plugins/sextante/parameters/ParameterCrs.py
Expand Up @@ -27,8 +27,8 @@

class ParameterCrs(Parameter):

def __init__(self, name="", description="", default = "4326"):
'''The value is the EPSG code of the CRS'''
def __init__(self, name="", description="", default = "EPSG:4326"):
'''The value is the auth id of the CRS'''
Parameter.__init__(self, name, description)
self.value = None
self.default = default
Expand Down
3 changes: 1 addition & 2 deletions python/plugins/sextante/tests/qgis_interface.py
Expand Up @@ -41,8 +41,7 @@ def __init__(self, canvas):
self.canvas = canvas
self.testRaster = QgsRasterLayer('data/raster', "raster")
self.testVector = QgsVectorLayer('data/vector', "vector", 'ogr')
QgsMapLayerRegistry.instance().addMapLayer(self.testRaster)
QgsMapLayerRegistry.instance().addMapLayer(self.testVector)
QgsMapLayerRegistry.instance().addMapLayers([self.testRaster,self.testVector])

self.statusBar = type('FakeStatusBar', (),
{'showMessage' : lambda _, m: None
Expand Down

0 comments on commit 28ca48c

Please sign in to comment.