Hello all,
i want to create new point to be away by specific angle and distance from existing point .
i checked geometryEngine.offset but its working only for polyline or polygon not working for points also i need to control the angle so i create the new point up or down not only right and left.
Thank you all
Solved! Go to Solution.
I have some code that uses latitude and longitude as input values to calculate a second point based on bearing and distance. Haven't used this in quite a while. I'm not sure how much efficiency you need, you would have handle any additional coordinate conversions:
function bearingDistance(lat, lon, radius, bearing){
const lat1Rads = toRad(lat);
const lon1Rads = toRad(lon);
const R_KM = 6371; // radius in KM
const d = radius/R_KM; //angular distance on earth's surface
const bearingRads = toRad(bearing);
const lat2Rads = Math.asin(
Math.sin(lat1Rads) * Math.cos(d) + Math.cos(lat1Rads) * Math.sin(d) * Math.cos(bearingRads)
);
const lon2Rads = lon1Rads + Math.atan2(
Math.sin(bearingRads) * Math.sin(d) * Math.cos(lat1Rads),
Math.cos(d) - Math.sin(lat1Rads) * Math.sin(lat2Rads)
);
return {
latitude: toDeg(lat2Rads),
longitude: toDeg(lon2Rads)
}
}
function toRad(degrees){
return degrees * Math.PI / 180;
}
function toDeg(radians){
return radians * 180 / Math.PI;
}
I have some code that uses latitude and longitude as input values to calculate a second point based on bearing and distance. Haven't used this in quite a while. I'm not sure how much efficiency you need, you would have handle any additional coordinate conversions:
function bearingDistance(lat, lon, radius, bearing){
const lat1Rads = toRad(lat);
const lon1Rads = toRad(lon);
const R_KM = 6371; // radius in KM
const d = radius/R_KM; //angular distance on earth's surface
const bearingRads = toRad(bearing);
const lat2Rads = Math.asin(
Math.sin(lat1Rads) * Math.cos(d) + Math.cos(lat1Rads) * Math.sin(d) * Math.cos(bearingRads)
);
const lon2Rads = lon1Rads + Math.atan2(
Math.sin(bearingRads) * Math.sin(d) * Math.cos(lat1Rads),
Math.cos(d) - Math.sin(lat1Rads) * Math.sin(lat2Rads)
);
return {
latitude: toDeg(lat2Rads),
longitude: toDeg(lon2Rads)
}
}
function toRad(degrees){
return degrees * Math.PI / 180;
}
function toDeg(radians){
return radians * 180 / Math.PI;
}
Hi sir, we are using the same code as given but getting the point at a wrong distance, kindly help us how to get the new point at given distance.
For lat- lattittue
log- logitude
radius- distance we are passing(line distance)
bearing- angle
if we enter 200 mt distance, the line length will be 652 mt. How to get the new point at the exact line distance, which we are providing. The screen shot provided for reference.
As @JohnGrayson suggested below, try using the JS APIs geodesicUtils.pointDistance(): https://developers.arcgis.com/javascript/latest/api-reference/esri-geometry-support-geodesicUtils.ht...
thank you sir,
its working, thank you exactly what i want 😀
You can also try the pointFromDistance() method: Geodetically computes the location at a defined distance and direction from a known location.