create point from center of line using arcade

3371
7
09-10-2017 08:43 PM
NathanMcKinley3
New Contributor

Does anyone know if you can create point symbology from the center coordinate of a line feature using arcade?

0 Kudos
7 Replies
DanielHuneycutt
New Contributor II

I'm currently working on this for polygon features.

Using:

POINT (Centroid(Geometry($feature)))

But getting this error:

Execution Error:Cannot create Geometry in this SpatialReference. Engine is using a different spatial reference.
XanderBakker
Esri Esteemed Contributor

I don't think you can use Arcade to visualize polylines as points. The error message seems to refer to the spatial reference. I did a simple test on a hosted feature that I published using the same spatial reference as the base map and it returned the point:

var geom = Geometry($feature);
Console('\ngeom:' + geom);

var line = Polyline(geom);
Console('\nline:' + line);

var cent = Centroid(line);
Console('\ncent:' + cent);

var pnt = Point(cent);
Console('\npnt:' + pnt);‍‍‍‍‍‍‍‍‍‍‍

return pnt;

Which yields:

geom:{"paths":[[[-8414259.482734734,697445.4680427602],[-8414258.288406167,697445.4680427602],[-8414258.288406167,697457.4113284288]]],"spatialReference":{"wkid":102100,"latestWkid":3857}}

line:{"paths":[[[-8414259.482734734,697445.4680427602],[-8414258.288406167,697445.4680427602],[-8414258.288406167,697457.4113284288]]],"spatialReference":{"wkid":102100,"latestWkid":3857}}

cent:{"x":-8414259.482734734,"y":697445.4680427602,"spatialReference":{"wkid":102100,"latestWkid":3857}}

pnt:{"x":-8414259.482734734,"y":697445.4680427602,"spatialReference":{"wkid":102100,"latestWkid":3857}}

So it returns the point, but the symbology will no be what you want (they will remain lines, and you will have an object for your symbology that you cannot actually use):

0 Kudos
Amanda__Huber
MVP Regular Contributor

@XanderBakker

In theory, if you use feature sets with this workflow could you use arcade on a separate point layer to represent the centroid of this line layer?

We're looking to do the same thing, but curious on your thoughts as we get started. 

 

Thanks!

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi @Amanda__Huber ,

So in the symbology profile, Arcade could return a geometry, but this is not something that is valid and that can be used to draw those features. Can you elaborate a bit more on what you have and what you want to get (and explain the why in this a bit more)?

0 Kudos
Amanda__Huber
MVP Regular Contributor

Hi @XanderBakker ,
Of course, thanks for the quick reply!
We're looking to visualize construction features (lines and polygons hosted the same service) as points on the map at high scales.
I know arcade built into the symbology setting doesn't support feature sets, but I was thinking since I have a point layer in the map, if there's a way to use the Point ( json ) (returns { Point }) function by getting the X,Y of the line/poly centroid through feature sets then it could be visualized through that layer. Thoughts?

Thanks again!

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi @Amanda__Huber ,

As far as I know, that is not possible using Arcade. If you would have Enterprise (or ArcGIS Pro) you could use  Arcade in attribute rules to automatically maintain another point layer where the center points would be stored. In the map, you would have to add the point layer and define visibility based on the scale. 

For ArcGIS Online, I would probably use ArcGIS Pro and the Feature to Point tool to create the layer or use the Find Locations | Find Centroids (consumes credits) in ArcGIS Online to create the point layer. 

0 Kudos
Bud
by
Notable Contributor

I'm not sure if this will be helpful or not, but I'll post it anyway:

In similar situations where we don't have a Midpoint() function, such as in the St_Geometry spatial type in EGDBs, we've used the following hack:

Buffer the line and get the centroid of the resulting polygon. It's kind of like a "poor man's midpoint".

If I recall, that works ok. But I think I remember the point not being the exact midpoint of the line. I forget what the specific issue was. It's probably good enough for most use cases though...