[OpenLayers-Users] Function to create a geographically correct
circle
Michael
mdm at yachtpc.com
Tue Jun 28 09:43:46 EDT 2011
I suppose it could work if we added the number of sides down in the line
that provides "* for (x = 0; x <= 360; x+=6)*". Probably needs more
tweaking to get squares and triangles to look like we expect.
I'm not sure how many folks besides me need this, but if there's a
perceived need, I'm willing to tune it up.
oops. Just noticed in the code that I use my shorthand definition of
pt=new OpenLayers Point. fixing code below
Michael
On 6/28/2011 6:33 AM, Janis Elmeris wrote:
> 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 OpenLayers.Point(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
>
>
> _______________________________________________
> 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/0c3e318d/attachment.html
More information about the Users
mailing list