Re: postgres 9.2.2 point conversion from polygon doesn't always give accurate center

From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Colin Dunklau <colin(dot)dunklau(at)gmail(dot)com>, pgsql-bugs(at)postgresql(dot)org
Subject: Re: postgres 9.2.2 point conversion from polygon doesn't always give accurate center
Date: 2013-02-03 09:16:51
Message-ID: CAEZATCXPokwKBGEBLkPEyH_kWhoUA6Ua9hJxQgLxiOtjtopDWA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On 1 February 2013 22:16, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Colin Dunklau <colin(dot)dunklau(at)gmail(dot)com> writes:
>> Hello! I believe I've found a bug in the type conversion process from
>> polygon to point.
>
>> In the documentation found here
>> http://www.postgresql.org/docs/9.2/interactive/functions-geometry.html,
>
>> Table 9-32 claims that running the point() function on a polygon
>> returns the "center of polygon". This is not the case for some
>> polygons, as shown below.
>
> It looks like what the code is actually computing is the average X
> position and average Y position of the points listed in the polygon.

That's correct. This is the most common definition used for the centre
of a polygon --- formally referred to as the centroid. See for example
http://en.wikipedia.org/wiki/Centroid

cdunklau=# select point( polygon '((0,0),(1,0),(1,1),(1,0))');
point
-------------
(0.75,0.25)
(1 row)

That is the correct answer. One way to think about the centroid is as
the centre of gravity of the polygon. In this case the polygon is an
"L" shape, so imagine balancing an "L" shaped object on knife edge ---
it would balance if the edge was aligned at 45 degrees to the sides of
the L, cutting each edge in half. So the centroid is halfway along the
line that connects the midpoints of the L shape.

It's also easy to see that the centroid is definitely not at (0.5,
0.5) because the entire polygon lies to the northwest / southeast of
that point.

Regards,
Dean

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Dean Rasheed 2013-02-03 09:33:19 Re: postgres 9.2.2 point conversion from polygon doesn't always give accurate center
Previous Message Georgi Georgiev 2013-02-03 04:36:54 Re: BUG #7823: PGDG packaged pgadmin3_92 removes its /usr/bin/pgadmin3 link