1

是否有任何 StackExchange 更快的方法来验证该点是否在使用 Redis 的多边形中。

我有一个纬度和经度点,想知道它落在哪个城市。我有城市的多边形数据。

目前我正在使用此代码并且它可以工作,但是当我必须在数百个城市多边形中进行检查时,我发现它效率太低且不可扩展。想用 Redis 来做这件事。

请协助。

    City1.Add(new GeoPoints(5.9581, 1.11865));
    City1.Add(new GeoPoints(4.99572, -1.47411));
    City1.Add(new GeoPoints(6.19298, -2.00145));
    City1.Add(new GeoPoints(6.98422, 0.38257));
    City1.Add(new GeoPoints(5.9581, 1.11865));

    City2.Add(new GeoPoints(-6.4461, 39.11052));
    City2.Add(new GeoPoints(-7.19336, 39.68732));
    City2.Add(new GeoPoints(-7.23151, 38.98969));
    City2.Add(new GeoPoints(-7.00528, 38.55296));
    City2.Add(new GeoPoints(-6.4461, 39.11052));


public bool IsPointInPolygon(List<GeoPoints> poly, GeoPoints point)
{
    int i, j;
    bool c = false;
    for (i = 0, j = poly.Count - 1; i < poly.Count; j = i++)
    {
        if ((((poly[i].Lt <= point.Lt) && (point.Lt < poly[j].Lt))
                || ((poly[j].Lt <= point.Lt) && (point.Lt < poly[i].Lt)))
                && (point.Lg < (poly[j].Lg - poly[i].Lg) * (point.Lt - poly[i].Lt)
                    / (poly[j].Lt - poly[i].Lt) + poly[i].Lg))

            c = !c;
    }
    return c;
}
4

1 回答 1

0

AFAIK 目前 Redis 中没有任何支持多边形查询的地理 API;这是最接近的,它不会靠近。所以:我认为您不能为此使用香草redis。

可能有一个“模块”添加了这种用法;如果是这样,SE.Redis 允许通过 Execute 调用模块。

于 2021-08-29T17:12:42.963 回答