Converting VB Script for Labelling to Arcade

2348
14
Jump to solution
07-09-2019 11:57 AM
WilliamDelmar
New Contributor II

I have the following VB Script expression for labeling hatches. It worked just fine in ArcMap. As I am now using ArcGIS Pro, I would like some help converting it to Arcade.

Function FindLabel ( esri__measure )

segLen = esri__measure

if  right(int((segLen *3.2808399)),2) = 0 then

  lblStation= int((segLen *3.2808399)/100) & "+00"

else

  lblStation = int((segLen *3.2808399)/100) & "+" &  right(int(segLen *3.2808399),2)

end if

 

  FindLabel = lblStation

 

End Function

0 Kudos
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

Hi William Delmar ,

I was able to connect to the data and I see what you mean. The field reference I proposed has a fixed reference to the length of the line. There is a special reference that points to the measurement: $measure.

Your code would look like this:

var segLen = Round($measure * 3.2808399, 0);
return Round((segLen - (segLen % 100)) / 100, 0) + Text(segLen % 100, "+00");

Resulting in:

View solution in original post

14 Replies
XanderBakker
Esri Esteemed Contributor

Hi WDelmar , 

I think you should be able to do something like this:

var segLen = Round(LengthGeodetic($feature, 'feet'), 0);
return Round((segLen - (segLen % 100)) / 100, 0) + Text(segLen % 100, "+00");
‍‍
0 Kudos
WilliamDelmar
New Contributor II

Mr. Bakker,

Thank you. I will give it a try.

WilliamDelmar
New Contributor II

When I tried the expression, I received an error of:

Invalid expression.

Error on line 1.

Projection is invalid

I altered line 1 to read:

var segLen = Round(Length($feature, 'feet'), 0);

And it returned a result of:

Expression is valid.

When I ran the expression, my labels read all the same number. Is there a way to have the resulting number change based on the distance from the beginning of the line?

Thanks.

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi William Delmar ,

Can you explain what projection your data has? You mention that all your labels read the same number. What is that number? Your original VB script used esri__measure. Is that value (attribute) available in the data in the web map? I guess you have points and want to show the measurement based on that value, right? And the value is in meters and you need to translate that to feet?

0 Kudos
WilliamDelmar
New Contributor II

Can you explain what projection your data has?

They were drawn in the Projected Coordinate System: NAD 1983 UTM Zone 15N, Projection: Transverse Mercator, WKID: 26915; with Geographic Coordinate System: GCS North American 1983, WKID: 4269.

What is that number?

The number on the labels is 1076+61. This appears to be the total length of the line when converted into feet and further converted into a method of stationing that is used for roadways and levees.

Your original VB script used esri__measure. Is that value (attribute) available in the data in the web map?

The esri__measure is the Shape Length of the lines drawn. The data is located in the map, though not currently a web map.

I guess you have points and want to show the measurement based on that value, right? And the value is in meters and you need to translate that to feet?

I am using existing data that is centerlines for levees. We collected observations that use the measurement along this line as a reference for points and lines along the centerline.

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi William Delmar , 

Is it possible to share a sample of your data? Or create a group in ArcGIS Online and invite me to that group (using xbakker@esri.co_utility_esri_co) and share the sample of the data in that group? It is so much easier if I can see and interact with the data.

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi WDelmar , 

Before you share your data, could you try this:

var segLen = Round($feature["Shape__Length"] * 3.2808399, 0);
return Round((segLen - (segLen % 100)) / 100, 0) + Text(segLen % 100, "+00");
0 Kudos
WilliamDelmar
New Contributor II

Here is a link to the group that was created. https://arcg.is/GPKiX

Hopefully, it works.

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi WDelmar ,

It seems that you shared layer package, but I think I can open it in ArcGIS Pro and publish it in my portal for the moment to understand the data you have. It seems the data source is still pointing to your SQL Server database and I don't have access to that. 

Is the data stored in the Enterprise Geodatabase and you are creating a web map consuming the service?

0 Kudos