[postgis-users] distance from centroid to the points that form the outer boundary of the polygon

17 views
Skip to first unread message

Yamini Singh

unread,
Jul 30, 2012, 9:04:15 AM7/30/12
to PostGIS User List

Hi All,

 

I am looking for suggestions for the following problem I have at hand.

 

1.       I have a table that contain multipolygons

2.       I want to calculate the maximum distance of points that form the polygon  from the centroid of the polygon. For example of the polygon is formed of 50 points then I want to have distance of all the 50 points from the centroid of the polygon.

 

I am not sure if someone has done this before. But I am finding it difficult to implement it. Any help in this regards is welcome…


Best,

YJS

Edward Mac Gillavry

unread,
Jul 30, 2012, 9:21:56 AM7/30/12
to postgi...@postgis.refractions.net
Hi there,

How about calculating the MinimumBoundingCircle of your geometry first http://postgis.refractions.net/docs/ST_MinimumBoundingCircle.html. Once you have the circle, it shouldn't be too difficult to derive the radius from this?

HTH

Edward


From: yamini...@live.com
To: postgi...@postgis.refractions.net
Date: Mon, 30 Jul 2012 15:04:15 +0200
Subject: [postgis-users] distance from centroid to the points that form the outer boundary of the polygon
_______________________________________________ postgis-users mailing list postgi...@postgis.refractions.net http://postgis.refractions.net/mailman/listinfo/postgis-users

Tom van Tilburg

unread,
Jul 30, 2012, 4:05:23 PM7/30/12
to postgi...@postgis.refractions.net
Hi Yamini,

Are you sure that multipolygons is what you want to work with? Since a multipolygon can consist of multiple polygons (obviously) who share a common centroid that can be way outside your actual polygons.

That said, I would make use of ST_Dumppoints to do that.
Something like:
============
WITH pointsdump AS
(
    SELECT gid, ST_Centroid(geom) AS centre, (ST_Dumppoints(geom)).geom AS point FROM polygontable
)

SELECT gid, ST_Distance(centre, point) AS distance FROM pointsdump
===========

Now for every point in a geometry with a known gid you will see the distance to it's centroid.
You can do statistics on these numbers with something like:
    SELECT gid, avg(distance) avg, max(distance) max, etc... FROM results GROUP BY gid

Cheers,
 Tom
Reply all
Reply to author
Forward
0 new messages