Select to view content in your preferred language

How can I draw a line from a point on a SceneView using a Bearing and Distance?

694
2
Jump to solution
07-17-2023 08:42 PM
alionthego
Emerging Contributor

I want to draw out a Great Circle radial from a point  on the Earth's Surface using the initial point and a Bearing Distance.  The line will be greater than 500 KM.

Currently I am using the following:

func drawRadialFromPoint(_ point: Point, heading: Double, distance: Double) {

     let overlay = GraphicsOverlay()

     let endPoint = calculateEndPoint(from: point, heading: heading, distance: distance)

     let polyline = Polyline(

        points: [

            point,

            endPoint

        ]

    )

    let polylineSymbol = SimpleLineSymbol(style: .solid, color: .blue, width: 3.0)

    let polylineGraphic = Graphic(geometry: polyline, symbol: polylineSymbol)

    overlay.addGraphic(polylineGraphic)

}

func calculateEndPoint(from startPoint: Point, heading: Double, distance: Double) -> Point {

    let angleInRadians = heading * .pi / 180

    let x = startPoint.x + distance * sin(angleInRadians)

    let y = startPoint.y + distance * cos(angleInRadians)

    return Point(x: x, y: y, spatialReference: startPoint.spatialReference)

}

It seems to work but there are two problems.  I don't believe this method is accurate for long distances on the Earth and I was hoping the API would offer a more accurate method to achieve this.

Secondly, when the user pans the earth and the start point is no longer visible, the line disappears which is a problem.

Is there a better way to achieve this?  

0 Kudos
1 Solution

Accepted Solutions
Ting
by Esri Contributor
Esri Contributor

> I don't believe this method is accurate for long distances on the Earth and I was hoping the API would offer a more accurate method to achieve this.

Please check out the geodeticMove(_:distance:distanceUnit:azimuth:azimuthUnit:curveType:) in the API. It allows you to move a point in a geodesic manner for a distance and a bearing (azimuth), and also allows you to specify one of the geodesic curve types.

Here is a small demo I wrote for a different purpose using the old SDK, but it shows how to draw a line given the starting point and the distance and azimuth. Please let me know if you need more info.

 

when the user pans the earth and the start point is no longer visible, the line disappears which is a problem.

The point and line graphics should only disappear when they are outside the field of view of a scene view. Please see the attached video. Is it what you are seeing?

 

View solution in original post

0 Kudos
2 Replies
Ting
by Esri Contributor
Esri Contributor

> I don't believe this method is accurate for long distances on the Earth and I was hoping the API would offer a more accurate method to achieve this.

Please check out the geodeticMove(_:distance:distanceUnit:azimuth:azimuthUnit:curveType:) in the API. It allows you to move a point in a geodesic manner for a distance and a bearing (azimuth), and also allows you to specify one of the geodesic curve types.

Here is a small demo I wrote for a different purpose using the old SDK, but it shows how to draw a line given the starting point and the distance and azimuth. Please let me know if you need more info.

 

when the user pans the earth and the start point is no longer visible, the line disappears which is a problem.

The point and line graphics should only disappear when they are outside the field of view of a scene view. Please see the attached video. Is it what you are seeing?

 

0 Kudos
alionthego
Emerging Contributor

Thanks.  This is really great and draws the line nicely.  I will read up on difference between the curveTypes geodesic and greatElliptical

0 Kudos