How to get a polygon's info like area, perimeter, altitude...?

1,056 views
Skip to first unread message

Oswaldo Guerra

unread,
Aug 9, 2010, 3:17:04 PM8/9/10
to KML Developer Support - Getting Started with KML
I'm making a script based in the following:
http://earth-api-samples.googlecode.com/svn/trunk/demos/draw/index.html
It draws a polygon based on mouse events.

Is there a way to get this polygon's area, perimeter, min and max
altitude...?

Thanks!

Greg-WBSR

unread,
Aug 9, 2010, 8:55:30 PM8/9/10
to KML Developer Support - Getting Started with KML
Have a look at this page, it might help you enough

http://www.barnabu.co.uk/geapi/polyplot/

kyonn

unread,
Aug 10, 2010, 4:08:43 AM8/10/10
to KML Developer Support - Getting Started with KML
Unfortunately the link you gave is only for regular polygons.

There is a simple way to calculate area for non regular poly : make
use of the official extension for google earth api ...

But about your problem Oswaldo Guerra, concerning the mousemove curve
(I mean the "draw"), I found how to calculate the distance, and so how
to make the "draw" example into such a curvimeter :

Let's start assuming you have the coords of the "draw" which is in
fact a polyline with very close points.

var zz=[], distance=0;
for (var i=0;i<coords.getLength();i++){
if (i>0) distance
+=parseFloat(distVincenty(coords.get(i-1).getLatitude(),
coords.get(i-1).getLongitude(),coords.get(i).getLatitude(),
coords.get(i).getLongitude() ) );
zz.push( [ distance,
ge.getGlobe().getGroundAltitude( coords.get(i).getLatitude(),
coords.get(i).getLongitude() ) ] );

}

That's it : you now have the total distance along the curve.
zz is an array containing altitude for each point so you also can plot
them to get an elevation profile, with jqplot for example.

The distVincenty function is found here :
http://www.movable-type.co.uk/scripts/latlong-vincenty.html

Now back to area, I've not implemented it, but with the coords of what
is in fact a polygon, one can also get the area with the gearth
extension or an implementation of its methods to calculate polygon
area.

Oswaldo Guerra

unread,
Aug 11, 2010, 1:05:58 AM8/11/10
to KML Developer Support - Getting Started with KML
Thanks guys for the help.
If useful, here is the way to calculate the area of a polygon:
http://www.wikihow.com/Calculate-the-Area-of-a-Polygon

Oswaldo.
Reply all
Reply to author
Forward
0 new messages