pggeodb.nancy.inra.fr/db_robot - db_robot on pggeodb.nancy.inra.fr
Previous topic Chapter index Next topic

Function: _st_concavehull

 

 

Schema

public

 

Owner

albenard

 

Descriptions

There is no description for function _st_concavehull

 

Options

Option

Value

Returns

public.geometry

Language

plpgsql

Parameters

param_inputgeom public.geometry

 

Definition

CREATE OR REPLACE FUNCTION public._st_concavehull (
 param_inputgeom public.geometry
)
RETURNS public.geometry AS
$span$
DECLARE

vexhull GEOMETRY;
var_resultgeom geometry;
var_inputgeom geometry;
vexring GEOMETRY;
cavering GEOMETRY;
cavept geometry[];
seglength double precision;
var_tempgeom geometry;
scale_factor float := 1;
i integer;

BEGIN

-- First compute the ConvexHull of the geometry
vexhull := public.ST_ConvexHull(param_inputgeom);
var_inputgeom := param_inputgeom;
--A point really has no concave hull
IF public.ST_GeometryType(vexhull) = 'ST_Point' OR public.ST_GeometryType(vexHull) = 'ST_LineString' THEN
RETURN
vexhull;
END IF;

-- convert the hull perimeter to a linestring so we can manipulate individual points
vexring := CASE WHEN public.ST_GeometryType(vexhull) = 'ST_LineString' THEN vexhull ELSE public.ST_ExteriorRing(vexhull) END;
IF abs(public.ST_X(public.ST_PointN(vexring,1))) < 1 THEN --scale the geometry to prevent stupid precision errors - not sure it works so make low for now
scale_factor := 100;
vexring := public.ST_Scale(vexring, scale_factor,scale_factor);
var_inputgeom := public.ST_Scale(var_inputgeom, scale_factor, scale_factor);
--RAISE NOTICE 'Scaling';
END IF;
seglength := public.ST_Length(vexring)/least(public.ST_NPoints(vexring)*2,1000) ;

vexring := public.ST_Segmentize(vexring, seglength);
-- find the point on the original geom that is closest to each point of the convex hull and make a new linestring out of it.
cavering := public.ST_Collect(
ARRAY(

SELECT
public
.ST_ClosestPoint(var_inputgeom, pt ) As the_geom
FROM (
SELECT  public.ST_PointN(vexring, n ) As pt, n
FROM
generate_series(1, public.ST_NPoints(vexring) ) As n
) As pt

)
)
;


var_resultgeom := public.ST_MakeLine(geom)
FROM public.ST_Dump(cavering) As foo;

IF public.ST_IsSimple(var_resultgeom) THEN
var_resultgeom := public.ST_MakePolygon(var_resultgeom);
--RAISE NOTICE 'is Simple: %', var_resultgeom;
ELSE
--RAISE NOTICE 'is not Simple: %', var_resultgeom;
var_resultgeom := public.ST_ConvexHull(var_resultgeom);
END IF;

IF scale_factor > 1 THEN -- scale the result back
var_resultgeom := public.ST_Scale(var_resultgeom, 1/scale_factor, 1/scale_factor);
END IF;
RETURN var_resultgeom;

END;
$span$
LANGUAGE
'plpgsql'
IMMUTABLE
RETURNS NULL ON NULL INPUT
SECURITY INVOKER
COST
100;

This file was generated with SQL Manager for PostgreSQL (www.pgsqlmanager.com) at 26/02/2014 11:51
Previous topic Chapter index Next topic