[postgis-users] Centroid 'Within'
Paragon Corporation
lr at pcorp.us
Wed Jun 22 12:56:35 PDT 2011
Sheara,
Here is a function we use that seems to work pretty well for our use-case.
CREATE OR REPLACE FUNCTION point_inside_geometry(param_geom geometry)
RETURNS geometry AS
$$
DECLARE
var_cent geometry := ST_Centroid(param_geom);
var_result geometry := var_cent;
BEGIN
-- If the centroid is outside the geometry then
-- calculate a box around centroid that is guaranteed to intersect the
geometry
-- take the intersection of that and find point on surface of intersection
IF NOT ST_Intersects(param_geom, var_cent) THEN
var_result := ST_PointOnSurface(ST_Intersection(param_geom,
ST_Expand(var_cent, ST_Distance(var_cent,param_geom)*2) ));
END IF;
RETURN var_result;
END;
$$
LANGUAGE plpgsql IMMUTABLE STRICT
COST 100;
Regina and Leo
h <http://www.postgis.us> ttp://www.postgis.us
_____
From: postgis-users-bounces at postgis.refractions.net
[mailto:postgis-users-bounces at postgis.refractions.net] On Behalf Of Sheara
Cohen
Sent: Wednesday, June 22, 2011 3:19 PM
To: postgis-users at postgis.refractions.net
Subject: [postgis-users] Centroid 'Within'
Hi All - I'm wondering if anyone has figured out a solution to converting a
polygon file to a centroid point file that produces centroids within the
polygons. Obviously, ST_Centroid doesn't produce centroids within the
polygon. And ST_PointOnSurface produces a point within that is only sort of
centroid-ish.
Any ideas would be great. Thank you!
~ Sheara
Sheara Cohen
Planner
C A L T H O R P E A S S O C I A T E S
2095 ROSE STREET, SUITE 201, BERKELEY, CALIFORNIA, 94709 USA
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20110622/390bc2a6/attachment.html>
More information about the postgis-users
mailing list