Skip to content
Permalink
Browse files
more API updates to the python plugins
  • Loading branch information
jef-n committed Jan 4, 2013
1 parent a572f3c commit 28ca48c4cf15fa610bfcab91ef636b8d15010eb0
@@ -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()

@@ -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)
@@ -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:
@@ -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 )
@@ -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 )
@@ -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 )
@@ -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 )

@@ -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
@@ -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()]
@@ -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:
@@ -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
@@ -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)
@@ -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:
@@ -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"))

@@ -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")
@@ -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)
@@ -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()
@@ -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)
@@ -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
@@ -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
@@ -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

0 comments on commit 28ca48c

Please sign in to comment.