0

My question is similar to Performing multiple layer intersection in QGIS?

However, there are a few differences. I have run a test analysis on a dummy data set and cannot replicate the result with my real larger data set.

Dummy data - polygons intersecting other polygons with intersect table

I have a list of environmental features that are potentially at risk (streams, fish, amphibians, red listed species, ungulate winter range, etc) that I have merged into a single omnibus layer. I have another polygon study area that consists of the threat (roads and storm water outlets - high salt application area). My goal is to study the intersection between the at-risk-layer and the threat-layer and to obtain a count of the number of at-risk-features that intersect with the threat. In the dummy example everything works just fine (see figure above). The next image is from my real data set.

Polygons with intersection table

This looks more complicated. The brownish layer is the merged polygon of streams, wellsites, amphibians, fish in streams, agricultural lands, ungulate winter range, etc... The light grey layer is the study area (roads and stormwater outfalls). The RskCnt field is a sum of all the fields with string data attached. I created multiple fields by running the following:

CASE
   WHEN "ALR" LIKE '%' THEN 1
   ELSE 0
END

Then I added all the fields to get the count:

WellID_n + GrndH2O_n + redlist_n + bluelist_n + wetland_n + riparian_n + uwr_n + Amphib_n + Hydro_n + Fish_n + ALR_n

However, I know that the counts are wrong. There are places where I should have more than a count of 3, because I can look at the individual layers that were not merged and determine that the count is wrong. The merging is not capturing all the fields. The fields are there, but not all the information is getting passed along.

What could be going wrong here?

The difference is that I didn't merge layers in the dummy case, so that's a clue. There must be something going wrong with the merge...but I can't seem to figure this out.

  • 1
    Have you tried to create a virtual layer where count is part of the sql ie select a. id , count(*) from tableA as a join tableB on st_intersects(a.$geometry,b.$geometry) you can figure out the rest I would have tested this but I am not in front of a computer – kartoza-geek May 25 at 1:08
  • I have just started to learn about SpatialLite where I believe your response applies. It looks like a workable solution. However, I believe that my problem may have been something more fundamental, simple, and embarrassingly overlooked. I was merging, when I should have been taking the union! I'll post an answer when this is done, because I've seen this type of question pop-up here - but I have not seen a full, adequate, or comprehensive answer. – Mark Thompson May 27 at 17:53
  • I have solved this problem for a number of my layers, but ran into the problem as described on this Bug report thread: issues.qgis.org/issues/21584 -> I get "GEOS geoprocessing error: difference failed. Execution failed after 6212.42 sections" It still loads the layer, but the result is incomplete. I'm downloading QGIS 2.18 to see if this will solve the problem. I'll add a complete response once it's all sorted out. – Mark Thompson May 31 at 15:56
  • QGIS 2.18 did not solve the problem. The processing error continues. I'm trying to break the data into pieces to see if this will help, but it doesn't seem to be working. – Mark Thompson May 31 at 21:18
  • I've posted my question and shared my data to a bug report that has been issued on this problem. github.com/qgis/QGIS/issues/29400 (I'm user technoautotroph in github. – Mark Thompson Jun 3 at 20:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.