I have a set of lat/long points. I need to calculate the center point and radius of a circle that will encompass all the points.

The co-ordinate system used is latitude/longitude as per google maps.

I previously used Think-Geo MapSuite where I could call a function, provide a collection of points and receive a bounding box. I would use the bounding box to instruct the map to display at a particular location and scale.

The tooling I'm using now is Xamarin Forms. This is a cross-platform tool that provides a high level wrapper across mobile platforms. For iOS this is Apple maps, Android is Google Maps and Windows Phone is Bing Maps. It is a new tool so the wrapper is very basic at present. I can only provide a center point and radius to instruct the map where to display.

I ultimately need C# code but pseudo code, or any other flavour would be a great help.

  • Would you be able to edit your question to include the coordinate system and units that you are trying calculate your radius in because the geographic and/or projected coordinate system(s) that you work in can make a big difference to this question and its answer(s). – PolyGeo Jan 25 '15 at 3:52
  • Also, can you say which tools you want to (or have to) use, if any? – BradHards Jan 25 '15 at 3:56
  • 1
    This question, or at least one similar, has already been answered previously. Search on your title to locate it. – Vince Jan 25 '15 at 5:25
  • I updated the question to provide more details. Vince - I searched for an answer before I posted this but did not find one. I would be obliged if you could point me at one if you know of it. – Steve Chadbourne Jan 25 '15 at 6:35
  • See also gis.stackexchange.com/questions/73362/… – Vince Jan 25 '15 at 17:01

First you have to calculate the centroid of your polygon, i.e. your set of Lon/Lat. This is simple mathematics, see Wikipedia for example: Centroid of polygon

Then calculate the distance from this centroid to each coordiante of your set using simple Pythagoras. The biggest value will be the radius of your circle.

1 degree in Latitude is equivalent to 111km, 1 degree in Longitude is around cos(Lat)*111km

Note, since you have geographic Lat/Lon coordinates (and not cartesian values) this calculation is not 100% exact. However, it should satisfy your needs as long as the area is not too big (lets say a few kilometers).

  • Approximate should be sufficient. Do you have an example of any of this in code? – Steve Chadbourne Jan 26 '15 at 21:51
  • Come on, this is very simple math. Such a task would be an exam in a "C# for beginners" course. – Wernfried Domscheit Jan 27 '15 at 14:16

I think you don't really need a circle / radius. If the goal is just to get all the points on the screen, you can just calculate the bounding box, and from that calculate the centre position and the extent (distance from centre to whichever edge is further away).

Of course, the API is terrible and you have to provide a distance in metres, but you only have it in degrees. So a rough multiplication of the greater of the distances in degrees by 111,319.9 to get metres will probably be required.

Bounding box on points is simple - start with the coordinates of the first point, then iterate over every other point and extent the bounding box if the point is outside the bounding box you have.

That is pretty basic, but if you need it in C#, please post the initial data structure you have and I can draft something.

  • Thanks Brad. My data structure is a basic class containing a string description property, a double latitude property and a double longitude property. I have a List of these. – Steve Chadbourne Jan 26 '15 at 21:49

Check if the below approach works

  1. Find the convex hull of these points
  2. Find the centroid of the convex hull polygon--which becomes center
  3. The farthest distance from centroid to the set of point is the radius of desired circle

For C#, refer this topic or this

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.