3

I'm using QGIS 3.20.2 and am wondering if it's possible to edit the coordinates of multiple points? I know I can edit individual points using the vertex editor. However I'm wanting to do edits along the lines of keeping the unique X coordinates for the points, but changing the Y coordinate to the same value for multiple points.

I have attempted to do this with the field calculator without success using the make_point expression. Is there a simple work around for this, or does it require editing in Excel and then importing the CSV again?

1 Answer 1

1

If you are ok with creating a new layer and want to move all points you can use "Geometry by expression":

make_point(x($geometry), 7572684)

enter image description here

Another option if you want to modify your layer in place is to use pyqgis. This will also allow you to move only selected points. Adjust the code, select the points you wan t to move and run:

lyr = QgsProject.instance().mapLayersByName('Random points')[0] #Change Random points to the name of your layer
newYCoordinate = 7573081.123 #Change
with edit(lyr):
    for selectedFeature in lyr.getSelectedFeatures(): #For each selected feature
        thePoint = selectedFeature.geometry().asPoint() #Fetch the point geometry
        newgeom = QgsPoint(thePoint.x(), newYCoordinate) #Create a new one using the old ones x coordinate, and your specified y coord
        selectedFeature.setGeometry(newgeom) #Set the geometry
        lyr.updateFeature(selectedFeature) #Update the feature

enter image description here

2
  • 2
    btw "Geometry by expression" also allows for using only selected features Mar 31, 2022 at 6:02
  • 1
    ok i see what you were trying to say my bad Mar 31, 2022 at 6:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.