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
This commit is contained in:
David Blasby 2001-07-18 22:17:34 +00:00
parent c5a57438e3
commit 3e181e60c9
3 changed files with 46 additions and 0 deletions

View file

@ -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

View file

@ -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)

View file

@ -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);
}