<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Hi Daniela,</p>
    <p>possible solution:</p>
    <p>1. run the "Union" algorithm that splits the input polygons</p>
    <p>2. add a new integer-column to the "Union"-result-layer f. e.
      "num_overlays"</p>
    <p>3. optionally an additional column with type "integer list" or
      "string", if You want to see afterwards, which features intersect,
      f. e. "overlay_ids" </p>
    <p>4. run the script below, that performs a self-intersection for
      each feature to find the spatial identical overlaps (Note: Layer-
      and column-names hard coded, adjust if necessary)<br>
    </p>
    <p><font face="monospace"><br>
      </font></p>
    <font face="monospace">union_layer =
      QgsProject.instance().mapLayersByName('Union')[0]<br>
      <br>
      union_layer.startEditing()<br>
      <br>
      for union_feature_1 in union_layer.getFeatures():<br>
          num_overlays = 0<br>
          overlay_ids = []<br>
          for union_feature_2 in union_layer.getFeatures():<br>
              if
      union_feature_1.geometry().equals(union_feature_2.geometry()) and
      union_feature_1.id() != union_feature_2.id():<br>
                  num_overlays += 1<br>
                  overlay_ids.append(union_feature_2.id())<br>
              <br>
          union_feature_1['num_overlays'] =  len(overlay_ids)<br>
          # solution for column type "string" instead of "integer list":<br>
          # union_feature_1['overlay_ids'] =  ','.join(str(id) for id in
      overlay_ids)<br>
          union_feature_1['overlay_ids'] =  overlay_ids<br>
          <br>
          union_layer.updateFeature(union_feature_1)<br>
          <br>
      union_layer.commitChanges()<br>
      <br>
      <br>
    </font>
    <p><br>
    </p>
    <p>hth</p>
    <p>Ludwig<br>
    </p>
    <p><br>
    </p>
    <p><br>
      <br>
    </p>
    <p><br>
    </p>
    <div class="moz-cite-prefix">Am 18.08.23 um 16:15 schrieb Daniela
      Friebel via QGIS-User:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAAbRx=RMhJ8BSGwXfYWh_aDXiOQ9nhD=cF=7jy8x1RFSmY6xQw@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="ltr">
        <div dir="ltr">
          <p class="MsoNormal"><a
              name="m_-439631545228891369__olk_signature"
              moz-do-not-send="true">Dear Community</a></p>
          <p class="MsoNormal"> </p>
          <p class="MsoNormal">I have a vectorlayer with many objects
            (polygons) that overlap. Now I want to create a new layer,
            where each overlap results in a separate object, which has
            an attribute with the number of overlaps.</p>
          <p class="MsoNormal">I have already tried various things, but
            have not yet found a solution. With the "union" tool I can
            generate the overlaps as objects, but I cannot count the
            number of overlaps. </p>
          <p class="MsoNormal">I am grateful for any help and hints.</p>
          <p class="MsoNormal"> </p>
          <p class="MsoNormal">(I would like to count the overlaps to
            eventually create a heatmap. If there is a completely
            different way of doing this, I would also appreciate a tip).</p>
          <p class="MsoNormal"> </p>
          <p class="MsoNormal">Kind regards</p>
          <p class="MsoNormal">Daniela</p>
        </div>
      </div>
      <br>
      <fieldset class="moz-mime-attachment-header"></fieldset>
      <pre class="moz-quote-pre" wrap="">_______________________________________________
QGIS-User mailing list
<a class="moz-txt-link-abbreviated" href="mailto:QGIS-User@lists.osgeo.org">QGIS-User@lists.osgeo.org</a>
List info: <a class="moz-txt-link-freetext" href="https://lists.osgeo.org/mailman/listinfo/qgis-user">https://lists.osgeo.org/mailman/listinfo/qgis-user</a>
Unsubscribe: <a class="moz-txt-link-freetext" href="https://lists.osgeo.org/mailman/listinfo/qgis-user">https://lists.osgeo.org/mailman/listinfo/qgis-user</a>
</pre>
    </blockquote>
  </body>
</html>