Hi
I want to union/combine two feature layers and display the dombined feature layer as a table in ArcGIS Dashboard.
I cannot use union/merge function in ArcGIS Pro because the two feature layers are using different geographic objects (points and lines)
I do not want to make any filtering inside the arcade expression.
Can someone post an template to the arcade expression on how to do that using FeatureSetByPortalItem or similar?
Appreciate all help
Solved! Go to Solution.
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));
Take a look at the Data Expressions in this GitHub repo: https://github.com/Esri/arcade-expressions/blob/master/dashboard_data/SpatialAggregation.md
There are a number of examples, the one linked above specifically showing how to spatially aggregate two layers in an expression. It's not exactly what you're looking to do, but would be a good place to start.
Hi @jcarlson
Thanks
I have tried this one:
As far I can see I only populate data from the fs1 featurelayer, and it should show the data, but the result is an empty dictionary. And it contains data.
Can you see something wrong in the code?
If not I can try and share the layers.
// Portal
var p = Portal('https://kraftnett.maps.arcgis.com');
// Create FeatureSet for points
var fs1 = FeatureSetByPortalItem(
p,
'fbf01e5a639a4a3ea335e089652c109a',
0,
[
'objectid','globalid','creationdate','creator','formStatus','nettniva','komponenttype'
],
false
);
// Create Featureset for lines
var fs2 = FeatureSetByPortalItem(
p,
'24481a7dc6d342db9c5b43cc8af9b8c1',
0,
[
'objectid','globalid','creationdate','creator','formStatus','nettniva','komponenttype'
],
false
);
// 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': {
'objectid': feature['objectid'],
'globalid': feature['globalid'],
'creationdate': feature['creationdate'],
'creator': feature['creator'],
'formStatus': feature['formStatus'],
'nettniva': feature['nettniva'],
'komponenttype': feature['komponenttype']
}
};
// Push feature into array
Push(features, feat);
};
// Create dict for output FeatureSet
var out_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': features
};
// Convert dictionary to feature set.
return FeatureSet(Text(out_dict));
The result is an empty dictionary:
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));
Do y'all know if there is a way to call in both feature layers in one call using something like this?
// Portal
var p = Portal('https://kraftnett.maps.arcgis.com');
// Create FeatureSet for points
var fs1andfs2 = FeatureSetByPortalItem(p,'fbf01e5a639a4a3ea335e089652c109a', [0,1],[*], true);
// Create empty feature array and feat object for output
var features = [];
var feat;
I am trying to use this too and I think this may greatly speed up my dashboard if it is possible.
I should say this is for two layers that are apart of the same service.