ArcGIS Dashboard Using Arcade to union two datasets (featureLayers)

1577
3
09-13-2022 05:52 AM
Labels (2)
LarsChristianØstgaard
New Contributor III

Hi

I want to display a table in ArcGIS Dashboard that contains data from two different featureLayers (datasets).

- I cannot use the Merge-functionality in ArcGIS Pro because the first featureLayers using geopoint, while the second featureLayer using polylines.

- Therefore I am trying to make an Arcade DataExpression to create a dictionary consising of data from the two different featureLayers.

- The two featureLayers both include the same fields ['objectid','CreationDate','Creator','formStatus','nettniva','id','komponenttype','driftsmerking','message','globalid','classid','spenning']

- I am NOT using any filtering inside the Arcade-expression other than only selecting the fields I want to display in the table.

- I then want to use the ArcadeExpression in both a table and indicator widget (if possible) in the ArcGIS Dashbord.

- When I use "return fs1;" I get data from my first featureLayer. This works but its not what I want., see the attached image "Image1 fs1.png".

- When I use "return fs2;" I get data from my second featureLayer. This works but its not what I want., see the attached image "Image2 fs2.png".

- But when I use "return FeatureSet(Text(dict));" I only get a empty dictionary, see the attached image "Image3 empty dictionary.png".

 

Is there any easier solution to this problem?

If not, can you see any errors in my Arcade Expression?

Since Im new to Arcade I may need a detailed description, but appreciate any tips 🙂

 

 

 

//Totalt antall rapporterte avvik Tabell

//ArcGIS Portal
var p = Portal('https://kraftnett.maps.arcgis.com');
//var all_fields = ['objectid','CreationDate','Creator','formStatus','nettniva','id','komponenttype','driftsmerking','message','globalid','classid','spenning']

//Feature: PointObject
var itemID_points = 'fbf01e5a639a4a3ea335e089652c109a';
var layerID_points = 0;
var fields_points = ['objectid','globalid','creationdate','creator','formStatus','nettniva','komponenttype'];

//Pull PointObject data
var fs1 = FeatureSetByPortalItem(p, itemID_points, layerID_points, fields_points, false);

//Create empty dictionary
var dict = {
    'fields': [
        {'name': 'ObjectId', 'type': 'esriFieldTypeInteger'},
        {'name': 'GlobalId', 'type': 'esriFieldTypeString'},
        {'name': 'CreationDate', 'type': 'esriFieldTypeDate'},
        {'name': 'Creator', 'type': 'esriFieldTypeString'},
        {'name': 'FormStatus', 'type': 'esriFieldTypeString'},
        {'name': 'Nettniva', 'type': 'esriFieldTypeString'},
        {'name': 'KomponentType', 'type': 'esriFieldTypeString'}
        ],
    'geometryType': '',
    'features': []
};

var index = 0;
//Loop through and add PointFeature data to dictionary
for (var feature in fs1) {
    dict.features[index++] = {
        'attributes': {
            'objectid': feature['objectid'],
            'globalid': feature['globalid'],
            'creationdate': feature['creationdate'],
            'creator': feature['creator'],
            'formStatus': feature['formStatus'],
            'nettniva': feature['nettniva'],
            'komponenttype': feature['komponenttype']
        }
    }
};

//Feature: LineObjects
var itemID_lines = '24481a7dc6d342db9c5b43cc8af9b8c1';
var layerID_lines = 0;
var fields_lines = ['objectid','globalid','creationdate','creator','formStatus','nettniva','komponenttype'];

//Pull LineObject data
var fs2 = FeatureSetByPortalItem(p, itemID_lines, layerID_lines, fields_lines, false);

//Loop through and add PointFeature data to dictionary
for (var feature in fs2) {
    dict.features[index++] = {
        'attributes': {
            'objectid': feature['objectid'],
            'globalid': feature['globalid'],
            'creationdate': feature['creationdate'],
            'creator': feature['creator'],
            'formStatus': feature['formStatus'],
            'nettniva': feature['nettniva'],
            'komponenttype': feature['komponenttype']
        }
    }
};

//Return result
//return fs1;
return FeatureSet(Text(dict));
//return dict;
//return [fs1, fs2]

 

 

Regards Lars

 

 

3 Replies
LarsChristianØstgaard
New Contributor III

I found a solution to this problem.

