Select to view content in your preferred language

Merging geometry and using unique ID in fields with Dashboard

265
0
01-12-2024 06:45 AM
Labels (1)
SteeveDeschenesEssipit
New Contributor

Hello,

 

I am trying to use Arcade within my Dashboard to merge a point, a line, and a polygone layer together (they all have the same fields). Many features have the same Unique ID and I need to use the DIstinct funtion so the features are counted just one time.

 

Here is my code that ChatGPT helped me with, but the AI cannot fix the problem... So I am turning to humans to help me!!! 

Here is my code: 
// Variables
var Pts = FeatureSetByPortalItem(Portal('https://cpnie.maps.arcgis.com'), 'xxxxx', 1, ['*'], false);
var Ligne = FeatureSetByPortalItem(Portal('https://cpnie.maps.arcgis.com'), 'xxxx', 0, ['*'], false);
var Polygone = FeatureSetByPortalItem(Portal('https://cpnie.maps.arcgis.com'), 'xxxx', 2, ['*'], false);

// Create empty feature array
var features = [];
var uniqueNumeroIds = new Set();

// Function to check for key existence
function hasKey(feature, key) {
    return feature && feature.attributes && feature.attributes.hasOwnProperty(key) && feature.attributes[key] !== undefined;
}

// Iterate over points
for (var pointKey in Pts) {
    var pointFeature = Pts[pointKey];

    var currentNumeroIdentification = pointFeature['NumeroIdentification'];

    if (!uniqueNumeroIds.has(currentNumeroIdentification)) {
        var feat = {
            attributes: {
                NumeroIdentification: currentNumeroIdentification,
                Date_Reception: new Date(pointFeature['Date_Reception']),
                Date_Due: new Date(pointFeature['Date_Due']),
                Date_Reponse: new Date(pointFeature['Date_Reponse']),
                Reponse_Accuse_Reception: new Date(pointFeature['Reponse_Accuse_Reception']),
                Date_demande_retroaction: new Date(pointFeature['Date_demande_retroaction']),
                Date_reception_retroaction: new Date(pointFeature['Date_reception_retroaction'])
            }
        };

        features.push(feat);
        uniqueNumeroIds.add(currentNumeroIdentification);
    }
}

// Iterate over lines
for (var lineKey in Ligne) {
    var lineFeature = Ligne[lineKey];

    var currentNumeroIdentification = lineFeature['NumeroIdentification'];

    if (!uniqueNumeroIds.has(currentNumeroIdentification)) {
        var feat = {
            attributes: {
                NumeroIdentification: currentNumeroIdentification,
                Date_Reception: new Date(lineFeature['Date_Reception']),
                Date_Due: new Date(lineFeature['Date_Due']),
                Date_Reponse: new Date(lineFeature['Date_Reponse']),
                Reponse_Accuse_Reception: new Date(lineFeature['Reponse_Accuse_Reception']),
                Date_demande_retroaction: new Date(lineFeature['Date_demande_retroaction']),
                Date_reception_retroaction: new Date(lineFeature['Date_reception_retroaction'])
            }
        };

        features.push(feat);
        uniqueNumeroIds.add(currentNumeroIdentification);
    }
}

// Iterate over polygons
for (var polygonKey in Polygone) {
    var polygonFeature = Polygone[polygonKey];

    var feat = {
        attributes: {
            NumeroIdentification: polygonFeature['NumeroIdentification'],
            Date_Reception: new Date(polygonFeature['Date_Reception']),
            Date_Due: new Date(polygonFeature['Date_Due']),
            Date_Reponse: new Date(polygonFeature['Date_Reponse']),
            Reponse_Accuse_Reception: new Date(polygonFeature['Reponse_Accuse_Reception']),
            Date_demande_retroaction: new Date(polygonFeature['Date_demande_retroaction']),
            Date_reception_retroaction: new Date(polygonFeature['Date_reception_retroaction'])
        }
    };

    features.push(feat);
    uniqueNumeroIds.add(polygonFeature['NumeroIdentification']);
}

// Convert array to a dictionary for output FeatureSet
var out_dict = {
    'fields': [
        { name: 'NumeroIdentification', type: 'esriFieldTypeString' },
        { name: 'Date_Reception', type: 'esriFieldTypeDate' },
        { name: 'Date_Due', type: 'esriFieldTypeDate' },
        { name: 'Date_Reponse', type: 'esriFieldTypeDate' },
        { name: 'Reponse_Accuse_Reception', type: 'esriFieldTypeDate' },
        { name: 'Date_demande_retroaction', type: 'esriFieldTypeDate' },
        { name: 'Date_reception_retroaction', type: 'esriFieldTypeDate' }
    ],
    'geometryType': '',
    'features': features
};

// Convert dictionary to feature set and return unique Numero d'identification.
var Uniquelist = FeatureSet(out_dict);

return Uniquelist;

 

 

Thank you very much for your help

Steeve Deschenes

0 Kudos
0 Replies