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

2

1

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

Krucik answered 4/8, 2015 at 9:46 Comment(0)
B
3

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];
Bathy answered 5/8, 2015 at 9:12 Comment(1)
i tried this solution, but not working as expected. stackoverflowV2
K
0

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);
}
Krucik answered 31/8, 2015 at 16:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.