Validation rule for finding overlaps between a number of different datasets

366
2
Jump to solution
04-03-2023 03:18 PM
Aнастасия88
Occasional Contributor

Hello people,

Just seeking a better way of detecting overlaps between a number of different datasets by validation rule.

I have a database that contains hundreds of datasets. I have a code for detecting overlaps between different datasets - see below. But in the code, I have to create "Intersects" function for each pair of datasets to detect overlaps. As there are heaps of datasets in the database, I would like to avoid creating heaps of lines for the geometry function. Is there any more sophisticated way of coding to detect overlaps between hundreds of different datasets?

Thanks in advance for your ideas!

 

// Validation - overlaps
var poly_b = FeatureSetByName($datastore, "polygon_b", ["*"], false)
var poly_b_intersect = Intersects(poly_b, Geometry($feature))

var line_a = FeatureSetByName($datastore, "line_a", ["*"], false)
var line_a_intersect = Intersects(line_a, Geometry($feature))

var polygon_c = FeatureSetByName($datastore, "polygon_c", ["*"], false)
var polygon_c_intersect = Intersects(polygon_c, Geometry($feature))

// return error if $feature intersect any polygon A
if (Count(poly_b_intersect) > 0 || Count(line_a_intersect) > 0 || Count(polygon_c_intersect) > 0)
    return {"errorMessage": "polygon A features must not be intersected with others."}
else
    return true
0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

You will have to write the code for loading the featuresets, but you can do the intersection in a loop.

var test_featuresets = [
    FeaturesetByName($datastore, "line_a", ["*"], false),
    FeaturesetByName($datastore, "polygon_b", ["*"], false),
    FeaturesetByName($datastore, "polygon_c", ["*"], false),
]

for(var i in test_featuresets) {
    var inter = First(Intersects(test_featuresets[i], $feature))
    if(inter != null) {
        return {"errorMessage": "polygon A features must not be intersected with others."}
    }
}
return true

 

 

Sidenote: Not too sure about that, but I think you have to return a boolean. errorMessage is for Calculation rules. So you probably want to change the return to false and input the error message in the Validation rule window.


Have a great day!
Johannes

View solution in original post

2 Replies
JohannesLindner
MVP Frequent Contributor

You will have to write the code for loading the featuresets, but you can do the intersection in a loop.

var test_featuresets = [
    FeaturesetByName($datastore, "line_a", ["*"], false),
    FeaturesetByName($datastore, "polygon_b", ["*"], false),
    FeaturesetByName($datastore, "polygon_c", ["*"], false),
]

for(var i in test_featuresets) {
    var inter = First(Intersects(test_featuresets[i], $feature))
    if(inter != null) {
        return {"errorMessage": "polygon A features must not be intersected with others."}
    }
}
return true

 

 

Sidenote: Not too sure about that, but I think you have to return a boolean. errorMessage is for Calculation rules. So you probably want to change the return to false and input the error message in the Validation rule window.


Have a great day!
Johannes
Aнастасия88
Occasional Contributor

Thanks Johannes for the good ideas!

The errorMessage is the legacy of calculatoin rule that I also prepared - thanks for pointing out.

0 Kudos