Draw a circular path around a WP

Discussion about software such as GSAK, OziExplorer etc, as well as all things hardware, GPSrs, laptops, PDAs, paperless caching, cables etc
Post Reply
User avatar
noikmeister
5000 or more caches found
5000 or more caches found
Posts: 1200
Joined: 10 July 09 12:29 pm
Location: Canberra

Draw a circular path around a WP

Post by noikmeister » 15 February 10 10:40 pm

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

User avatar
caughtatwork
Posts: 16185
Joined: 17 May 04 12:11 pm
Location: Melbourne
Contact:

Re: Draw a circular path around a WP

Post by caughtatwork » 16 February 10 7:36 am

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.

User avatar
noikmeister
5000 or more caches found
5000 or more caches found
Posts: 1200
Joined: 10 July 09 12:29 pm
Location: Canberra

Re: Draw a circular path around a WP

Post by noikmeister » 16 February 10 8:08 am

I'll fix it up into a wsf file with some parameter handling on the command line and upload it.

User avatar
caughtatwork
Posts: 16185
Joined: 17 May 04 12:11 pm
Location: Melbourne
Contact:

Re: Draw a circular path around a WP

Post by caughtatwork » 16 February 10 9:05 am

I don't think you'll be able to upload it as a file.

User avatar
mtrax
Posts: 1947
Joined: 19 December 06 9:57 am
Location: Weston Creek, Canberra

Re: Draw a circular path around a WP

Post by mtrax » 16 February 10 1:39 pm

err, why would I want to do this ? is this to show a cache's proximity radius?

User avatar
noikmeister
5000 or more caches found
5000 or more caches found
Posts: 1200
Joined: 10 July 09 12:29 pm
Location: Canberra

Re: Draw a circular path around a WP

Post by noikmeister » 16 February 10 1:44 pm

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.

User avatar
Agent Basil
2500 or more caches found
2500 or more caches found
Posts: 673
Joined: 31 July 08 8:26 pm
Location: Deakin, ACT

Re: Draw a circular path around a WP

Post by Agent Basil » 16 February 10 9:05 pm

Pork ?

User avatar
noikmeister
5000 or more caches found
5000 or more caches found
Posts: 1200
Joined: 10 July 09 12:29 pm
Location: Canberra

Re: Draw a circular path around a WP

Post by noikmeister » 16 February 10 9:15 pm

Agent Basil wrote:Pork ?
Naw man, I don't eat pork.

User avatar
caughtatwork
Posts: 16185
Joined: 17 May 04 12:11 pm
Location: Melbourne
Contact:

Re: Draw a circular path around a WP

Post by caughtatwork » 16 February 10 9:22 pm

Nork?

User avatar
Big Matt and Shell
6500 or more caches found
6500 or more caches found
Posts: 1905
Joined: 11 February 07 9:53 pm
Twitter: BigMattandShell
Contact:

Re: Draw a circular path around a WP

Post by Big Matt and Shell » 17 February 10 12:32 pm

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.

User avatar
noikmeister
5000 or more caches found
5000 or more caches found
Posts: 1200
Joined: 10 July 09 12:29 pm
Location: Canberra

Re: Draw a circular path around a WP

Post by noikmeister » 20 April 10 11:10 pm

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....

User avatar
mtrax
Posts: 1947
Joined: 19 December 06 9:57 am
Location: Weston Creek, Canberra

Re: Draw a circular path around a WP

Post by mtrax » 21 April 10 8:04 am

to create a new page on the wiki you just navigate to the name of the new page you want
eg /wiki/subject_blah

User avatar
allrounder
3500 or more caches found
3500 or more caches found
Posts: 365
Joined: 19 January 06 2:38 pm
Location: Kambah

Re: Draw a circular path around a WP

Post by allrounder » 05 June 10 1:05 am


Post Reply