Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to count how many points intersect each polygon using SQL SERVER

Hi so I have database of Polygons and Points with geometry data. I want to see how many intersect per polygon just showing the count of polygons with points in them.

This my script of finding the intersected points and polygons:

SELECT NEATCELL FROM 
[dbo].[POLYGON] as p,[PLACES6].[dbo].[Points] as h
WHERE P.NEATCELL.STIntersects(h.PointsGEOM) = 1  

Now I want to find how many points are there in each intersected polygon using the count function.So for this script I wanna do a count of how many points are there in neatcell. How do I go about doing that?

like image 960
ABaut Avatar asked Dec 11 '25 22:12

ABaut


1 Answers

The following query should get you the result you want:

SELECT 
    NEATCELL, 
    COUNT(*) AS NumberOfIntersections 
FROM 
    [dbo].[POLYGON] as p,
    [PLACES6].[dbo].[Points] as h
WHERE 
    P.NEATCELL.STIntersects(h.PointsGEOM) = 1
GROUP BY 
    NEATCELL
like image 71
David Tansey Avatar answered Dec 13 '25 18:12

David Tansey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!