是否可以使用 JavasScript 确定 GeoJSON 点是否在 GeoJSON 多边形内?
Is it possible to determine if a GeoJSON point is inside a GeoJSON polygon using JavasScript?
是否可以仅使用 JavaScript(通过 d3、topojson 或任何其他方式)来确定给定纬度、经度的 GeoJSON 点是否位于给定 GeoJSON 多边形内?
例如,我可以根据教程here绘制一张显示英国国家的地图。
然后我有一些点有坐标但没有指示它们位于哪个国家/地区。
我想显示每个国家/地区的总点数。
我能否在浏览器中找出哪个国家/地区包含每个点,或者我是否需要使用 PostGIS 或类似工具在服务器上预处理我的点数据?
似乎 d3
你涵盖了:https://github.com/d3/d3-geo#geoContains
d3.geoContains(object, point)
Returns true if and only if the specified GeoJSON object contains the specified point, or false if the object does not contain the point. The point must be specified as a two-element array [longitude, latitude] in degrees. For Point and MultiPoint geometries, an exact test is used; for a Sphere, true is always returned; for other geometries, an epsilon threshold is applied.
扩展 @thedude 答案,如果您需要对给定的 GeoJSON 进行多次检查,您也可以使用 geojson-lookup。
Turf.js provides a function called boolean-point-in-polygon
例如:
var pt = turf.point([-77, 44]);
var poly = turf.polygon([[
[-81, 41],
[-81, 47],
[-72, 47],
[-72, 41],
[-81, 41]
]]);
turf.booleanPointInPolygon(pt, poly);
//= true
是否可以仅使用 JavaScript(通过 d3、topojson 或任何其他方式)来确定给定纬度、经度的 GeoJSON 点是否位于给定 GeoJSON 多边形内?
例如,我可以根据教程here绘制一张显示英国国家的地图。
然后我有一些点有坐标但没有指示它们位于哪个国家/地区。
我想显示每个国家/地区的总点数。
我能否在浏览器中找出哪个国家/地区包含每个点,或者我是否需要使用 PostGIS 或类似工具在服务器上预处理我的点数据?
似乎 d3
你涵盖了:https://github.com/d3/d3-geo#geoContains
d3.geoContains(object, point)
Returns true if and only if the specified GeoJSON object contains the specified point, or false if the object does not contain the point. The point must be specified as a two-element array [longitude, latitude] in degrees. For Point and MultiPoint geometries, an exact test is used; for a Sphere, true is always returned; for other geometries, an epsilon threshold is applied.
扩展 @thedude 答案,如果您需要对给定的 GeoJSON 进行多次检查,您也可以使用 geojson-lookup。
Turf.js provides a function called boolean-point-in-polygon
例如:
var pt = turf.point([-77, 44]);
var poly = turf.polygon([[
[-81, 41],
[-81, 47],
[-72, 47],
[-72, 41],
[-81, 41]
]]);
turf.booleanPointInPolygon(pt, poly);
//= true