# VxCount = !shape!.pointcount fuction in AGOL

850
7
06-07-2019 10:07 AM by
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!

1 Solution

Accepted Solutions by 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));‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍``````
7 Replies by Esri Esteemed Contributor

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‍‍‍‍‍‍‍‍`````` by
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. by
New Contributor III  by 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));‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍`````` by Esri Esteemed Contributor

Hi GeoPolar

Any luck with the new expression I shared? by
New Contributor III

Amazing!!!! thank You Xander Bakker ! This was just what I was looking for! by Esri Esteemed Contributor 