Skip to content

Instantly share code, notes, and snippets.

@NPS-ARCN-CAKN
Last active August 29, 2015 14:19
Show Gist options
  • Save NPS-ARCN-CAKN/5ef102a7e0c2672cc3ab to your computer and use it in GitHub Desktop.
Save NPS-ARCN-CAKN/5ef102a7e0c2672cc3ab to your computer and use it in GitHub Desktop.
SQL: Select points that fall within a polygon
-- SQL Server 2008R2, there are better functions in later versions of Sql Server such as STContains()
SELECT Animals.GroupNumber
FROM LegacyUnits INNER JOIN
Animals ON LegacyUnits.PolygonFeature.STIntersects(Animals.Location) = 1
-- Here is an UPDATE query example:
UPDATE Animals
SET Unit = LegacyUnits.LegacyUnitID
FROM LegacyUnits INNER JOIN
Animals ON LegacyUnits.PolygonFeature.STIntersects(Animals.Location) = 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment