2

In QGIS I have a shapefile that contains a polygon of administrative boundaries in a country. I need to add six random points inside the polygon.

Can i get the coordinates from random points feature and sync it with my polygons?

Ex: I have US administrative boundaries shapefile that contains "country_name" and "state_name". Then, i generate six random points for every states. Afterward, i want an exported .xlsx file which contains "country_name", "state_name", "lat_long_1", "lat_long_2", etc. accordance with its state.

What should i do?

Taras
35.7k5 gold badges77 silver badges151 bronze badges
asked Jun 15, 2022 at 3:31
2
  • 4
    (1) "Random points inside polygons" (sampling strategy: count) (2) "Join attributes by location" (3) "Add X/Y fields to layer" (4) Export as a CSV Commented Jun 15, 2022 at 6:30
  • Of course you can Commented Jun 19, 2022 at 10:11

1 Answer 1

2

Let's assume there is a polygon layer called 'gadm40_SVN_1'. Data was taken from https://gadm.org/download_country.html.

input

Step 1. Apply the "Random points inside polygons" geoalgorithm with 'Points count' as a sampling strategy.

step1

Step 2. Use the "Join attributes by location" tool to get desired fields for a point layer from the polygon layer. 'Are within' is a suitable geometric predicate for this stage. The spatial index can be additionally used to improve the performance over big data sets.

step2

Step 3. Make use of the "Add X/Y fields to layer" geoalgorithm. I used the EPSG:3794 which is a Projected coordinate system.

step3

Step 4. Finally, export the layer in a preferred output format via right-mouse click > Export > Save Feature As. For Excel, the CSV format can be suitable. Otherwise, I suggest paying attention to this article: Exporting attribute table to Excel from QGIS.

answered Jun 19, 2022 at 13:41

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.