3

I have a series of points in .shp format arranged in lines over an area, which I've used the 'regular points' tool to generate. In some of the lines, I want to decrease the spacing of the points so have added extras (selected points in image below) points with additions

I've added the extra points using the 'add point feature tool' and just clicked them approximately where they need to be.

Now I want to 'tidy up' the lines, and make all the new points on the same northing as the original ones, which they are slightly off because I added them by hand. I'm using a UTM CRS.

My question: Is there a way of selecting all the features in a row, and assigning a shared northing to all of them at once?

I realise at the moment I could either use the 'edit node' tool and change them one by one, or use the field calculator tool to make east and north columns, filled with the $x command, export this as a CSV or similar, edit in excel and re-import. I'm hoping for something more streamlined than this though!

Other software I've used has a very handy way of doing this, where selected points can be edited using the properties panel by simply clicking and changing the east or north for multiple points (image below)

properties window allows easy coordinate editing

6

you can also use the field calculator to change the geometry directly for selected points or all points. see picture below (sorry it's the german version but it should be clear anyway):

enter image description here

  • Nice solution! Because python is my go-to tool, I often overlook (or am unaware) of other methods- especially the power of expressions. – Ben W Sep 2 at 5:45
  • 2
    same for me! But your solution is also elegant – eurojam Sep 2 at 5:56
3

I'm not sure whether you are comfortable using the python console, but here is a short script I wrote which should do what you want (one row of points at a time). In case you are not familiar with running scripts in the console, open the python console, click the 'Show Editor' button, and paste the following code into the editor.

Note: Before running the script, ensure your point grid layer is the selected (active) layer, and that the points you want to move are selected (like I said this will only work for one row of points at a time).

Before:

enter image description here

Make sure you have entered your desired y_val in the code, this line should look like (as an example):

y_val = 7476811.000

then click the green arrow to run the script. You will see the layer is in edit mode and your points should all be sitting on the exact same y/northing. You will also see a message box asking if you are happy with the edits:

enter image description here

If so, click ok on the message and the changes will be saved. If not, close the message dialog using the X. You can then just toggle editing off and discard the changes.

After clicking ok:

enter image description here

layer = iface.activeLayer()
feats = [f for f in layer.selectedFeatures()]
layer.startEditing()
for f in feats:
    fid = f.id()
    x_val = f.geometry().constGet().x()
    y_val = #Enter desired y/northing here
    new_geom = QgsGeometry().fromPointXY(QgsPointXY(x_val, y_val))
    layer.changeGeometry(fid, new_geom)

layer.triggerRepaint()
msg = QMessageBox()
msg.setText('Are you happy with the edits?')
msg.buttonClicked.connect(lambda: layer.commitChanges())
msg.show()
2

You have mentioned that you are using "Regular Points" to create points arranged in lines over an area.

You could create another layer with "Regular Points" with half the vertical spacing of the first layer. Pay attention to the extent of both layers.

Then you could use this new layer to snap new points on the first layer to decrease the spacing.

Snapping: Settings > Snapping Options > Choose the layer to change : mode "to vertex" and a tolerance (depending on your projection)

You could also create a regular vector grid made of polygons (Tool "Vector Grid"), there you could snap the points on the line in W-E direction. This would be the way to create points not half the way between the regular points.

Snapping: Settings > Snapping Options > Choose the layer to change : mode "to segment" and a tolerance (depending on your projection)

enter image description here

Red points = Regular Grid 1; Crosses = Regular Grid 2; Pink Cross = snapped point

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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