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?

3
  • 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
    – Taras
    Commented Jun 15, 2022 at 6:30
  • It works, thank you! @Taras Commented Jun 19, 2022 at 8:44
  • 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.

Your Answer

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

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