Skip to content
Skip to breadcrumbs
Skip to header menu
Skip to action menu
Skip to quick search
Quick Search
Browse
Pages
Blog
Labels
Attachments
Mail
Advanced
What’s New
Space Directory
Feed Builder
Keyboard Shortcuts
Confluence Gadgets
Log In
Dashboard
Groovy
Copy Page
You are not logged in. Any changes you make will be marked as
anonymous
. You may want to
Log In
if you already have an account. You can also
Sign Up
for a new account.
This page is being edited by
.
Paragraph
Paragraph
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
Preformatted
Quote
Bold
Italic
Underline
More colours
Strikethrough
Subscript
Superscript
Monospace
Clear Formatting
Bullet list
Numbered list
Outdent
Indent
Align left
Align center
Align right
Link
Table
Insert
Insert Content
Image
Link
Attachment
Symbol
Emoticon
Wiki Markup
Horizontal rule
tinymce.confluence.insert_menu.macro_desc
Info
JIRA Issue
Status
Gallery
Tasklist
Table of Contents
Other Macros
Page Layout
No Layout
Two column (simple)
Two column (simple, left sidebar)
Two column (simple, right sidebar)
Three column (simple)
Two column
Two column (left sidebar)
Two column (right sidebar)
Three column
Three column (left and right sidebars)
Undo
Redo
Find/Replace
Keyboard Shortcuts Help
<p>Every Google Earth user is going mad about path and distance: you can get Path or Distance but not both.<br /> This little snipset help you to get path AND distance.</p> <ol> <li>Create your path as usual with Google Earth</li> <li>Save it as a .kml file (not .kmz)</li> <li>Run the this script</li> </ol> <p>The current version <strong>is KML 2.2</strong></p> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> /** * Compute distance in Google Earth KML path file from a path * @author Marc DEXET ( marcdexet [at] gmail [dot] org ) */ class Point { def lat def lon public Point(){} public Point(String gps) { def xyz = gps.tokenize(','); lat = Double.parseDouble( xyz[1] ) lon = Double.parseDouble( xyz[0] ) } public String toString() { return "LAT: ${lat} LON: ${lon}" } public static double distance(Point p0, Point p1) { return Haversine.compute(p0, p1) } } /** * List of Points */ class PointList { def points def distance def partiels = [] public PointList( List points ) { this.points = points compute() } void compute() { def nbPointList = points.size() distance = 0; partiels = [] for( idx in 1..(nbPointList-1) ) { def p0 = points[(idx-1)] def p1 = points[idx] def dist = Point.distance(p0,p1) partiels << dist distance = distance+dist } } } /** * Haversine algorithmus * (thanks to http://www.movable-type.co.uk/scripts/latlong.html) */ class Haversine { static double R = 6371 static double compute(Point p1, Point p2) { def dLat = Math.toRadians(p2.lat-p1.lat); def dLon = Math.toRadians(p2.lon-p1.lon); def a = Math.sin(dLat/2) * Math.sin(dLat/2) + Math.cos( Math.toRadians(p1.lat) ) * Math.cos( Math.toRadians(p2.lat) ) * Math.sin(dLon/2) * Math.sin(dLon/2); def c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); def d = R * c; return d } } class KmlParser { static ns = new groovy.xml.Namespace("http://earth.google.com/kml/2.2", 'ns') List parse( Object input ) { def kml = new groovy.util.XmlParser().parse( input ); def coords = kml[ ns.Document ][ ns.Placemark ][ ns.LineString ][ ns.coordinates ].text() def myList = coords.tokenize(); def points = [] myList.each{ gestring -> points << new Point(gestring) } return points; } } // Application def kmlParser = new KmlParser() def points = kmlParser.parse( args[0] ) def PointList pointList = new PointList( points ) def partiels = pointList.partiels; def distance = pointList.distance; java.text.DecimalFormat f = new java.text.DecimalFormat( "0.000" ); java.text.DecimalFormat n = new java.text.DecimalFormat( "00" ); println "Distance totale: ${f.format(distance)} km" partiels.eachWithIndex { d, i -> println "${n.format(i)}) ${f.format(d)} km" } </pre></td></tr></table> <h2>Archives</h2> <h3>KML 2.1</h3> <table class="wysiwyg-macro" data-macro-name="code" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGV9&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>/** * Compute distance in Google Earth KML path file from a path * @author Marc DEXET ( marcdexet [at] gmail [dot] org ) */ class Point { def lat def lon public Point(){} public Point(String gps) { def xyz = gps.tokenize(','); lat = Double.parseDouble( xyz[1] ) lon = Double.parseDouble( xyz[0] ) } public String toString() { return "LAT: ${lat} LON: ${lon}" } public static double distance(Point p0, Point p1) { return Haversine.compute(p0, p1) } } /** * List of Points */ class PointList { def points def distance def partiels = [] public PointList( List points ) { this.points = points compute() } void compute() { def nbPointList = points.size() distance = 0; partiels = [] for( idx in 1..(nbPointList-1) ) { def p0 = points[(idx-1)] def p1 = points[idx] def dist = Point.distance(p0,p1) partiels << dist distance = distance+dist } } } /** * Haversine algorithmus * (thanks to http://www.movable-type.co.uk/scripts/latlong.html) */ class Haversine { static double R = 6371 static double compute(Point p1, Point p2) { def dLat = Math.toRadians(p2.lat-p1.lat); def dLon = Math.toRadians(p2.lon-p1.lon); def a = Math.sin(dLat/2) * Math.sin(dLat/2) + Math.cos( Math.toRadians(p1.lat) ) * Math.cos( Math.toRadians(p2.lat) ) * Math.sin(dLon/2) * Math.sin(dLon/2); def c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); def d = R * c; return d } } class KmlParser { static ns = new groovy.xml.Namespace("http://earth.google.com/kml/2.1", 'ns') List parse( Object input ) { def kml = new groovy.util.XmlParser().parse( input ); def coords = kml[ ns.Document ][ ns.Placemark ][ ns.LineString ][ ns.coordinates ].value[0] def myList = coords.tokenize(); def points = [] myList.each{ gestring -> points << new Point(gestring) } return points; } } // Application def kmlParser = new KmlParser() def points = kmlParser.parse( args[0] ) def PointList pointList = new PointList( points ) def partiels = pointList.partiels; def distance = pointList.distance; java.text.DecimalFormat f = new java.text.DecimalFormat( "0.000" ); java.text.DecimalFormat n = new java.text.DecimalFormat( "00" ); println "Distance totale: ${f.format(distance)} km" partiels.eachWithIndex { d, i -> println "${n.format(i)}) ${f.format(d)} km" } </pre></td></tr></table>
Please type the word appearing in the picture.
Attachments
Labels
Location
Watch this page
< Edit
Preview >
Loading…
Save
Cancel
Next hint
search
attachments
weblink
advanced