/// <summary>
/// 每条线都是闭合的线-首尾相连
/// </summary>
/// <param name="lyrPath"></param>
/// <param name="fieldName">过滤字段</param>
/// <param name="fieldVal">过滤值</param>
/// <returns></returns>
public List<IFeature> LineStringIsLinearRing(string[] lyrPaths, string fieldName, string fieldVal)
{
var fsAll = new List<IFeature>();
foreach (var path in lyrPaths)
{
foreach (var shapefileFeature in ShpUtils.FS(path))
{
fsAll.Add(shapefileFeature);
}
}
var fsResult = InnerLineStringIsLinearRing(lyrPaths[0],fsAll, fieldName, fieldVal);
return fsResult;
}
InnerLineStringIsLinearRing
方法实现:
private List<IFeature> InnerLineStringIsLinearRing(string lyrPath, List<IFeature> fsAll, string fieldName, string fieldVal)
{
var tol = 0.0001;
var dataName = Path.GetFileNameWithoutExtension(lyrPath);
var fsResult = new List<IFeature>();
foreach (var f in fsAll)
{
var fieldObj = DbaseFileHeaderEx.Attr(lyrPath, fieldName, f.Attributes);
var coveredStart = false;
var coveredEnd = false;
if (f.Geometry == null || f.Geometry.IsEmpty)
{
continue;
}
Coordinate start = null;
Coordinate end = null;
GeometryStartEndPoints(f.Geometry, ref start, ref end);
if(start == null || end == null)
{
Commons.LogHelper.Warn(lyrPath + "几何对象不正确,无法检查");
}
start = f.Geometry.Coordinates[0];
end = f.Geometry.Coordinates[f.Geometry.Coordinates.Length - 1];
//var fieldObj = f.Attributes[fieldName];
if (fieldObj != null && fieldObj.ToString() == fieldVal)
{
if (start.Equals2D(end)) continue;
foreach (var f1 in fsAll)
{
if (f == f1)
continue;
if (f1.Geometry == null || f1.Geometry.IsEmpty) continue;
if (f1.Geometry.Distance(new Point(start)) < tol)
coveredStart = true;
if (f1.Geometry.Distance(new Point(end)) < tol)
coveredEnd = true;
if (coveredStart && coveredEnd) break;
}
}
else
{
continue;
}
if (!(coveredStart && coveredEnd))
{
fsResult.Add(f);
}
}
return fsResult;
}