Select to view content in your preferred language

How to make data expression that finds intersecting features faster?

3518
11
01-25-2023 04:40 AM
Labels (1)
NygrenOhto
Occasional Contributor

How can I make the following data expression faster? I have a feature layer with 5500 rows and another one with 3175 and it takes this script 5:30 minutes to run through. That's way too long.

 

I am trying to create an indicator that compares data from two different years in certain areas in a city by checking intersecting population data squares with regions of a city.

 

 

var portal = Portal("https://arcgisportal.xxxx.fi/arcgis/");
var areas = FeatureSetByPortalItem(portal, 'xxxx719ebb25xxxx968694axxxxxxxx', 3, ['*'], true);
var sql = "area_name = 'xxxxxxx'";
var filtAreas = Filter(areas, sql);

var stat2021 = FeatureSetByPortalItem(portal, 'xxx8abda0xxxx483xxxxxxxx', 0, ['he_vakiy'], true);
var sql2 = "he_vakiy > 0"
var stat = Filter(stat2021, sql2)

//var stat = Intersection(stat, filtAreas)

var features = [];
var feat;

for (var poly in stat) {
//Console(poly)
var pts = Count(Intersects(poly, filtAreas));
Console(pts)
feat = {
'attributes': {
'he_vakiy': poly['he_vakiy']

}
};

// Push feature into array
If(pts > 0){
Push(features, feat);
}
};
// Create dict for output FeatureSet
var out_dict = {
'fields': [
{'name': 'he_vakiy', 'alias': 'population', 'type': 'esriFieldTypeInteger'}
],
'geometryType': '',
'features': features
};

// Convert dictionary to feature set.
return FeatureSet(Text(out_dict));

 

 

0 Kudos
11 Replies
NygrenOhto
Occasional Contributor

I tried this change as well, but it didn't make any significant changes to the speed. I didn't time it but based on how long it felt.

Thanks for the help!

-Ohto

0 Kudos
NygrenOhto
Occasional Contributor

I managed to make it A LOT faster by using Disjoint() instead of Intersect().

Sample:

var portal = Portal("https://arcgisportal.xxxxxx.xxx/arcgis/");
var areas = FeatureSetByPortalItem(portal, 'xxxxxxebb254f1xxxx9xxxx1cdfxxx', 3, ['*'], true);
var sql = "area_name = 'xxxxxx'";
var filtAreas = Filter(areas, sql);

var stat2021 = FeatureSetByPortalItem(portal, 'xxxxbda0144xxxx3e8476d6xxxx', 0, ['he_vakiy'], true);
var sql2 = "he_vakiy > 0"
var stat = Filter(stat2021, sql2)


var features = [];
var feat;

for (var poly in stat) {
    for (var filtArea in filtAreas)
    {
        //Console(poly)
        If(Disjoint(poly, filtArea)) {
            continue;
        }
        feat = { 
            'attributes': { 
                'he_vakiy': poly['he_vakiy']
            
            }
        };
        
        Push(features, feat);
    }
    
    
    
    // Push feature into array
    
    
};
// Create dict for output FeatureSet
var out_dict = { 
    'fields': [
        {'name': 'he_vakiy', 'alias': 'population', 'type': 'esriFieldTypeInteger'}
    ],
  'geometryType': '', 
  'features': features 
}; 

// Convert dictionary to feature set. 
return FeatureSet(Text(out_dict)); 

 

-Ohto

 

 

0 Kudos