Thanks to visit codestin.com
Credit goes to github.com

Skip to content

pcpc/geopointsPolygon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

geopointsPolygon

Extracting the geographic points from the polygon in the GeoJSON file to use with the POLYGON() SQL Server function.

Usage example

node geopoints.js exampleCityArea.geojson

The polygon geometry that comes from this command, will output as exampleCityArea.txt.

Here is how you can find a point inside of a polygon by using the polygon.geomtry from the result output text file (which will be stored in your database)

To check if a point is within a polygon in SQL Server, you use the "STIntersects" function on the geometry data type, where you compare your point geometry to the polygon geometry; if the point intersects the polygon (meaning it falls within its boundary), the result will be TRUE, indicating the point is inside the polygon. [1, 2, 3, 4, 5, 6]
Key points about point-in-polygon in SQL Server: [1, 3, 7]

• Geometry data type: Both the point and polygon should be stored as geometry data types in your SQL Server database. [1, 3, 7]
• STIntersects function: This is the primary function used to check if a point is within a polygon. [1, 2, 6]

Example SQL query:

SELECT
    CASE WHEN point.geometry.STIntersects(polygon.geometry) THEN 'Point is inside polygon'
         ELSE 'Point is outside polygon' END AS result
FROM PointTable AS point
INNER JOIN PolygonTable AS polygon
ON -- Join condition based on your data
WHERE point.geometry = /* Your point geometry */
  AND polygon.geometry = /* Your polygon geometry */

Explanation: [1, 3, 7]

• point.geometry: Represents the geometry of your point data. [1, 3, 7]
• polygon.geometry: Represents the geometry of your polygon data. [1, 2, 7]
• STIntersects: This function checks if the point geometry intersects with the polygon geometry. [1, 2, 6]
• CASE statement: The result is returned as a string indicating whether the point is inside or outside the polygon. [1, 2, 5]

Important considerations: [3, 7]

• Spatial reference system (SRID): Ensure both your point and polygon geometries use the same SRID for accurate spatial calculations. [3, 7]
• Complex polygons: If your polygons have holes, you might need to use additional spatial functions to accurately check for points inside the polygon's interior. [1, 8]

Generated by Google

[1] https://learn.microsoft.com/en-us/sql/relational-databases/spatial/polygon?view=sql-server-ver16
[2] https://community.esri.com/t5/arcgis-enterprise-questions/obtain-polygon-geometry-points-for-sql-stintersect/td-p/409370
[3] https://learn.microsoft.com/en-us/sql/relational-databases/spatial/point?view=sql-server-ver16
[4] https://autogis-site.readthedocs.io/en/latest/lessons/lesson-3/point-in-polygon-queries.html
[5] https://en.wikipedia.org/wiki/Point_in_polygon
[6] https://www.youtube.com/watch?v=f0YJFp7BQyc
[7] https://community.safe.com/transformers-9/geometryreplacer-from-microsoft-sql-server-binary-for-multi-polygon-type-27842
[8] https://ir.lib.nycu.edu.tw/bitstream/11536/749/1/A1997WM15100010.pdf

About

Extracting the geographic points in the polygon of the GeoJSON file.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors