Find Center Point From List of Lat Long Coords in Linq

I need to find the center point of a list of coordinates, but I don't want to simply search for the extremities and find a midpoint, as some of the coordinates could be rogues.  Is there a way that I can somehow weight the center based on the density ?  Any ideas ?
WatersideAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
A good way to find a geographical centroid is to treat all the coordinates as 3-d vectors and average them.
it_saigeDeveloperCommented:
In other words, something like:
Imports System.Device.Location

Module Module1
	ReadOnly coordinates As New List(Of GeoCoordinate) From _
		{ _
			New GeoCoordinate() With {.Latitude = 22.9833, .Longitude = 72.5}, _
			New GeoCoordinate() With {.Latitude = 18.975, .Longitude = 72.8258}, _
			New GeoCoordinate() With {.Latitude = 22.3, .Longitude = 73.2003}, _
			New GeoCoordinate() With {.Latitude = 26.926, .Longitude = 75.8235}, _
			New GeoCoordinate() With {.Latitude = 28.61, .Longitude = 77.23}, _
			New GeoCoordinate() With {.Latitude = 22.3, .Longitude = 70.7833} _
		}

	Sub Main()
		Dim central = coordinates.GetCentralGeoCoordinate()
		Console.WriteLine("Central Latitude: {0}; Central Longitude: {1}", central.Latitude, central.Longitude)
		Console.ReadLine()
	End Sub
End Module

Module Extensions
	<System.Runtime.CompilerServices.Extension()> _
	Public Function GetCentralGeoCoordinate(ByVal coordinates As IEnumerable(Of GeoCoordinate)) As GeoCoordinate
		' Original code authored by Yodacheese - http://stackoverflow.com/questions/6671183/calculate-the-center-point-of-multiple-latitude-longitude-coordinate-pairs
		If coordinates.Count = 1 Then Return coordinates.Single()

		Dim CentralLatitude As Double
		Dim CentralLongitude As Double

		Dim x As Double = 0
		Dim y As Double = 0
		Dim z As Double = 0

		Dim vectors = (From coordinate As GeoCoordinate In coordinates
					Let latitude = coordinate.Latitude * Math.PI / 180
					Let longitude = coordinate.Longitude * Math.PI / 180
					Let a = Math.Cos(latitude) * Math.Cos(longitude)
					Let b = Math.Cos(latitude) * Math.Sin(longitude)
					Let c = Math.Sin(latitude)
					Select New With {.X = a, .Y = b, .Z = c})

		x = vectors.Sum(Function(vector) vector.X) / coordinates.Count
		y = vectors.Sum(Function(vector) vector.Y) / coordinates.Count
		z = vectors.Sum(Function(vector) vector.Z) / coordinates.Count

		CentralLatitude = Math.Atan2(z, Math.Sqrt(x * y + y * y))
		CentralLongitude = Math.Atan2(y, x)

		Return New GeoCoordinate(CentralLatitude * 180 / Math.PI, CentralLongitude * 180 / Math.PI)
	End Function
End Module

Open in new window

Which produces the following output -Capture.JPG-saige-

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
WatersideAuthor Commented:
Typo I think line 46 should read..

CentralLatitude = Math.Atan2(z, Math.Sqrt(x * x + y * y))

Thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.