I want to convert my polygon layers into point layer where I will have a point for each grid of 100m *100m grid for entire polygon layers using PyQGIS ?

I don't know any library function for grid creation and way to extract single point from the gird Point may be centroid of grid.

That's why I haven't provided any code snippet.


In the QGIS documentation, Convert polygon/line vertices to points

it provides this option to convert polygons to points

Converts the line or polygon vertices into points.

Shapes [vector: any]
Layer to process.
Points [vector]
The resulting layer.

Console usage (here is the script)

processing.runalg('saga:convertpolygonlineverticestopoints', shapes, points)

  • But how to add 100m distance for each point condition i.e. Each grid of 100m*100m – sudhanshud Sep 6 '17 at 21:46
  • Could you edit this question to just ask about converting polygons and vertices into points, and ask a different question about grid creation. GIS SE, like to have one question per post to make it easier for searching and answer for the community. – whyzar Sep 6 '17 at 21:49

If you want to get the centroid point of each polygon one option would be to the following:

  1. You'll first need to get the layer object, once you have that then loop through each feature using layer.getFeatures() method (keyword web search "pyqgis vector layer")
  2. Once you have the feature object you may use the feature.geometry().centroid().asPoint() which will return the x/y coordinate (keyword web search "pyqgis get layer features")
  3. Once you have the x/y coordinate you may then create a new point layer and write the x/y values to that layer thus creating a centroid point layer (keyword web search "pyqgis create point layer AND pyqgis add point features to point layefr")

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.