Node.js / Javascript库来测试point是否在geojson multipolygon中 [英] Node.js/Javascript library to test if point is in geojson multipolygon

查看:140
本文介绍了Node.js / Javascript库来测试point是否在geojson multipolygon中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一些通常用于node.js或javascript的库,它提供了一个检查坐标是否在geojson多边形中的函数?

Is there some library for node.js or javascript in general that provides a function to check if a coordinate is in a geojson multipolygon?

我正在尝试创建一个小的HTTP API,告诉我哪些多边形(代表国家,县,城市等)包含给定的坐标。

I'm trying to create a small HTTP API that tells me which multipolygons (representing countries, counties, cities, etc.) contain a given coordinate.

我以为我会保留一个列表所有多重多边形和它们在内存中的边界框,然后首先检查每个多边形,如果它的边界框包含坐标。如果是,那么它将检查坐标是否在多边形本身。

I thought that I'll hold a list of all multipolygons & their bounding-box in memory and then first check for each polygon if its bounding box cointains the coordinate. If yes, then it'll check if the coordinate is in the multipolygon itself.

我知道有一个名为clipper的库得到了运行到javascript ,但似乎该库不提供简单的pointInPolygon函数,即使库本身非常强大。它仍然可能有这个库?

I know there's a library called "clipper" that got ported to javascript, but it seems that the library does not provide a simple "pointInPolygon" function, even if the library itself is very powerful.. Is it still possible with this library?

另外,我找到了另一个名为的库geojson-js-utils但它似乎不支持多重多边形(至少它没有在那里提到)

Additionally, I've found another library called "geojson-js-utils" but it does not seem to support multipolygons (at least it's not mentioned there)

我发现了一些其他库可以检查一个点是否在多边形中,但我不知道如何使用它们来检查一个点是否在多边形中。

I've found some other libraries that can check if a point is in a polygon, but I don't know how to use them to check if a point is in a multipolygon.

任何提示?

推荐答案

最新的Clipper 有一个高效的PointInPolygon功能。它使用算法多边形点Hormann& amp;和任意多边形的问题 Agathos。

In newest Clipper there is an efficient PointInPolygon function. It uses algorithm The Point in Polygon Problem for Arbitrary Polygons by Hormann & Agathos.

Javascript Clipper的PointInPolygon函数说:

ClipperLib.Clipper.PointInPolygon()

Number PointInPolygon(IntPoint pt, Path poly)

如果为假则返回0,如果pt在poly上则返回-1,如果pt在poly中则返回+1。

Returns 0 if false, -1 if pt is on poly and +1 if pt is in poly.

用法:

var poly = [{X:10,Y:10},{X:110,Y:10},{X:110,Y:110},{X:10,Y:110}];
var pt = new ClipperLib.IntPoint(50,50);
var inpoly = ClipperLib.Clipper.PointInPolygon(pt, poly);
// inpoly is 1, which means that pt is in polygon






要测试多面,您可以遍历子多边形并使用PointInPolygon检查它们。


To test multipolygon, you can traverse subpolygons and check them using PointInPolygon.

这篇关于Node.js / Javascript库来测试point是否在geojson multipolygon中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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