I'm trying to create a buffer around a single point in a spatial entity and finding all the points from a different entity that fall within that buffer. I tried two approaches. The code below runs without error but returns no records, even though I know from looking at the data in ArcMap that there should records should come up (increasing the buffer to a huge number also didn't return any records). Removing the last line seems to create a buffer around every point in the incidents entity and finds every point in the hydrants entity. I want to figure out how to do this around just one point in the hydrants entity.
SELECT incidents.id_incident, hydrants.OBJECTID_1
FROM zelaya2.dbo.incidents, zelaya2.dbo.HYDRANTS
WHERE Shape.STBuffer(1000).STIntersects(incidents.geog) = 1
AND hydrants.OBJECTID_1 = 177619;
Also tried setting a temporary variable as the buffer, but again got no records returns and no error message.
DECLARE @g geography;
Set @g =
(SELECT hydrants.Shape.STBuffer(1000)
FROM zelaya2.dbo.hydrants
WHERE OBJECTID_1 = 177619)
SELECT *
FROM zelaya2.dbo.incidents
WHERE @g.STIntersects(incidents.geog) = 1
EDIT: I confirmed that both layers are SRID 4326
SELECT DISTINCT shape.STSrid FROM zelaya2.dbo.HYDRANTS;
and the same for incidents. If they are different then you have an issue with SRIDs SQL Server will not compare geometries or geographies with different SRIDs. It may be worthwhile putting up some test data and table schemas for people to try things out for you. The query you are trying should work, so it is likely to be a data issue.geometry
, then a 1000 degree buffer would be generated, and an invalid geometry would result.