是否可以使用JavasScript确定GeoJSON点是否在GeoJSON多边形内? [英] Is it possible to determine if a GeoJSON point is inside a GeoJSON polygon using JavasScript?

查看:305
本文介绍了是否可以使用JavasScript确定GeoJSON点是否在GeoJSON多边形内?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以仅使用JavaScript(通过d3,topojson或其他方式)确定给定纬度上的GeoJSON点是否位于给定的GeoJSON多边形内?

Is it possible to determine whether a GeoJSON point at a given lat,lon lies within a given GeoJSON polygon using only JavaScript (either through d3, topojson, or any other way)?

例如,我可以在此处.

然后我有一些点具有坐标,但是没有指示它们位于哪个国家/地区.

I then have a some points which have coordinates but no indication as to which country they lie within.

我想显示每个国家的总积分.

I would like to display a total point count for each country.

我可以算出哪个国家/地区包含浏览器中的每个点,还是需要使用PostGIS或类似工具在服务器上预处理我的点数据?

Can I work out which country contains each point in the browser, or do I need to preprocess my point data on the server using PostGIS or similar?

推荐答案

好像您已经了解了d3一样:

Seems like d3 has you covered: https://github.com/d3/d3-geo#geoContains

d3.geoContains(对象,点)

d3.geoContains(object, point)

当且仅当指定的GeoJSON对象包含指定的点时才返回true,否则返回false.该点必须指定为以度为单位的两元素数组[经度,纬度].对于点和多点几何,将使用精确测试.对于Sphere,始终返回true;否则,返回true.对于其他几何形状,将应用epsilon阈值.

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.

这篇关于是否可以使用JavasScript确定GeoJSON点是否在GeoJSON多边形内?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