Select to view content in your preferred language

Using pull data to looking up closest point

11994
16
Jump to solution
05-25-2017 07:47 AM
StuartMoore
Frequent Contributor

Has anyone tried using the pull data to identify the closest point of another dataset to the geopoint and retrieve a value something like the near toolbox function in arcmap.

It's a bit like using the pulldata function and a calculation in one go that takes the current location of the geopoint and calculates the distance to a list of points within a csv file and then returns their site name

thanks

Stu

16 Replies
ChaimSchwartzIroads
Regular Contributor

This looks really great, if I ever have the need again and implement it I promise to post. Thank you for sharing the example!!

utenalarosa
Occasional Contributor

 

@IsmaelChivite Can this be use in a public survey?

Thanks

oribecco_SMJV
New Contributor

Hello @IsmaelChivite , 

 

After using your script and mimicking the fields in your screenshot, the 'city_json' field returns the feature layer feature service link, and the 'closest_city' field respectively returns a blank. Any idea why this might be happening? 

 

Thanks 

0 Kudos
Tim-Woodfield
Regular Contributor

@IsmaelChivite Is this still the best way to accomplish the closest feature search? Are there any options for a public survey like the "?distance=" search? Not sure in what order those records are returned or if they could be sorted by distance.

0 Kudos
mikaël
Frequent Contributor

Is this still the best solution to get a nearest record?

Trying to get the nearest polyline from a geopoint question.

Thanks!

IGTLab_Empress
Occasional Contributor

Has anyone else been able to expand on this conundrum? I'm using Survey123 Connect and am trying to pull attribute data from the nearest point to another point that I'm plotting on a survey. I tried the script that @IsmaelChivite posted, but it hasn't populated in the way that I've hoped yet. Any input would be appreciated!

0 Kudos
Erwinvan_Veen1
Regular Contributor

Far from ideal and far from accurate, I currently use the below calculation. Although it does not get the actual nearest point, it does provide an indication of the nearest by limiting the search distance. For our usecase this is sufficient to give an indication of the nearest street name. This is purely to provide an indication, not important for the actual data.

pulldata("@layer", "getValueAt", "attributes.<ATTRIBUTE>", "https://<URL>/arcgis/rest/services/<SERVICE>/FeatureServer/<LAYERID>?distance=25&units=esriSRUnit_Meter", ${GEOMETRY_NAME})

What I use as a better solution is in a web map use an Arcade expression to find the actual nearest feature. Admittedly, I have the advantage we only use Survey123 to get reports which ArcGIS Online users then edit using a web map. So I am lucky I can use Arcade expressions in a Form. That Arcade expression is adapted from From the Smart Editor to Smart Forms.

 

var wegvak = FeatureSetByName($map, "<POLYGONLAYER_STREETNAMES>")

var bufferedLocation = Buffer($feature, 500, 'meters')
var candidateWegvakken = Intersects(wegvak, bufferedLocation)

var featuresWithDistances = []
for (var f in candidateWegvakken) {
    Push(featuresWithDistances,
        {
            'distance': Distance($feature, f, 'feet'),
            'feature': f
        }
    )
}
// Sort the candidates by distance using a custom function
function sortByDistance(a, b) {
    return a['distance'] - b['distance']
}
var sorted = Sort(featuresWithDistances, sortByDistance)
// Get the closest candidate
var closestFeatureWithDistance = First(sorted)
// If there was no candidate, return null
if (IsEmpty(closestFeatureWithDistance)) { return null }
// Return the candidate name attribute value
return `${closestFeatureWithDistance['feature']['<STREET_NAME>']}`

 

Frankly, it's great and all we can use AI in Survey123, but we still cannot properly use Arcade expressions and use other coordinate systems in Survey123. I think the priorities are mixed up here..