[OpenLayers-Users] Function to create a geographically correct circle

Janis Elmeris janis.elmeris at intelligentsystems.lv
Tue Jun 28 09:33:45 EDT 2011


It would be a good idea to add this function to 
OpenLayers.Geometry.Polygon along with createRegularPolygon that is 
already there. Something like createGeodesicRegularPolygon as there is 
getGeodesicArea.

Janis

On 2011.06.06. 8:20, Michael wrote:
> Regular Polygons are fine for many applications.  I needed range rings 
> for ocean races, which did not correctly reflect the projection of the 
> map.  Although it projected like a nice round circle, the correct 
> shape should have been oval.
>
> Did not find a geographic circle function in OL, so I adapted one from 
> one found online.
>
> I present it here should anyone want it, or have a better idea, or 
> want to point out that this was in OL all along.
>
> *function GeoCircle(latin, lonin, radius)// thanks to VE site for 
> basic algo. Returns an OL Polygon of diameter in nautical miles
>   {
>     var locs = new Array();
>     var lat1 = latin * Math.PI/180.0;
>     var lon1 = lonin * Math.PI/180.0;
>     var d = radius/3440.07;// change this value to the radius of the 
> Earth in your units
>     var x;
>     for (x = 0; x <= 360; x+=6)  //gives 60 points.  More than enough 
> for a smooth circle most likely
>     {
>         var tc = (x / 90)* Math.PI / 2;
>         var lat = 
> Math.asin(Math.sin(lat1)*Math.cos(d)+Math.cos(lat1)*Math.sin(d)*Math.cos(tc));
>         lat = 180.0 * lat / Math.PI;
>         var lon;
>          if (Math.cos(lat1)==0)
>         {
>             lon=lonin; // endpoint a pole
>         }
>         else
>         {
>             lon = ((lon1 - Math.asin(Math.sin(tc) * 
> Math.sin(d)/Math.cos(lat1)) + Math.PI) % (2 * Math.PI)) - Math.PI;
>         }
>         lon = 180.0 * lon / Math.PI;
>         var loc = new pt(lon,lat);
>         locs.push(loc);
>     }
>     var poly = new OpenLayers.Feature.Vector(new 
> OpenLayers.Geometry.Polygon(new OpenLayers.Geometry.LinearRing(locs)));
>
>     return poly;  //this can be added to a map
> }
> *
>
>
> _______________________________________________
> Users mailing list
> Users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20110628/2e65a735/attachment.html


More information about the Users mailing list