Determine the centroid of multiple points

前端 未结 6 1737
甜味超标
甜味超标 2020-12-09 01:01

I\'m writing a mapping application that I am writing in python and I need to get the lat/lon centroid of N points. Say I have two locations

a.lat = 101
a.lon         


        
相关标签:
6条回答
  • 2020-12-09 01:14

    If you are averaging angles and have to deal with them crossing the 0/360 then it is safer to sum the sin and cos of each value and then Average = atan2(sum of sines,sum of cosines)
    (be careful of the argument order in your atan2 function)

    0 讨论(0)
  • 2020-12-09 01:22

    Have a look at the pdf document linked below. It explains how to apply the plane figure algorithm that Bill the Lizard mentions, but on the surface of a sphere.

    poster thumbnail and some details http://img51.imageshack.us/img51/4093/centroidspostersummary.jpg
    Source: http://www.jennessent.com/arcgis/shapes_poster.htm
    There is also a 25 MB full-size PDF available for download.
    Credit goes to mixdev for finding the link to the original source, and of course to Jenness Enterprises for making the information available. Note: I am in no way affiliated with the author of this material.

    0 讨论(0)
  • 2020-12-09 01:25

    Separately average the latitudes and longitudes.

    0 讨论(0)
  • 2020-12-09 01:26

    Adding to Andrew Rollings' answer.

    You will also need to make sure that if you have points on either side of the 0/360 longitude line that you are measuring in the "right direction"

    Is the center of (0,359) and (0, 1) at (0,0) or (0,180)?
    
    0 讨论(0)
  • 2020-12-09 01:33

    The math is pretty simple if the points form a plane figure. There's no guarantee, however, that a set of latitudes and longitudes are that simple, so it may first be necessary to find the convex hull of the points.

    EDIT: As eJames points out, you have to make corrections for the surface of a sphere. My fault for assuming (without thinking) that this was understood. +1 to him.

    0 讨论(0)
  • The below PDF has a bit more detail than the poster from Jenness Enterprises. It also handles conversion in both directions and for a spheroid (such as the Earth) rather than a perfect sphere.

    Converting between 3-D Cartesian and ellipsoidal latitude, longitude and height coordinates

    0 讨论(0)
提交回复
热议问题