VxCount = !shape!.pointcount fuction in AGOL

1565
7
Jump to solution
06-07-2019 10:07 AM
GeoPolar
New Contributor III

Hi everyone!

it is possible to make an arcade expression from VxCount = !shape!.pointcount Python expression?

This Arcmap/ArcGIS Pro python expression allow to show the total number of vertices of a Feature Class. but what about AGOL Environment?

Thanks! 

0 Kudos
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

The example I provided was just to test the function. The return statement at the end of the expression returns OK. You will have to use something like this to make it work:

Function CountVertices(geom) {
    var cnt_vertices = Null;
    var geom_type = TypeOf(geom);
    Console(geom_type);
    if (geom_type == "Point") {
        cnt_vertices = 1;
    } else if (geom_type == "Multipoint") {
        cnt_vertices = Count(geom.points);
    } else if (geom_type == "Polyline") {
        var cnt_line = 0;
        for (var i = 0; i < Count(geom.paths); i++) { 
            cnt_line += Count(geom.paths[i]);
        }
        cnt_vertices = cnt_line;
    } else if (geom_type == "Polygon") {
        var cnt_pol = 0;
        for (var i = 0; i < Count(geom.rings); i++) { 
            cnt_pol += Count(geom.rings[i]);
        }
        cnt_vertices = cnt_pol;
    } else {
        // this should not happen...    
    }
    return cnt_vertices;
}


return CountVertices(Geometry($feature));

View solution in original post

7 Replies
XanderBakker
Esri Esteemed Contributor

Hi Miguel Angel Barrientos Martinez , 

You mention that this expression will calculate the vertices of a feature class, but I assume you are mean a feature, since that is what the python expression will do.

In Arcade you can determine the number of vertices, but the expression will probably be different depending the type of geometry you have. On what type of geometry do you want to apply the Arcade expression?

Have a look at the following function:

Function CountVertices(geom) {
    var cnt_vertices = Null;
    var geom_type = TypeOf(geom);
    Console(geom_type);
    if (geom_type == "Point") {
        cnt_vertices = 1;
    } else if (geom_type == "Multipoint") {
        cnt_vertices = Count(geom.points);
    } else if (geom_type == "Polyline") {
        var cnt_line = 0;
        for (var i = 0; i < Count(geom.paths); i++) { 
            cnt_line += Count(geom.paths[i]);
        }
        cnt_vertices = cnt_line;
    } else if (geom_type == "Polygon") {
        var cnt_pol = 0;
        for (var i = 0; i < Count(geom.rings); i++) { 
            cnt_pol += Count(geom.rings[i]);
        }
        cnt_vertices = cnt_pol;
    } else {
        // this should not happen...    
    }
    return cnt_vertices;
}

var pt = Point({ 'x': 100, 'y': 100, 'spatialReference':{'wkid':102100} });
var line = Polyline({ 'paths' : [ [ [-97.06138,32.837], [-97.06133,32.836], [-97.06124,32.834], [-97.06127,32.832] ],  [ [-97.06326,32.759], [-97.06298,32.755] ] ] , 'spatialReference':{'wkid':102100}});
var poly = Polygon(Polygon({'rings' : [ [ [-97.06138,32.837], [-97.06133,32.836], [-97.06124,32.834], [-97.06127,32.832], [-97.06138,32.837] ],  [ [-97.06326,32.759], [-97.06298,32.755], [-97.06153,32.749], [-97.06326,32.759] ] ], 'spatialReference':{'wkid':102100}}));
var mp = Multipoint({ 'points' : [ [-97.06138,32.837], [-97.06133,32.836], [-97.06124,32.834], [-97.06127,32.832] ], 'spatialReference':{'wkid':102100} });

Console(CountVertices(pt));
Console(CountVertices(mp));
Console(CountVertices(line));
Console(CountVertices(poly));

return "OK";

This will print the following information to the Console with the provided test geometries:

Point
1
Multipoint
4
Polyline
6
Polygon
9
GeoPolar
New Contributor III

Hi Xander! put this code in custom expression label box in AGOL but all labels created was "OK" butg none with vertex count. BTW this expression is related with a Poliline Feature Class, no Polygon or points.  Thanks Xander for your quick response. 

0 Kudos
GeoPolar
New Contributor III

ok labels

0 Kudos
XanderBakker
Esri Esteemed Contributor

The example I provided was just to test the function. The return statement at the end of the expression returns OK. You will have to use something like this to make it work:

Function CountVertices(geom) {
    var cnt_vertices = Null;
    var geom_type = TypeOf(geom);
    Console(geom_type);
    if (geom_type == "Point") {
        cnt_vertices = 1;
    } else if (geom_type == "Multipoint") {
        cnt_vertices = Count(geom.points);
    } else if (geom_type == "Polyline") {
        var cnt_line = 0;
        for (var i = 0; i < Count(geom.paths); i++) { 
            cnt_line += Count(geom.paths[i]);
        }
        cnt_vertices = cnt_line;
    } else if (geom_type == "Polygon") {
        var cnt_pol = 0;
        for (var i = 0; i < Count(geom.rings); i++) { 
            cnt_pol += Count(geom.rings[i]);
        }
        cnt_vertices = cnt_pol;
    } else {
        // this should not happen...    
    }
    return cnt_vertices;
}


return CountVertices(Geometry($feature));
XanderBakker
Esri Esteemed Contributor

Hi GeoPolar 

Any luck with the new expression I shared?

GeoPolar
New Contributor III

Amazing!!!! thank You Xander Bakker ! This was just what I was looking for!

XanderBakker
Esri Esteemed Contributor

I'm glad it worked!