NTS-NetTopologySuite中找出不在线上的点

逄边浩
2023-12-01
        /// <summary>
        /// 检查点是否有不在线上的情况
        /// </summary>
        /// <param name="pLyrPath">点shp路径</param>
        /// <param name="lineLyrPath">线shp路径</param>
        /// <param name="filterField">匹配的字段</param>
        /// <param name="filterVal">匹配的字段值</param>
        /// <returns>返回所有不在线上的点</returns>
        public List<IFeature> PointInLine(string pLyrPath, string lineLyrPath, string filterField, string filterVal,double tol = 0.0001)
        {
            var fs = new List<IFeature>();
            var fsPoints = ShpUtils.FS(pLyrPath);
            var fsLines = ShpUtils.FS(lineLyrPath);

            foreach (var fp in fsPoints)
            {
                var val = DbaseFileHeaderEx.Attr(pLyrPath,filterField,fp.Attributes);
                if (filterField != null && val != filterVal)
                {
                    continue;
                }
                IFeature theLine = null;
                foreach (var fl in fsLines)
                {
                    var geomP = fp.Geometry;
                    var geoL = fl.Geometry;
                    if (geoL.Distance(geomP) < tol)
                    {
                        theLine = fl;
                        break;
                    }
                }
                if (null == theLine)
                {
                    fs.Add(fp);
                }
            }
            return fs;
        }

其中:
ShpUtils.FS(pLyrPath);是获取shp文件中的所有要素。
DbaseFileHeaderEx.Attr获取要素指定的属性值

 类似资料: