1

I need to create some random points using QGIS. I have two vector files, one line and the other polygon type. I need to create the random points in those spaces that are not the polygon in itself but are the lines.

Let's assume some buildings (polygon), I need to create the random points in those places where there is not a building.

3

What are the lines? Administrative boundaries? One way to accomplish this would be converting your line to polygon (if it is a closed shape) and then make the difference from the administrative polygon and the buildings. From the resulting polygon, run the "Random points inside polygons" tool.

A simpler approach would be to run for instance the "Random points in extent" and then use a select by location to erase the points inside your buildings. The downside of this approach is that you cannot set a final number of points.

Just type "random points" in the QGIS processing toolbox and you'll see there are lots of options. But basically is either creating a mask and then the points inside or create some random points and delete those inside the buildings.

4
  • The lines won't be useful. I need to work solely with the polygon shape. However, I need the random points outside the perimeter of the polygons. Is there any way of doing this? Like saying, create random points in this layer but excluding the fields...
    – Daniel
    Oct 24 '17 at 14:32
  • the second approach involves just the buildings
    – Albert
    Oct 24 '17 at 14:42
  • Really? What I want are the random points within an extent but outside the buildings. i.e. I have a town (extent) with its buildings and I want the random points outside the buildings
    – Daniel
    Oct 24 '17 at 14:44
  • 1
    Yes, try it. It is pretty straightforward. First you will need to run the Random points in extent tool. Then Select by location the points that intersect with your buildings and delete them or inverse the selection and export them in a new layer.
    – Albert
    Oct 24 '17 at 14:48
3

In Qgis 2.18, you can use the processing algorithm Random points in layer bounds

Run it on your building layer, it will create random points everywhere in the extent of your layer.

Then use select by location, to select the points that intersects/ are wihtin a building an delete them.

The result is a point layer with only point that don't overlaped a building

EDIT

I just realize that this answer use the same approach as @Albert one...

EDIT 2

To get a regular number of point (e.g. 5000 points), you could use the method described by @Albert in his comment:

I suggest you to create enough points to have an excess once you have erased the points in your buildings. Then, to randomly keep exactly 5000, create a new field in the field calculator with this expression: rand( 0,10000000) This will create a random number from 0 to 10M that you can use to order the points and keep, say, the first 5k.

4
  • Yes well, we were answering at the same time I guess. The only problem with the points in layer bounds is at the edges where you won't have points, that's why I proposed using the extent, then you just zoom when you want and use the layer/canvas extent to have also points surrounding your edge buildings. In any case, I prefer to create a mask and put the exact amount of points I want.
    – Albert
    Oct 24 '17 at 15:01
  • That make sense and i totally agree with you. Using a Mask is clearly the option that provide the better control!
    – YoLecomte
    Oct 24 '17 at 15:05
  • Yeap, I managed to this. Maybe I should have been more clear. I have a budget of 5000 points, so if I erase them I have to creat more points and do this process over and over until I achieve my budget.
    – Daniel
    Oct 24 '17 at 15:05
  • 1
    If you use this approach I suggest you to create enough points to have an excess once you have erased the points in your buildings. Then, to randomly keep exactly 5000, create a new field in the field calculator with this expression: rand( 0,10000000) This will create a random number from 0 to 10M that you can use to order the points and keep, say, the first 5k.
    – Albert
    Oct 25 '17 at 6:40

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.