The problem was that the date field was really a datetime field (containing day, month year, hour, minute, second, nanosecond.. So the whole output failed to be displayed due to the creationdate field in datetime was not in esriFieldTypeDate format.

The solution was to create a new field and convert the datetime (yyyy-MM-dd HH:mm:ss.SSS) to date (yyyy-MM-dd HH:mm:ss) and casting this in a esriFieldTypeDate format.

 

//Totalt antall rapporterte avvik Tabell * Virker

// Portal
var p = Portal('https://kraftnett.maps.arcgis.com');

// Create FeatureSet for points
var fs1 = FeatureSetByPortalItem(p,'fbf01e5a639a4a3ea335e089652c109a', 0, ['globalid','objectid','komponenttype','nettniva','formStatus','creator','CreationDate','id','driftsmerking','message','classid','spenning'], true);

// Create Featureset for lines
var fs2 = FeatureSetByPortalItem(p,'24481a7dc6d342db9c5b43cc8af9b8c1', 0 ,['globalid','objectid','komponenttype','nettniva','formStatus','creator','CreationDate','id','driftsmerking','message','classid','spenning'], true);

// Create empty feature array and feat object for output
var features = [];
var feat;

// Iterate fs1
for (var feature in fs1) {
    
    // Filter points by polygon
    //var pts = Contains(feature, fs2);
    
    // Create feature with aggregated values
    feat = { 
        'attributes': { 
            'objecttype': ['PointObject'],
            'objectid': feature['objectid'],
            'globalid': feature['globalid'],
            'komponenttype': feature['komponenttype'],
            'nettniva': feature['nettniva'],
            'formStatus': feature['formStatus'],
            'creator': feature['creator'],
            'creationdate': feature['CreationDate'],
            '_creationdate': Number(Date(Year(feature['CreationDate']), Month(feature['CreationDate']), Day(feature['CreationDate']))),
            'id': feature['id'],
            'driftsmerking': feature['driftsmerking'],
            'message': feature['message'],
            'classid': feature['classid'],
            'spenning': feature['spenning']
        }
    };
    
    // Push feature into array
    Push(features, feat);
};

for (var feature in fs2) {
    
    // Filter points by polygon
    //var pts = Contains(feature, fs2);
    
    // Create feature with aggregated values
    feat = { 
        'attributes': { 
            'objecttype': ['LineObject'],
            'objectid': feature['objectid'],
            'globalid': feature['globalid'],
            'komponenttype': feature['komponenttype'],
            'nettniva': feature['nettniva'],
            'formStatus': feature['formStatus'],
            'creator': feature['creator'],
            'creationdate': feature['CreationDate'],
            '_creationdate': Number(Date(Year(feature['CreationDate']), Month(feature['CreationDate']), Day(feature['CreationDate']))),
            'id': feature['id'],
            'driftsmerking': feature['driftsmerking'],
            'message': feature['message'],
            'classid': feature['classid'],
            'spenning': feature['spenning']
        }
    };
    
    // Push feature into array
    Push(features, feat);
};

// Create dict for output FeatureSet
var out_dict = { 
    'fields': [
        {'name': 'objecttype', 'type': 'esriFieldTypeString'},
        {'name': 'objectid', 'type': 'esriFieldTypeOID'},
        {'name': 'globalid', 'type': 'esriFieldTypeGlobalID'},
        {'name': 'komponenttype', 'type': 'esriFieldTypeString'},
        {'name': 'nettniva', 'type': 'esriFieldTypeString'},
        {'name': 'formStatus', 'type': 'esriFieldTypeString'},
        {'name': 'creator', 'type': 'esriFieldTypeString'},
        {'name': 'creationdate', 'type': 'esriFieldTypeString'},
        {'name': '_creationdate', 'type': 'esriFieldTypeDate'},
        {'name': 'id', 'type': 'esriFieldTypeString'},
        {'name': 'driftsmerking', 'type': 'esriFieldTypeString'},
        {'name': 'message', 'type': 'esriFieldTypeString'},
        {'name': 'classid', 'type': 'esriFieldTypeString'},
        {'name': 'spenning', 'type': 'esriFieldTypeString'}
    ],
  'geometryType': '', 
  'features': features 
}; 



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

 

 

 

 

DavidNyenhuis1
Esri Contributor

With this week's update to Arcade and ArcGIS Dashboards, date fields in feature set constructors now just work. You no longer have to wrap dates with Number() if you pass the dictionary into the FeatureSet() function (which as of this release accepts a dictionary as opposed to only text based JSON).

Instead of:

return FeatureSet(Text(dict))

Do this:

return FeatureSet(dict)

Learn more in this blog post

NOTE: For Enterprise users, this update is targeted for 11.2

LarsChristianØstgaard
New Contributor III

Thanks for the update, I will try this

0 Kudos