I have a table of 40 polygons, they contain name, id and the geometry. I have a second table of addresses with it's own geometry represented as points. I have aggregated the 40 polygons using geometry::UnionAggregate
.
I want to be able to return the id of the polygon for one point in particular from my table of addresses.
The following is my code but I get a true value (1) for each of the 40 polygons. I was expecting 39 nulls
and '1' for the polygon that actually contains the point. Is this because it is now treating the aggregated polygons as one entity now so therefore they all contain the point?
I am new to spatial queries and may be missing something blindingly obvious but would appreciate some help.
declare @n geometry
set @n = (select geometry::UnionAggregate(sp_geometry) from Polygons)
declare @p geometry
set @p = (select sp_geometry from PointData);
select n.id from Polygons n, pointdata p
where @n.MakeValid().STWithin(@p) = 1