how to get the ray of a circle in meters using getRadius()

ぐ巨炮叔叔 提交于 2019-12-13 05:57:06

问题


the method getRadius() of class ol.geom.Circle returns the radius of a circle ; how can I convert this value into meters ?

I draw a circle on a map using a particular projection (e.g Spherical Mercator, LambertIIe, etc.) then I convert this geometry into degree to process further treatments such as testing if a point (in degrees) is inside this circle

so getting the radius always in the same unit (meter) from a geometry in degree would be useful

thanks in advance

Jean-Marie


回答1:


You can use the ol.proj.METERS_PER_UNIT table to get the radius in meters:

var units = map.getView().getProjection().getUnits();
var radiusM = circle.getRadius() * ol.proj.METERS_PER_UNIT[units];



回答2:


I use the following method to get the radius (getFirstCoordinate referring to the center and getLastCoordinate referring to a point on the perimeter) :

var wgs84Sphere = new ol.Sphere(6378137);

var center=circle.getFirstCoordinate();
var ray=getDistance(center[0],center[1],circle.getLastCoordinate()[0],circle.getLastCoordinate()[1]);


// getDistance returns the distance between 2 points (source : http://openlayers.org/en/v3.7.0/examples/measure.html)

function getDistance(long1,lat1,long2,lat2) {
    var c1 = [long1,lat1];
    var c2 = [long2,lat2];
    return wgs84Sphere.haversineDistance(c1,c2);
}


来源:https://stackoverflow.com/questions/31805918/how-to-get-the-ray-of-a-circle-in-meters-using-getradius

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!