From 3e181e60c94921a17635cdd6a23b8e30b5ebf5a3 Mon Sep 17 00:00:00 2001 From: David Blasby Date: Wed, 18 Jul 2001 22:17:34 +0000 Subject: [PATCH] Added function: point_inside_circle(geometry, Px, Py, d) - returns true if there is a point in geometry whose distance to (Px,Py) is < d git-svn-id: http://svn.osgeo.org/postgis/trunk@18 b70326c6-7e19-0410-871a-916f4a2858ee --- postgis.h | 2 ++ postgis.sql.in | 6 ++++++ postgis_fn.c | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/postgis.h b/postgis.h index 3d749f254..c034e77b9 100644 --- a/postgis.h +++ b/postgis.h @@ -371,6 +371,8 @@ Datum ellipsoid_in(PG_FUNCTION_ARGS); Datum length_ellipsoid(PG_FUNCTION_ARGS); Datum length3d_ellipsoid(PG_FUNCTION_ARGS); +Datum point_inside_circle(PG_FUNCTION_ARGS); + //for GIST index diff --git a/postgis.sql.in b/postgis.sql.in index ca3213f07..5b797d812 100644 --- a/postgis.sql.in +++ b/postgis.sql.in @@ -230,6 +230,12 @@ CREATE FUNCTION truly_inside(GEOMETRY,GEOMETRY) AS '@MODULE_FILENAME@' LANGUAGE 'c' with (isstrict); +CREATE FUNCTION point_inside_circle(GEOMETRY,float8,float8,float8) + RETURNS bool + AS '@MODULE_FILENAME@' + LANGUAGE 'c' with (isstrict); + + ------- Aggregate CREATE FUNCTION combine_bbox(BOX3D,GEOMETRY) diff --git a/postgis_fn.c b/postgis_fn.c index 6e462f8f5..dbed0cc0c 100644 --- a/postgis_fn.c +++ b/postgis_fn.c @@ -1455,4 +1455,42 @@ Datum force_collection(PG_FUNCTION_ARGS) +// point_inside_circle(geometry, Px, Py, d) +// returns true if there is a point in geometry whose distance to (Px,Py) is < d +PG_FUNCTION_INFO_V1(point_inside_circle); +Datum point_inside_circle(PG_FUNCTION_ARGS) +{ + + GEOMETRY *geom = (GEOMETRY *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); + char *o; + int type1,j; + int32 *offsets1; + POINT3D *pt; + double Px = PG_GETARG_FLOAT8(1); + double Py = PG_GETARG_FLOAT8(2); + double d = PG_GETARG_FLOAT8(3); + double dd = d*d; //d squared + + offsets1 = (int32 *) ( ((char *) &(geom->objType[0] ))+ sizeof(int32) * geom->nobjs ) ; + + //now have to do a scan of each object + + for (j=0; j< geom->nobjs; j++) //for each object in geom + { + o = (char *) geom +offsets1[j] ; + type1= geom->objType[j]; + + if (type1 == POINTTYPE) //point + { + //see if its within d of Px,Py + pt = (POINT3D *) o; + if ( ( (pt->x - Px)*(pt->x - Px) + (pt->y - Py)*(pt->y - Py) ) < dd) + { + PG_RETURN_BOOL(TRUE); + } + } + + } + PG_RETURN_BOOL(FALSE); +} \ No newline at end of file -- 2.49.0