user772436
user772436

Reputation: 51

How to calculate geographic area for Bing Maps MapPolygon?

I have a Silverlight application with a Bing Map control that displays a series of editable MapPolygons that the user can resize at will. These MapPolygons are, of course, defined as geographic coordinates. How do I calculate the area of a polygon?

The polygons are stored as geography types in SQL Server and I could go back to the server for the answer, but then the user loses an interactive update of the area as they reshape the polygons. Accuracy to within a few percent is desirable.

Upvotes: 0

Views: 1575

Answers (2)

user772436
user772436

Reputation: 51

I solved this by writing a routine to do 'spherical geometry' area calculations on the client. Works a treat and no need to go back to the server.

In short, I cheat. I find the centroid of the area, flatten to a plane centered on the centroid, and use plane geometry to do the polygon area calculation by treating the polygon as a series of triangles.

Although it's an approximation it's quite accurate enough for my purposes. If I needed an exact answer I would use SCHUMMBOs method.

Dave.

Upvotes: 1

schummbo
schummbo

Reputation: 900

If you don't mind going back to a WCF service, you can use the Microsoft.SqlServer.Types library to do the calculation. SqlGeometry has a method called STArea that does this: http://blogs.msdn.com/b/davidlean/archive/2008/10/17/this-site-under-construction.aspx

You wouldn't have to lose the interactivity of the app either necessarily. When the user is finished resizing, you can ask the service for the area and display a spinner or something briefly. I understand this wouldn't be as slick as doing it on the fly as the resize, but you also don't have to calculate the area on the client.

Sorry I wasn't more helpful in answering how to do it on the fly.

Upvotes: 0

Related Questions