5

Calculating the centroid several time on a number of geographical points. I was wondering is there a perl or python module that could make my life easier when working with large datasets of lat long points?

A coworker recommended using the perl module Math::Polygon, and that the polygon_centroid() function could be of some use, however I would like to know of other options.

0

2 Answers 2

11

If you want to do this in Python I'd recommend the Shapely library. You could read all your points into a MultiPoint object, and every object in Shapley has a centroid property. A quick sample:

from shapely.geometry import MultiPoint
points = MultiPoint([(0.0, 0.0), (1.0, 1.0)])
print points.centroid #True centroid, not necessarily an existing point
print points.representative_point() #A represenative point, not centroid,
                                    #that is guarnateed to be with the geometry.

One thing to note - it's fine if all your lat-long data is in the same projection/datum, but Shapely is projection agnostic, so if your data needs to be projected you need to do it yourself before adding it.

0
2

You might want to check out ESRI's help on working with geometry. You will want to use the Describe function and the shapeFieldName property. There are two properties for centroids that you can use. One is called centroid which is the true centroid if it is within or on the feature; otherwise, returns the label point (returns a point object). The other is called trueCentroid which returns the centre of gravity (centroid) regardless of whether it is actually within the shape or not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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