Populate "State" based on the origin of the polyline feature...

341
2
Jump to solution
10-11-2020 10:38 PM
ShahriarRahman
New Contributor III

This script works fine,

return First(Intersects(FeatureSetByName($datastore, “DIVISION_WITH_POSTCODE”, [“STATE”], False, $feature)).STATE;

………………….

But, some part of the polyline feature is shared between two state boundaries, and with the above script, the state (sorted alphabetically) is populated. Without the “First” function, it populates the last state (reverse alphabetically). I need to populate the state name based on the origin of the line feature. As from one of the Xander’s posts I got that “…Arcade does not have access to the location where you clicked and will use the entire feature geometry…”. I am wondering is it possible to populate the state based on the origin (starting point) of the polyline feature? Nice if you please can share any sample script or great to have your suggestion. I appreciate any help you can provide.

 

Kind regards,

Shahriar

0 Kudos
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

Hi srahman ,

It is possible to get the start point of a line using its json definition and intersect that point with your polygons. Have a look at the expression below:

// get the geometry of the line
var line = Geometry($feature);

// the json of the first point can be accessed like this:
var json = line["paths"][0][0];
//{"spatialReference":{"latestWkid":3857,"wkid":102100},"x":-8406060.52628989,"y":674888.746493517}

// create a point from this first point json
var pnt = Point(json);

// access the polygon layer
var pols = FeatureSetByName($map,"Colombia Censo 2018 Población a Nivel de Municipio");

// intersect the polygon layer with the point and take the "first" polygon
var pol = First(Intersects(pols, pnt));

// get the name of the polygon using the field name
var startmuni = pol["MPIO_CNMBR"];

// return the result
return startmuni;

View solution in original post

2 Replies
XanderBakker
Esri Esteemed Contributor

Hi srahman ,

It is possible to get the start point of a line using its json definition and intersect that point with your polygons. Have a look at the expression below:

// get the geometry of the line
var line = Geometry($feature);

// the json of the first point can be accessed like this:
var json = line["paths"][0][0];
//{"spatialReference":{"latestWkid":3857,"wkid":102100},"x":-8406060.52628989,"y":674888.746493517}

// create a point from this first point json
var pnt = Point(json);

// access the polygon layer
var pols = FeatureSetByName($map,"Colombia Censo 2018 Población a Nivel de Municipio");

// intersect the polygon layer with the point and take the "first" polygon
var pol = First(Intersects(pols, pnt));

// get the name of the polygon using the field name
var startmuni = pol["MPIO_CNMBR"];

// return the result
return startmuni;
ShahriarRahman
New Contributor III

Thank you, Xander Bakker‌. Great help. The script you shared works perfectly fine.