1

I have a coordinate, and a path. I need to find a point on path closest to my coordinate. Something like http://turfjs.org/static/docs/module-turf_point-on-line.html but for iOS. ArcGIS doesn't seem to have such functionality. Or I don't see it. In worst case I may implement own algorithm. But it is really hard to wrap head around math formulas.

  • I don't use iOS SDK but in ArcObjects I would use a proximity operator which I think is this one in iOS developers.arcgis.com/ios/api-reference/… and developers.arcgis.com/ios/api-reference/…. Does that do what you're after? In ArcObjects you cast the proximity operator from the geometry to find the location on and then give a query point to find the closest. – Michael Stimson May 4 '16 at 3:30
  • There are plenty of tools in arcgis to do it, to name a few: linear referencing, near analysis, measure online method... – FelixIP May 4 '16 at 9:59
  • Thank you guys, I see now. Michael Miles-Stimson, please make your comment as answer so that I can mark it. – Roman Temchenko May 4 '16 at 13:17
  • there is also the AGSGeometryEngine nearestVertexInGeometry:toPoint: if you want a specific vertex from the route. – crmackey May 6 '16 at 5:11
0

It is important to note that you can grab the nearest coordinate or the nearest vertex of the route from the geometry engine...

You didn't specify if you were using Swift or Objective-C, but here is some untested Swift code to search a given route for the closest coordinate to a given point and then display it as a graphic:

import UIKit
import ArcGIS

class SomeViewController: UIViewController, AGSMapViewLayerDelegate {

    @IBOutlet weak var mapView:AGSMapView!

    // some variables you will need, obviously your app will require more...
    var point: AGSGraphic!
    var routeResult: AGSRouteResult!
    var routeGraphicsLayer:AGSGraphicsLayer!
    let geometryEngine = AGSGeometryEngine.defaultGeometryEngine()

    override func viewDidLoad() {
        super.viewDidLoad()

        // your app code to generate a point and route...

        // MARK: Find closest point on route to your point of interest
        // add a graphic for the point, assuming you are working with an AGSRouteResult for your route
        self.routeGraphicsLayer = AGSGraphicsLayer()
        self.mapView.addMapLayer(routeGraphicsLayer, withName: "Graphics")

        // find nearest vertex or coordinate on route to a given point
        let closestPoint = self.geometryEngine.nearestCoordinateInGeometry(self.routeResult.routeGraphic.geometry, toPoint:self.point)

        // set symbol
        let closestMarkerSymbol = AGSSimpleMarkerSymbol()
        closestMarkerSymbol.style = .Diamond
        closestMarkerSymbol.outline.color = UIColor.blueColor()

        // display it, add attribute for distance to route
        var attrib: [String:Double] = ["Distance": self.routeResult.distance]
        let closestPointGraphic = AGSGraphic(closestPoint, attributes:attrib)
        self.closestPointGraphic.symbol = closestMarkerSymbol
        self.routeGraphicsLayer.addGraphic(closestPointGraphic)
        self.routeGraphicsLayer.visible = true

        // do other stuff, maybe add a callout/popup for the point so the user can see distance?

    }

}
0

ArcGIS has something that can be used. AGSGeometryEngine nearestCoordinateInGeometry:toPoint:. But still a long way to go.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.