QGIS – How to Get Coordinates from Random Points in Polygon and Sync with Shapefile

overlapping-featurespoint-creationpoint-in-polygonqgisshapefile

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?

Best Answer

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.

Related Question