6

Mac 10.9.5; QGIS 2.8.4-Wien; history and unioned data, in GDA94, zone 55 here.

I have a polygon of fire history with a number of overlapping features. I want to create a new polygon for fire frequency, where each feature has a count of the overlapping features in the history polygon.

The attached data is a small subset of my full data set, so I need a method that will be manageable with a large data set.

I unioned the history polygon to itself to get the individual features that should contain the frequencies. I previously followed Donovan Cameron's method in ArcGIS (http://forums.esri.com/Thread.asp?c=93&f=987&t=282764) with success. However, there is no 'summarize' option in QGIS, so I get stuck at point #6 in that method. I no longer have access to ArcGIS, so I am looking for a QGIS solution.

Here are some other things I've tried:

  • In another ArcGIS method (gis.stackexchange.com/questions/51929/how-to-count-and-rasterize-polygon-overlaps-in-arcgis-desktop), I get stuck at the 'dissolve' step (step 2) because there is no option to count in the dissolve tool for QGIS.

  • In the spaghetti and meatball (blogs.esri.com/esri/arcgis/2012/11/13/spaghetti_and_meatballs/) method, I substituted 'Feature to polygon' with union, and used Vector>Geometry tools>Polygon centroids (instead of the suggested Feature to point tool). At the intersect step I get an empty polygon so I tried to use the spatial join then join steps. This produced a range of the counts I was expecting (0-4) but not all of the original unioned polygon features were retained and the spatial configuration of counts were incorrect.

  • Finally, I've tried raster solutions (e.g. Creating a raster surface of overlaps from vector polygon shapefiles?), but I can't work out how to split my polygon features into separate polygons (multipart to single part returns an indentical polygon).

2 Answers 2

2

I think you could use the Join attributes by location tool which allows you to extract some statistical data from two layers such as sum of values, feature count etc. This can be accessed from:

Processing Toolbox > QGIS geoalgorithms, Vector general tools > Join attributes by location

Join attributes by location interface

Note that the we are taking the summary of intersecting features. You can choose to keep the sum, mean etc parameters or remove them entirely. The output will always contain a count field which counts the number of intersecting features. Here was the result:

Result

2
  • 1
    I did try that too; the counts should be in the range 0-8, not what is returned using join attributes by location. I had a chance to test this on ArcGIS yesterday and realised that the union polygon (attached), generated in QGIS is not correct either. So I need to sort that out before I make further progress with summarising frequencies. I'm using the Arc solution for now, but would still like a QGIS method for future use.
    – asmith
    Commented Feb 24, 2016 at 22:24
  • @asmith - Interesting, I wonder where the Union function went wrong. Atleast you have more correct results from Arc as this method for QGIS has worked for me in the past :)
    – Joseph
    Commented Feb 25, 2016 at 11:44
0

Unfortunately, my tests show that this is a very slow method. If you have any ideas how to optimize the processing, I would be glad to read your comments. It takes 2 minutes and 24 seconds to process 70 heavily overlapping circles like that:

enter image description here

My current analysis of this task shows that using the Union tool may gives no result at all (the process ends with an error due to too many overlapping objects).

Input polygons: enter image description here Final result: enter image description here

Here's how it currently works (there's a standard QGIS tool for each step):

  1. Convert the input polygons into lines. Polygons to lines
  2. Split the input polygons with lines. Split with lines
  3. Calculate the centroids of the polygons. Point on Surface
  4. Remove duplicate geometries. Delete duplicate geometries
  5. Count the points in the polygons. Count points in polygon

Processing Steps < == Ctrl + Left Mouse Click to watch

I made a custom processing tool for this task (copy the code below and save it as a *.model3 file):

QGIS Custom Model

