Created
June 13, 2010 01:10
-
-
Save Sharpie/436238 to your computer and use it in GitHub Desktop.
Function to allow editing of QGIS point coordinates via the Python console.
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
# Arrgh... QGIS doesn't appear to have a way of editing the coordinates of a point. Only input via CSV | |
# files. This is the way to go for large numbers of coordinates but it just plain sucks balls for | |
# dealing with a handful of points. I don't know much about the guts of QGIS so I can't submit a formal | |
# fix, but it does have a python interpreter... | |
# Based on code given in this post by Carson Farmer: | |
# | |
# http://www.mail-archive.com/qgis-user@lists.osgeo.org/msg01446.html | |
# | |
# Date: 11/04/2008 | |
# | |
# Updated to work with QGIS v. 1.4.0 by Charlie Sharpsteen | |
def move_point(): | |
# Need this to create the dialog. | |
from PyQt4.QtGui import * | |
# Shortcut to iface. | |
iface = qgis.utils.iface | |
# Recover currently active layer- *must* be selected in legend pane for this to work. | |
layer = iface.mapCanvas().currentLayer() | |
# this is the currently selected feature, if more than one is selected, only the first is used | |
feature = layer.selectedFeatures()[0] | |
# this is used to get the point coordinates | |
point = feature.geometry().asPoint() | |
# this is the input dialog | |
input = QInputDialog.getText( iface.mainWindow(), "Move Point Feature", "Enter New Coordinates as 'xcoord,ycoord'", | |
QLineEdit.Normal, str( point.x() ) + "," + str( point.y() )) | |
# now we translate the later by the distance between the original point, and the user specified point | |
layer.translateFeature( feature.id(), input[0].split( "," )[ 0 ].toDouble()[ 0 ] - point.x(), input[ 0 ].split( "," )[ 1 ].toDouble()[ 0 ] - point.y() ) | |
# we have to update the extents of the layer so it knows about the change | |
layer.updateExtents() | |
# don't know if this is required... | |
QgsMapLayerRegistry.instance().addMapLayer(layer) | |
# now refresh the map canvas | |
iface.mapCanvas().refresh() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment