简体   繁体   English

查找 Lat Long position 是否在 esri shapefile 中

[英]Find if Lat Long position is in a shape in an esri shapefile

I am trying to use the Net Topology Suite (v 1.13.2) in a simple console app to find points in a shape file that contains road information.我正在尝试在一个简单的控制台应用程序中使用 Net Topology Suite (v 1.13.2) 来查找包含道路信息的形状文件中的点。

I have loaded the shape file and stored the data in a typed list, and I have checked that the data looks as expected..我已经加载了形状文件并将数据存储在一个类型化的列表中,并且我检查了数据是否符合预期..

When I iterate around the list I want to find if a given point is within any of the shapes in the shape file.当我遍历列表时,我想查找给定点是否在形状文件中的任何形状内。

Sounds straightforward!听起来很简单!

my code looks like;我的代码看起来像;

    private static Feature FindPoint(double lat, double lon)
    {
        Coordinate c = new Coordinate(lat, lon);

        IGeometry g = factory.CreateGeometry(Geometry.DefaultFactory.CreatePoint(c));

        foreach(Feature f in Features)
        {
            if (f.Geometry.Overlaps(g))
                return f;
            if (f.Geometry.EnvelopeInternal.Contains(c))
                return f;
            if (f.Geometry.Boundary.Contains(g))
                return f;
            if (f.Geometry.Contains(g))
                return f;
        }
        return null;
    }

None of these statements, or any of the others I have tried return any indication that the point is within any of the shapes in.这些陈述或我尝试过的任何其他陈述都没有返回任何指示该点位于任何形状内的指示。

I am trying with a Lat and Long I picked from one of the shapes in the file.我正在尝试从文件中的一个形状中挑选的经纬度。 SO it should be there.所以它应该在那里。

Any ideas as to where I am going wrong?关于我哪里出错的任何想法?

@Habib, I have checked and the geometry type is LineString, but the Envelope is defined as a polygon. @Habib,我已经检查过了,几何类型是 LineString,但是信封被定义为多边形。

I have looked at the link you sent, new code below;我查看了您发送的链接,下面是新代码;

DistanceOp dop = new DistanceOp(f.Geometry,g);
var np = dop.NearestPoints();
var d = dop.Distance();

Tried to do as indicated there, but the answer I get for the distance between the point I have chosen and the line is 71.236662957979718.尝试按照那里的指示进行操作,但我得到的关于我选择的点与线之间的距离的答案是 71.236662957979718。

71.236662957979718 what? 71.236662957979718 什么? cm, metres, degrees???厘米,米,度???

Strange anyway, as I have picked a point on one of the lines, so I would expect an answer of 0.无论如何,很奇怪,因为我在其中一条线上选择了一个点,所以我希望答案为 0。

Putting the longitude before the latitude while creating the coordinate got it working for me.在创建坐标时将经度放在纬度之前让它对我有用。

Corrected code:更正的代码:

private static Feature FindPoint(double lat, double lon)
{
    Coordinate c = new Coordinate(lon, lat);
    Geometry g = Geometry.DefaultFactory.CreatePoint(c);

    foreach(Feature f in Features)
    {
        if (f.Geometry.Contains(g))
            return f;
    }
    return null;
}

I'm using NetTopologySuite.IO.Esri found here: https://github.com/NetTopologySuite/NetTopologySuite.IO.Esri .我正在使用 NetTopologySuite.IO.Esri 在这里找到: https://github.com/NetTopologySuite/NetTopologySuite.IO

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM