Page 1 of 1

Draw a circular path around a WP

Posted: 15 February 10 10:40 pm
by noikmeister
Hi,

Ever wanted to project a circle around a WP in Google Earth and been frustrated by your inability to do so? Well have I go the solution for you. The jscript below will, given starting co-ordinates and the required distance (in metres), spit out a gpx file that has a track described by a bunch of points. Just edit the SouthCentre, EastCentre and DistanceAway variables at the top of the script. For ease of calculation it only accepts decimal degrees.

The resolution of the circle is adjustable by adjusting the "Resolution" variable in the top part of the script. If you want it to run fast, leave it at 0.0001. If you want a better circle then add a zero or two (but it takes considerably longer).

Now I couldn't be bothered looking up the methods to write the output to a file, so it just echoes it to the screen and you just redirect the output as shown below.

To run it on a Windows machine just open a cmd prompt (start -> Run -> cmd.exe) and type:
cscript /nologo ProjectCircle.js > output.gpx

this will create a file called output.gpx in the current directory. Copy the code below into your favourite text edit (aka Notepad) and save the file and name it ProjectCircle.js (or whatever you want to name it).

Now if you are feeling the need to point out that my code is crap, or you can just do it really easily this way or that way with some program I am unaware of maybe consider starting a new thread. I enjoyed myself doing this and thought I'd share it all with you (and yes I know I could have used trig functions to make it more efficient, but it was just quicker to write this way).

-->8 Copy below here
var SouthCentre = -35.0000;
var EastCentre = 149.0000;
var NewSouth = SouthCentre;
var NewEast = EastCentre;
var DistanceAway = 1000;
var Resolution = 0.0001;

WScript.Echo("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
WScript.Echo("<gpx xmlns=\"http://www.topografix.com/GPX/1/1\" version=\"1.1\" creator=\"EasyGPS 3.06\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.topografix.com/GPX/gpx_overlay/0/3 http://www.topografix.com/GPX/gpx_overl ... verlay.xsd http://www.topografix.com/GPX/gpx_modified/0/1 http://www.topografix.com/GPX/gpx_modif ... dified.xsd\">");
WScript.Echo("<trk>");
WScript.Echo("<name>ACTIVE LOG</name>");
WScript.Echo("<type>GPS Tracklog</type>");
WScript.Echo("<trkseg>");

//get max east
NewSouth = SouthCentre;
NewEast = EastCentre;
do
{
NewEast = NewEast + Resolution;
var Dist=GetDist(NewSouth,NewEast);
}
while (Dist < DistanceAway);
var MaxEast=NewEast;

//get max south
NewSouth = SouthCentre;
NewEast = EastCentre;
do
{
NewSouth = NewSouth - Resolution;
var Dist=GetDist(NewSouth,NewEast);
}
while (Dist < DistanceAway);
var MaxSouth=NewSouth;

//get max west
NewSouth = SouthCentre;
NewEast = EastCentre;
do
{
NewEast = NewEast - Resolution;
var Dist=GetDist(NewSouth,NewEast);
}
while (Dist < DistanceAway);
var MaxWest=NewEast;

//get max north
NewSouth = SouthCentre;
NewEast = EastCentre;
do
{
NewSouth = NewSouth + Resolution;
var Dist=GetDist(NewSouth,NewEast);
}
while (Dist < DistanceAway);
var MaxNorth=NewSouth;

WScript.Echo("<trkpt lat=\"" + SouthCentre.toPrecision(6) + "\" lon=\"" + MaxEast.toPrecision(7) + "\"/>");
NewSouth = SouthCentre;
do
{
NewSouth = NewSouth - Resolution;
NewEast = EastCentre;
do
{
NewEast = NewEast + Resolution;
var Dist=GetDist(NewSouth,NewEast);
}
while (Dist < DistanceAway);
WScript.Echo("<trkpt lat=\"" + NewSouth.toPrecision(6) + "\" lon=\"" + NewEast.toPrecision(7) + "\"/>");
}
while (NewSouth > MaxSouth);
WScript.Echo("<trkpt lat=\"" + MaxSouth.toPrecision(6) + "\" lon=\"" + EastCentre.toPrecision(7) + "\"/>");
NewEast = EastCentre;
do
{
NewEast = NewEast - Resolution;
NewSouth = SouthCentre;
do
{
NewSouth = NewSouth - Resolution;
var Dist=GetDist(NewSouth,NewEast);
}
while (Dist < DistanceAway);
WScript.Echo("<trkpt lat=\"" + NewSouth.toPrecision(6) + "\" lon=\"" + NewEast.toPrecision(7) + "\"/>");
}
while (NewEast > MaxWest);
WScript.Echo("<trkpt lat=\"" + SouthCentre.toPrecision(6) + "\" lon=\"" + MaxWest.toPrecision(7) + "\"/>");
NewSouth = SouthCentre;
do
{
NewSouth = NewSouth + Resolution;
NewEast = EastCentre;
do
{
NewEast = NewEast - Resolution;
var Dist=GetDist(NewSouth,NewEast);
}
while (Dist < DistanceAway);
WScript.Echo("<trkpt lat=\"" + NewSouth.toPrecision(6) + "\" lon=\"" + NewEast.toPrecision(7) + "\"/>");
}
while (NewSouth < MaxNorth);
WScript.Echo("<trkpt lat=\"" + MaxNorth.toPrecision(6) + "\" lon=\"" + EastCentre.toPrecision(7) + "\"/>");
NewEast = EastCentre;
do
{
NewEast = NewEast + Resolution;
NewSouth = SouthCentre;
do
{
NewSouth = NewSouth + Resolution;
var Dist=GetDist(NewSouth,NewEast);
}
while (Dist < DistanceAway);
WScript.Echo("<trkpt lat=\"" + NewSouth.toPrecision(6) + "\" lon=\"" + NewEast.toPrecision(7) + "\"/>");
}
while (NewEast < MaxEast);
WScript.Echo("<trkpt lat=\"" + SouthCentre.toPrecision(6) + "\" lon=\"" + MaxEast.toPrecision(7) + "\"/>");

WScript.Echo("</trkseg>");
WScript.Echo("</trk>");
WScript.Echo("</gpx>");

function GetDist(lat2, lon2){
var R = 6371000; // metres
var lat1 = SouthCentre;
var lon1 = EastCentre;
var dLat = (lat2-lat1) * Math.PI/180;
var dLon = (lon2-lon1) * Math.PI/180;
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(lat1 * Math.PI/180) * Math.cos(lat2 * Math.PI/180) *
Math.sin(dLon/2) * Math.sin(dLon/2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var d = R * c;
return(d);
}
-->8 Copy above here

Re: Draw a circular path around a WP

Posted: 16 February 10 7:36 am
by caughtatwork
Your code is crap and there are a million better ways to do it.
I kid, I kid :D

You should consider placing this in the wiki so it's not lost to the bowels of the forum. In the wiki it will easily searchable and maintainable.

Re: Draw a circular path around a WP

Posted: 16 February 10 8:08 am
by noikmeister
I'll fix it up into a wsf file with some parameter handling on the command line and upload it.

Re: Draw a circular path around a WP

Posted: 16 February 10 9:05 am
by caughtatwork
I don't think you'll be able to upload it as a file.

Re: Draw a circular path around a WP

Posted: 16 February 10 1:39 pm
by mtrax
err, why would I want to do this ? is this to show a cache's proximity radius?

Re: Draw a circular path around a WP

Posted: 16 February 10 1:44 pm
by noikmeister
Well in the instance that I did it was that a cache that shall remain nameless said that it was a certain distance from a bunch of other caches. The intersection of these circles is where the cache was.

Re: Draw a circular path around a WP

Posted: 16 February 10 9:05 pm
by Agent Basil
Pork ?

Re: Draw a circular path around a WP

Posted: 16 February 10 9:15 pm
by noikmeister
Agent Basil wrote:Pork ?
Naw man, I don't eat pork.

Re: Draw a circular path around a WP

Posted: 16 February 10 9:22 pm
by caughtatwork
Nork?

Re: Draw a circular path around a WP

Posted: 17 February 10 12:32 pm
by Big Matt and Shell
I have no idea about the code but I have used the following GSAK macro a number of times.

http://gsak.net/board/index.php?s=283e9 ... entry45998

I have also used it with a bit of fiddling with the code to solve some of those nasty puzles that use distances from a point to calculate the GZ.

Re: Draw a circular path around a WP

Posted: 20 April 10 11:10 pm
by noikmeister
caughtatwork wrote:Your code is crap and there are a million better ways to do it.
I kid, I kid :D

You should consider placing this in the wiki so it's not lost to the bowels of the forum. In the wiki it will easily searchable and maintainable.
Ok how do I create a new page? I've been to the Wiki and signed in and there is no "new page" link that I can find....

Re: Draw a circular path around a WP

Posted: 21 April 10 8:04 am
by mtrax
to create a new page on the wiki you just navigate to the name of the new page you want
eg /wiki/subject_blah

Re: Draw a circular path around a WP

Posted: 05 June 10 1:05 am
by allrounder