Select to view content in your preferred language

Survey123 Arcade Expression join multiple polylines

1397
3
Jump to solution
05-31-2021 09:19 AM
PaulSweeney3
Frequent Contributor

Hi All 

 

I am trying to create an arcade expression that returns a URL to populate a survey123 form with a single path from numerous polylines with a common attribute, ordered by a segment id field. so basically I have multiple polylines to be converted into one long polyline and to be passed it into the survey123 form. 

 

var mainTable= OrderBy(FeatureSetByPortalItem(Portal('https://tlilimerick.maps.arcgis.com/'),'xxxxxxxxx', 0),'Segment')
var Job = $feature.Job
var SQL1 = 	"Job='" + Job+"'"
var Polylines_in_Job = OrderBy(filter(Fibre,SQL1),'Segment')
var i = 0

for (var f in Fibre_Job) {
geom[i++] = Geometry(f);

}

return geom

 

the code above returns an array with the exact number of polyline objects required in it  and normally  I have no problem passing a single polyline in on it s own I just can t figure out how to access every vertex in each polyline and generating a new string to include in the URL. I got it to work for start and end points but that's not exactly what I want. I also realised i needed the order to be correct or else it would be a nonsensical line ,so I added a segment id to be prepopulated by the user to inform the desired route. 1,2,3 etc   @XanderBakker  would you be able to assist with this one? 

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

Hi @PaulSweeney3 ,

It is possible to use a union to merge geometries into a single geometry, but normally with lines, this will result in a multipart geometry. If that is not a problem, you should probably use this option.

You can also access the individual vertices and create a single polyline. This challenge will be to get the lines in the right order and make sure that each individual line is captured in the same direction to avoid obtaining weird lines. 

Let me know in what direction you want to go.

View solution in original post

0 Kudos
3 Replies
XanderBakker
Esri Esteemed Contributor

Hi @PaulSweeney3 ,

It is possible to use a union to merge geometries into a single geometry, but normally with lines, this will result in a multipart geometry. If that is not a problem, you should probably use this option.

You can also access the individual vertices and create a single polyline. This challenge will be to get the lines in the right order and make sure that each individual line is captured in the same direction to avoid obtaining weird lines. 

Let me know in what direction you want to go.

0 Kudos
PaulSweeney3
Frequent Contributor

Hi @XanderBakker 

The union tool seems like it does the trick,  i ve pieced together this code thanks for that 

var mainTable= xxx
var Job = $feature.Job
var SQL1 = 	"Job='" + Job+"'"
var Fibre_Job = OrderBy(filter(mainTable,SQL1),'Segment')
var i = 0
var geom = []
for (var f in Fibre_Job) {
geom[i++] = Geometry(f);

}

var merge = Union(geom)
var  i = 0 
var outparts = []
for(var f in merge.paths[i]) {
    var e= 0
    var ptstr=Concatenate(merge.paths[e][i].y," ",merge.paths[e][i].x)
    TotalPoly[i++]= ptstr;
}

return Concatenate(TotalPoly, ";");

 

for my own education id love to see how you would have managed the second option you mentioned above. You can see from my code I used ordered by and I have a 'segment' field for the end user to populate to specify the order he polyline would follow. This will help to get the lines in the right order. The lines are already captured in the correct direction. 

Also is there a limit to how long a URL can be? as some of these segments are quite long . if its the case that they are very long and i cant use them have you any advice on how to minimise the length of the URL while still maintaining the general location of the line maybe only use vertices at a regular defined interval or  something along those lines. 

 

Regards 

 

Paul 

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi @PaulSweeney3 ,

Not sure if this will work, but from what I can deduce from what you did it could be something like this:

var id = $feature.ID;
var sql  = "ID LIKE '" + Left(id, Count(id)-1) + "%'"; // ignore this
var fs = OrderBy(Filter($layer, sql),'ID ASC');

var TotalPoly = [];
var i = 0;
for (var feat in fs) {
    var pnts = Geometry(feat)["paths"][0];
    for (var p in pnts) {
        TotalPoly[i++] = pnts[p].y + " " + pnts[p].x;
    }
}

return Concatenate(TotalPoly, ";"); 

 

I am sure there must be a limit on the length of the URL, but not sure what it is... You can round the coordinates, but this will affect the precision of the geometry that results.