3

I am using QGIS 2.8.6 and I have a shapefile with polygons. I want to remove all the polygons which have both minimum length and minimum width less than 500m. I need to do it within a Python script. Does anyone have an idea about how to accomplish this? Can you also explain to me how to do it with the available functionalities of QGIS?

When I tried to use Polygons from layer extent, I could find the height and width of the bounding boxes greater than or equal to 500m however these bounding boxes represent maximum length and width so I can still have polygons inside which do not satisfy my requirement.

  • minimum width is not ambiguous, but what is your definition of minimum length ? An illustration would help, I think. – radouxju Feb 19 '16 at 8:05
2

I suggest to do (I hope that your polygons have unique ID):

  1. Use Polygons to line (from Vector) - that convert your shape to line
  2. Use Explode lines from Processing Toolbox - that explode line to lines with inherit your polygon ID
  3. Open Filed calculator for this layer and create new field with expression (now you have information about lengths for all lines in polygons)

$length

  1. Make a copy ot this layer
  2. Use Sum Line lengths from Processing Toolbox (select exploded lines and polygon layer) - that sum all lines lengths and count lines for unique polygon ID
  3. Use Extract by attribute from Processing Toolbox (with condition < 500) - input layer will Exploded Lines with $length attribute. Now you will have only lines of less than 500.
  4. Use Sum Line lengths from Processing Toolbox (select exploded lines and polygon layer) - that sum all lines lengths and count lines for unique polygon ID with your condition < 500 (input layer from 6 step)
  5. Last step is join this two layers. Use Join attributes by location from Vector>Data managment tools and select target and join layers (created in 5 step and 7 step)
  6. Now look to the table and compare attributes counted all lines in polygon and counted all lines in polygon which are less than 500. For a triangle counted all lines in polygon will be 3 and for the rest min. 4. I think that now you should analyze differences between counted all lines in polygon and counted all lines in polygon which are less than 500 (for example: if you have 4 or more "all lines" and min. 2 or more "lines with condition < 500" than you can select them and delete. For triangle: if you have 3 "all lines" and min. 1 or more (depends from your specify) "lines with condition < 500" than you can select them and delete.
  7. I think it will help but in my opinion are simplest methods with using python.
|improve this answer|||||

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.