I m using QGIS 1.8 Lisboa. After calculating the centroids from a polygon shapefile, if some of them lie outside the polygon outlines, I'd like to move them on the polygon they came from. The criterion should be univocal as I must use them to extract coordinates to be used as the identification code of the polygon itself. Therefore, the procedure should output the same point location each time it runs for the same polygon (not a random position like the one given by "random points" function, that gives a new result each times it's ran).
|
|
You could use the Shapely python library, which provides a function Here's a Python script that can be run in the QGIS Python console. The polygon layer for which you want to create the attribute should be selected. The function takes the name of the attribute you want to update. The attribute has to exist in your layer already, it has to be string type, and it should be long enough (30 characters). Here's an example of the points the algorithm found:
|
|||||||||||||
|
|
The ftools centroid tool can place the centroid outside the polygon if it is concave.
Alternatively, if installing PostGIS is a bit much for a one-off use, you could use Spatialite from within QGIS. You can then use the QSpatiaLite plugin to import your data to SpatiaLite and run the query (SpatialLite honours |
|||
|
|
|
when I understand you right, use: Vector->Research Tools_>Random Points. Now select under "Stratified Sampling Design (Individual polygons)" use value from input field and use approriate field, which gives numerical value of points, which should be genereated for each different polygon |
|||||||
|