<!DOCTYPE model>
<Option type="Map">
  <Option name="children" type="Map">
    <Option name="native:countpointsinpolygon_1" type="Map">
      <Option name="active" type="bool" value="true"/>
      <Option name="alg_config"/>
      <Option name="alg_id" type="QString" value="native:countpointsinpolygon"/>
      <Option name="color" type="QString" value=""/>
      <Option name="comment" type="Map">
        <Option name="color" type="QString" value=""/>
        <Option name="component_description" type="QString" value=""/>
        <Option name="component_height" type="double" value="60"/>
        <Option name="component_pos_x" type="double" value="1520"/>
        <Option name="component_pos_y" type="double" value="680"/>
        <Option name="component_width" type="double" value="100"/>
        <Option name="outputs_collapsed" type="bool" value="true"/>
        <Option name="parameters_collapsed" type="bool" value="true"/>
      </Option>
      <Option name="component_description" type="QString" value="Count points in polygon"/>
      <Option name="component_height" type="double" value="30.000000000000004"/>
      <Option name="component_pos_x" type="double" value="730"/>
      <Option name="component_pos_y" type="double" value="465"/>
      <Option name="component_width" type="double" value="200"/>
      <Option name="dependencies"/>
      <Option name="id" type="QString" value="native:countpointsinpolygon_1"/>
      <Option name="outputs"/>
      <Option name="outputs_collapsed" type="bool" value="true"/>
      <Option name="parameters_collapsed" type="bool" value="true"/>
      <Option name="params" type="Map">
        <Option name="CLASSFIELD" type="List">
          <Option type="Map">
            <Option name="source" type="int" value="2"/>
            <Option name="static_value" type="QString" value=""/>
          </Option>
        </Option>
        <Option name="FIELD" type="List">
          <Option type="Map">
            <Option name="source" type="int" value="2"/>
            <Option name="static_value" type="QString" value="NUMPOINTS"/>
          </Option>
        </Option>
        <Option name="POINTS" type="List">
          <Option type="Map">
            <Option name="child_id" type="QString" value="native:pointonsurface_1"/>
            <Option name="output_name" type="QString" value="OUTPUT"/>
            <Option name="source" type="int" value="1"/>
          </Option>
        </Option>
        <Option name="POLYGONS" type="List">
          <Option type="Map">
            <Option name="child_id" type="QString" value="native:deleteduplicategeometries_1"/>
            <Option name="output_name" type="QString" value="OUTPUT"/>
            <Option name="source" type="int" value="1"/>
          </Option>
        </Option>
        <Option name="WEIGHT" type="List">
          <Option type="Map">
            <Option name="source" type="int" value="2"/>
            <Option name="static_value" type="QString" value=""/>
          </Option>
        </Option>
      </Option>
    </Option>
    <Option name="native:deleteduplicategeometries_1" type="Map">
      <Option name="active" type="bool" value="true"/>
      <Option name="alg_config"/>
      <Option name="alg_id" type="QString" value="native:deleteduplicategeometries"/>
      <Option name="color" type="QString" value=""/>
      <Option name="comment" type="Map">
        <Option name="color" type="QString" value=""/>
        <Option name="component_description" type="QString" value=""/>
        <Option name="component_height" type="double" value="60"/>
        <Option name="component_pos_x" type="double" value="1120"/>
        <Option name="component_pos_y" type="double" value="490"/>
        <Option name="component_width" type="double" value="100"/>
        <Option name="outputs_collapsed" type="bool" value="true"/>
        <Option name="parameters_collapsed" type="bool" value="true"/>
      </Option>
      <Option name="component_description" type="QString" value="Delete duplicate geometries"/>
      <Option name="component_height" type="double" value="30"/>
      <Option name="component_pos_x" type="double" value="510"/>
      <Option name="component_pos_y" type="double" value="405"/>
      <Option name="component_width" type="double" value="240"/>
      <Option name="dependencies"/>
      <Option name="id" type="QString" value="native:deleteduplicategeometries_1"/>
      <Option name="outputs"/>
      <Option name="outputs_collapsed" type="bool" value="true"/>
      <Option name="parameters_collapsed" type="bool" value="true"/>
      <Option name="params" type="Map">
        <Option name="INPUT" type="List">
          <Option type="Map">
            <Option name="child_id" type="QString" value="native:splitwithlines_1"/>
            <Option name="output_name" type="QString" value="OUTPUT"/>
            <Option name="source" type="int" value="1"/>
          </Option>
        </Option>
      </Option>
    </Option>
    <Option name="native:fieldcalculator_1" type="Map">
      <Option name="active" type="bool" value="true"/>
      <Option name="alg_config"/>
      <Option name="alg_id" type="QString" value="native:fieldcalculator"/>
      <Option name="color" type="QString" value=""/>
      <Option name="comment" type="Map">
        <Option name="color" type="QString" value=""/>
        <Option name="component_description" type="QString" value="Serialize `fid` field.&#xa;This step is only nescessary for saving in geopackage format."/>
        <Option name="component_height" type="double" value="60"/>
        <Option name="component_pos_x" type="double" value="990"/>
        <Option name="component_pos_y" type="double" value="420"/>
        <Option name="component_width" type="double" value="240"/>
        <Option name="outputs_collapsed" type="bool" value="true"/>
        <Option name="parameters_collapsed" type="bool" value="true"/>
      </Option>
      <Option name="component_description" type="QString" value="Field calculator"/>
      <Option name="component_height" type="double" value="30"/>
      <Option name="component_pos_x" type="double" value="880"/>
      <Option name="component_pos_y" type="double" value="525"/>
      <Option name="component_width" type="double" value="200"/>
      <Option name="dependencies"/>
      <Option name="id" type="QString" value="native:fieldcalculator_1"/>
      <Option name="outputs" type="Map">
        <Option name="Overlap Count results" type="Map">
          <Option name="child_id" type="QString" value="native:fieldcalculator_1"/>
          <Option name="color" type="QString" value=""/>
          <Option name="comment" type="Map">
            <Option name="color" type="QString" value=""/>
            <Option name="component_description" type="QString" value=""/>
            <Option name="component_height" type="double" value="60"/>
            <Option name="component_pos_x" type="double" value="0"/>
            <Option name="component_pos_y" type="double" value="0"/>
            <Option name="component_width" type="double" value="100"/>
            <Option name="outputs_collapsed" type="bool" value="true"/>
            <Option name="parameters_collapsed" type="bool" value="true"/>
          </Option>
          <Option name="component_description" type="QString" value="Overlap Count results"/>
          <Option name="component_height" type="double" value="30"/>
          <Option name="component_pos_x" type="double" value="1030"/>
          <Option name="component_pos_y" type="double" value="585"/>
          <Option name="component_width" type="double" value="200"/>
          <Option name="default_value" type="invalid"/>
          <Option name="mandatory" type="bool" value="false"/>
          <Option name="name" type="QString" value="Overlap Count results"/>
          <Option name="output_name" type="QString" value="OUTPUT"/>
          <Option name="outputs_collapsed" type="bool" value="true"/>
          <Option name="parameters_collapsed" type="bool" value="true"/>
        </Option>
      </Option>
      <Option name="outputs_collapsed" type="bool" value="true"/>
      <Option name="parameters_collapsed" type="bool" value="true"/>
      <Option name="params" type="Map">
        <Option name="FIELD_LENGTH" type="List">
          <Option type="Map">
            <Option name="source" type="int" value="2"/>
            <Option name="static_value" type="int" value="0"/>
          </Option>
        </Option>
        <Option name="FIELD_NAME" type="List">
          <Option type="Map">
            <Option name="source" type="int" value="2"/>
            <Option name="static_value" type="QString" value="fid"/>
          </Option>
        </Option>
        <Option name="FIELD_PRECISION" type="List">
          <Option type="Map">
            <Option name="source" type="int" value="2"/>
            <Option name="static_value" type="int" value="0"/>
          </Option>
        </Option>
        <Option name="FIELD_TYPE" type="List">
          <Option type="Map">
            <Option name="source" type="int" value="2"/>
            <Option name="static_value" type="int" value="1"/>
          </Option>
        </Option>
        <Option name="FORMULA" type="List">
          <Option type="Map">
            <Option name="source" type="int" value="2"/>
            <Option name="static_value" type="QString" value="$id"/>
          </Option>
        </Option>
        <Option name="INPUT" type="List">
          <Option type="Map">
            <Option name="child_id" type="QString" value="native:countpointsinpolygon_1"/>
            <Option name="output_name" type="QString" value="OUTPUT"/>
            <Option name="source" type="int" value="1"/>
          </Option>
        </Option>
      </Option>
    </Option>
    <Option name="native:pointonsurface_1" type="Map">
      <Option name="active" type="bool" value="true"/>
      <Option name="alg_config"/>
      <Option name="alg_id" type="QString" value="native:pointonsurface"/>
      <Option name="color" type="QString" value=""/>
      <Option name="comment" type="Map">
        <Option name="color" type="QString" value=""/>
        <Option name="component_description" type="QString" value=""/>
        <Option name="component_height" type="double" value="60"/>
        <Option name="component_pos_x" type="double" value="1300"/>
        <Option name="component_pos_y" type="double" value="580"/>
        <Option name="component_width" type="double" value="100"/>
        <Option name="outputs_collapsed" type="bool" value="true"/>
        <Option name="parameters_collapsed" type="bool" value="true"/>
      </Option>
      <Option name="component_description" type="QString" value="Point on surface"/>
      <Option name="component_height" type="double" value="30"/>
      <Option name="component_pos_x" type="double" value="670"/>
      <Option name="component_pos_y" type="double" value="315"/>
      <Option name="component_width" type="double" value="200"/>
      <Option name="dependencies"/>
      <Option name="id" type="QString" value="native:pointonsurface_1"/>
      <Option name="outputs"/>
      <Option name="outputs_collapsed" type="bool" value="false"/>
      <Option name="parameters_collapsed" type="bool" value="true"/>
      <Option name="params" type="Map">
        <Option name="ALL_PARTS" type="List">
          <Option type="Map">
            <Option name="source" type="int" value="2"/>
            <Option name="static_value" type="bool" value="true"/>
          </Option>
        </Option>
        <Option name="INPUT" type="List">
          <Option type="Map">
            <Option name="child_id" type="QString" value="native:splitwithlines_1"/>
            <Option name="output_name" type="QString" value="OUTPUT"/>
            <Option name="source" type="int" value="1"/>
          </Option>
        </Option>
      </Option>
    </Option>
    <Option name="native:polygonstolines_1" type="Map">
      <Option name="active" type="bool" value="true"/>
      <Option name="alg_config"/>
      <Option name="alg_id" type="QString" value="native:polygonstolines"/>
      <Option name="color" type="QString" value=""/>
      <Option name="comment" type="Map">
        <Option name="color" type="QString" value=""/>
        <Option name="component_description" type="QString" value=""/>
        <Option name="component_height" type="double" value="60"/>
        <Option name="component_pos_x" type="double" value="564"/>
        <Option name="component_pos_y" type="double" value="171"/>
        <Option name="component_width" type="double" value="100"/>
        <Option name="outputs_collapsed" type="bool" value="true"/>
        <Option name="parameters_collapsed" type="bool" value="true"/>
      </Option>
      <Option name="component_description" type="QString" value="Polygons to lines"/>
      <Option name="component_height" type="double" value="30"/>
      <Option name="component_pos_x" type="double" value="430"/>
      <Option name="component_pos_y" type="double" value="135"/>
      <Option name="component_width" type="double" value="200"/>
      <Option name="dependencies"/>
      <Option name="id" type="QString" value="native:polygonstolines_1"/>
      <Option name="outputs"/>
      <Option name="outputs_collapsed" type="bool" value="true"/>
      <Option name="parameters_collapsed" type="bool" value="true"/>
      <Option name="params" type="Map">
        <Option name="INPUT" type="List">
          <Option type="Map">
            <Option name="parameter_name" type="QString" value="inputpolygons"/>
            <Option name="source" type="int" value="0"/>
          </Option>
        </Option>
      </Option>
    </Option>
    <Option name="native:splitwithlines_1" type="Map">
      <Option name="active" type="bool" value="true"/>
      <Option name="alg_config"/>
      <Option name="alg_id" type="QString" value="native:splitwithlines"/>
      <Option name="color" type="QString" value=""/>
      <Option name="comment" type="Map">
        <Option name="color" type="QString" value=""/>
        <Option name="component_description" type="QString" value=""/>
        <Option name="component_height" type="double" value="60"/>
        <Option name="component_pos_x" type="double" value="555"/>
        <Option name="component_pos_y" type="double" value="439"/>
        <Option name="component_width" type="double" value="100"/>
        <Option name="outputs_collapsed" type="bool" value="true"/>
        <Option name="parameters_collapsed" type="bool" value="true"/>
      </Option>
      <Option name="component_description" type="QString" value="Split with lines"/>
      <Option name="component_height" type="double" value="30"/>
      <Option name="component_pos_x" type="double" value="430"/>
      <Option name="component_pos_y" type="double" value="255"/>
      <Option name="component_width" type="double" value="200"/>
      <Option name="dependencies"/>
      <Option name="id" type="QString" value="native:splitwithlines_1"/>
      <Option name="outputs"/>
      <Option name="outputs_collapsed" type="bool" value="true"/>
      <Option name="parameters_collapsed" type="bool" value="true"/>
      <Option name="params" type="Map">
        <Option name="INPUT" type="List">
          <Option type="Map">
            <Option name="parameter_name" type="QString" value="inputpolygons"/>
            <Option name="source" type="int" value="0"/>
          </Option>
        </Option>
        <Option name="LINES" type="List">
          <Option type="Map">
            <Option name="child_id" type="QString" value="native:polygonstolines_1"/>
            <Option name="output_name" type="QString" value="OUTPUT"/>
            <Option name="source" type="int" value="1"/>
          </Option>
        </Option>
      </Option>
    </Option>
  </Option>
  <Option name="designerParameterValues"/>
  <Option name="groupBoxes"/>
  <Option name="help"/>
  <Option name="modelVariables"/>
  <Option name="model_group" type="QString" value="Custom"/>
  <Option name="model_name" type="QString" value="Count_Polygon_Overlaps"/>
  <Option name="parameterDefinitions" type="Map">
    <Option name="inputpolygons" type="Map">
      <Option name="data_types" type="List">
        <Option type="int" value="2"/>
      </Option>
      <Option name="default" type="invalid"/>
      <Option name="defaultGui" type="invalid"/>
      <Option name="description" type="QString" value="Input Polygons"/>
      <Option name="flags" type="int" value="0"/>
      <Option name="help" type="QString" value=""/>
      <Option name="metadata"/>
      <Option name="name" type="QString" value="inputpolygons"/>
      <Option name="parameter_type" type="QString" value="vector"/>
    </Option>
    <Option name="native:fieldcalculator_1:Overlap Count results" type="Map">
      <Option name="create_by_default" type="bool" value="true"/>
      <Option name="data_type" type="int" value="-1"/>
      <Option name="default" type="invalid"/>
      <Option name="defaultGui" type="invalid"/>
      <Option name="description" type="QString" value="Overlap Count results"/>
      <Option name="flags" type="int" value="0"/>
      <Option name="help" type="QString" value=""/>
      <Option name="metadata"/>
      <Option name="name" type="QString" value="native:fieldcalculator_1:Overlap Count results"/>
      <Option name="parameter_type" type="QString" value="sink"/>
      <Option name="supports_append" type="bool" value="true"/>
      <Option name="supports_non_file_outputs" type="bool" value="true"/>
    </Option>
  </Option>
  <Option name="parameterOrder"/>
  <Option name="parameters" type="Map">
    <Option name="inputpolygons" type="Map">
      <Option name="color" type="QString" value=""/>
      <Option name="comment" type="Map">
        <Option name="color" type="QString" value=""/>
        <Option name="component_description" type="QString" value="Input overlapping polygons"/>
        <Option name="component_height" type="double" value="60"/>
        <Option name="component_pos_x" type="double" value="200"/>
        <Option name="component_pos_y" type="double" value="150"/>
        <Option name="component_width" type="double" value="100"/>
        <Option name="outputs_collapsed" type="bool" value="true"/>
        <Option name="parameters_collapsed" type="bool" value="true"/>
      </Option>
      <Option name="component_description" type="QString" value="inputpolygons"/>
      <Option name="component_height" type="double" value="30"/>
      <Option name="component_pos_x" type="double" value="190"/>
      <Option name="component_pos_y" type="double" value="225"/>
      <Option name="component_width" type="double" value="200"/>
      <Option name="name" type="QString" value="inputpolygons"/>
      <Option name="outputs_collapsed" type="bool" value="true"/>
      <Option name="parameters_collapsed" type="bool" value="true"/>
    </Option>
  </Option>
</Option>

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.