Hi Deborah Hide ,
With a couple of adjustments you get the result you are after:
var blocks = Intersects(FeatureSetByName($datastore, "Blocks"), $feature);
var cnt = Count(blocks);
var intersectArea = 0;
if (cnt > 0) {
for (var block in blocks) {
intersectArea += Area(Intersection($feature, block), "hectare");
}
}
return Round(intersectArea, 2);
Which will result in:
Notice that I switched off the Union (a union requieres two or more geometries to be successful) since this would make the processing time larger. I recommend you not to use it unless your blocks are regions and have overlap. If this is not the case, you do not need it.
You can also enhance the result by including more information, for instance the percentage of the area that has overlap with the blocks and perhaps information of the blocks that overlap. See below (I blurred parts of it since I don't know if it contains sensitive data):
To do this, you would need the expression below:
var blocks = Intersects(FeatureSetByName($datastore, "Blocks"), $feature);
var cnt = Count(blocks);
var intersectArea = 0;
if (cnt > 0) {
var blocknames = "Block names:";
for (var block in blocks) {
intersectArea += Area(Intersection($feature, block), "hectare");
blocknames += TextFormatting.NewLine + " - " + block.extent;
}
var zoneArea = Area($feature, "hectare");
var percentage = Round(intersectArea * 100.0 / zoneArea, 1);
var result = cnt + " Building block(s) found:"
result += TextFormatting.NewLine + " - Test Area : " + Round(zoneArea, 2) + " ha.";
result += TextFormatting.NewLine + " - Overlap Area: " + Round(intersectArea, 2) + " ha.";
result += TextFormatting.NewLine + " - Percentage Overlap: " + percentage + "%";
result += TextFormatting.NewLine + blocknames;
return result;
} else {
return "No overlap with building blocks..."
}