Draw a circle in Google Earth
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). Due to the wiki wanting to reformat everything watch for line wrap. Each line ends with a semi-colon.
-->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_overlay/0/3/gpx_overlay.xsd http://www.topografix.com/GPX/gpx_modified/0/1 http://www.topografix.com/GPX/gpx_modified/0/1/gpx_modified.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