I have two tables that I am storing geometries in.
CREATE TABLE config.region
(
id int identity(1,1) PRIMARY KEY,
polygon GEOMETRY NOT NULL
)
CREATE TABLE config.location
(
id int identity(1,1) PRIMARY KEY,
position GEOMETRY
)
The region table will hold rectangular polygons. The location table will hold only points.
What I want to do is select all the regions and a COUNT of how many points are actually within each polygon.
I've come up with this query, that shows the polygon id, the location id and whether or not the location is in the polygon.
SELECT
polygon.id as pid,
config.location.id as lid,
polygon,
polygon.STContains(config.location.position) as within
FROM
config.polygon, config.location
How can I modify this to give counts instead of just a list of whether or not they are within each other?