[OpenLayers-Users] Buffers in kilometer

Ralph Dell RDell at CatawbaCountyNC.gov
Fri May 29 04:59:22 PDT 2015


Is this piece of code helpful for what you are trying to do?
I orginally got it here http://geographika.co.uk/creating-a-geodesic-circle-in-openlayers
but the url is no longer good.

/*
 * APIMethod: createGeodesicPolygon
 * Create a regular polygon around a radius. Useful for creating circles
 * and the like.
 *
 * Parameters:
 * origin - {<OpenLayers.Geometry.Point>} center of polygon.
 * radius - {Float} distance to vertex, in map units.
 * sides - {Integer} Number of sides. 20 approximates a circle.
 * rotation - {Float} original angle of rotation, in degrees.
 * projection - {<OpenLayers.Projection>} the map's projection
 */
OpenLayers.Geometry.Polygon.createGeodesicPolygon = function(origin, radius, sides, rotation, projection){
    if (projection.getCode() !== "EPSG:4326") {
        origin.transform(projection, new OpenLayers.Projection("EPSG:4326"));
    }
    var latlon = new OpenLayers.LonLat(origin.x, origin.y);
    var angle;
    var new_lonlat, geom_point;
    var points = [];
    
    for (var i = 0; i < sides; i++) {
        angle = (i * 360 / sides) + rotation;
        new_lonlat = OpenLayers.Util.destinationVincenty(latlon, angle, radius);
        new_lonlat =  new_lonlat.transform(new OpenLayers.Projection("EPSG:4326"), projection);
        geom_point = new OpenLayers.Geometry.Point(new_lonlat.lon, new_lonlat.lat);
        points.push(geom_point);
    }
    var ring = new OpenLayers.Geometry.LinearRing(points);
    return new OpenLayers.Geometry.Polygon([ring]);
};

Ralph Dell
Catawba County NC

-----Original Message-----
From: openlayers-users-bounces at lists.osgeo.org [mailto:openlayers-users-bounces at lists.osgeo.org] On Behalf Of Robert Sanson
Sent: Thursday, May 28, 2015 5:04 PM
To: adityakumar529; openlayers-users at lists.osgeo.org
Subject: Re: [OpenLayers-Users] Buffers in kilometer

Your map is in geographic coordinates (lat/long). Conversion of degrees to meters is complex as it varies depending on latitude.

Take a look at the function OpenLayers.Util.destinationVincenty

You might be able to write a function that takes your vector points and then generates the coordinates of the buffer around them

Another option would be to project your map features that you want buffered into a metric projection eg. Spherical Mercator, then buffer them in m, then reproject them back to 4326 and add them to your vector layer.

regards,

Robert

-----Original Message-----
From: openlayers-users-bounces at lists.osgeo.org [mailto:openlayers-users-bounces at lists.osgeo.org] On Behalf Of adityakumar529
Sent: Friday, 29 May 2015 8:47 a.m.
To: openlayers-users at lists.osgeo.org
Subject: Re: [OpenLayers-Users] Buffers in kilometer

Its EPSG:4326



-----
GIS Developer

--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Buffers-in-kilometer-tp5207934p5208068.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
_______________________________________________
Users mailing list
Users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/openlayers-users
_______________________________________________
Users mailing list
Users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/openlayers-users


More information about the Users mailing list