本文主要是介绍GIS管道流向分析,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一、开发思路
1.设置起点,和水管路线。
2.从起点开始分级遍历树结构管线,如果形成回路的判断上一级最短的路线作为流向连接点。
二、详细代码
private List<IPolyline> lis;
private void 流向ToolStripMenuItem_Click(object sender, EventArgs e)
{
IFeatureLayer playerS = getLayer("b") as IFeatureLayer;
IFeatureLayer gx = getLayer("a") as IFeatureLayer;
IPoint pointS = playerS.FeatureClass.GetFeature(1).Shape as IPoint;
//获取所有线
lis = new List<IPolyline>();
IFeatureCursor pFC = gx.Search(null, false);
IFeature pfeature = pFC.NextFeature();
while (pfeature != null)
{
IPolyline pline = pfeature.Shape as IPolyline;
lis.Add(pline);
pfeature = pFC.NextFeature();
}
drawLine(pointS);
}
private void drawLine(IPoint pointS)
{
List<IPolyline> lisLine = queryLine(pointS, lis);//查点相交线
MoveList(lisLine, pointS);//移除回路线
List<Dictionary<IPolyline, IPoint>> lisPoint = new List<Dictionary<IPolyline, IPoint>>();
foreach (IPolyline item in lisLine)
{
Dictionary<IPolyline, IPoint> endPointLine = drawArrow(item, pointS);//开始箭头
lisPoint.Add(endPointLine);
}
foreach (IPolyline item in lisLine)
{
Dictionary<IPolyline, IPoint> endPointLine = drawArrow(item, pointS);//开始箭头
lisPoint.Add(endPointLine);
if (lis.Count > 0)
{
foreach (KeyValuePair<IPolyline, IPoint> item1 in endPointLine)
{
drawLine(item1.Value);
}
}
}
}
//查询点相交线
private List<IPolyline> queryLine(IPoint pointS, List<IPolyline> lisLine)
{
List<IPolyline> lisP = new List<IPolyline>();
IRelationalOperator pRela = pointS as IRelationalOperator;
foreach (IPolyline item in lis)
{
bool isJont = pRela.Disjoint(item);
if (!isJont)
{
lisP.Add(item);
}
}
return lisP;
}
//画箭头返回未点
private Dictionary<IPolyline, IPoint> drawArrow(IPolyline pline, IPoint interPoint)
{
netAnalysic pnet = new netAnalysic();
IPoint point;
Dictionary<IPolyline, IPoint> dic = new Dictionary<IPolyline, IPoint>();
if (pline.FromPoint.X == interPoint.X && pline.FromPoint.Y == interPoint.Y)
{
pnet.DrawArrowElementForEdgeElement(pline, axMapControl1.Map);
point = pline.ToPoint;
}
else
{
IPolyline pline1 = new PolylineClass();
pline1.ToPoint = pline.FromPoint;
pline1.FromPoint = pline.ToPoint;
pnet.DrawArrowElementForEdgeElement(pline1, axMapControl1.Map);
point = pline.FromPoint;
}
lis.Remove(pline);
dic.Add(pline, point);
return dic;
}
//判断中间回路线
private void MoveList(List<IPolyline> lisLine, IPoint interPoint)
{
netAnalysic pnet = new netAnalysic();
foreach (IPolyline pline in lisLine)
{
IPoint startPoint = null;
if (pline.FromPoint.X == interPoint.X && pline.FromPoint.Y == interPoint.Y)
{
startPoint = pline.ToPoint;
}
else
{
startPoint = pline.FromPoint;
}
foreach (IPolyline pline1 in lisLine)
{
if (pline != pline1)
{
IPoint endPoint = null;
if (pline1.FromPoint.X == interPoint.X && pline1.FromPoint.Y == interPoint.Y)
{
endPoint = pline1.ToPoint;
}
else
{
endPoint = pline1.FromPoint;
}
IPolyline pline2 = new PolylineClass();
pline2.FromPoint = startPoint;
pline2.ToPoint = endPoint;
IPolyline pline3 = new PolylineClass();
pline3.FromPoint = endPoint;
pline3.ToPoint = startPoint;
IPolyline remoLine = null;
foreach (IPolyline itemLine in lis)
{
if (itemLine.FromPoint.X == startPoint.X && itemLine.FromPoint.Y == startPoint.Y && itemLine.ToPoint.X == endPoint.X && itemLine.ToPoint.Y == endPoint.Y)
{
if (pline.Length < pline1.Length)
{
pnet.DrawArrowElementForEdgeElement(pline2, axMapControl1.Map);
}
else
{
pnet.DrawArrowElementForEdgeElement(pline3, axMapControl1.Map);
}
remoLine = itemLine;
}
if (itemLine.ToPoint.X == startPoint.X && itemLine.ToPoint.Y == startPoint.Y && itemLine.FromPoint.X == endPoint.X && itemLine.FromPoint.Y == endPoint.Y)
{
if (pline.Length < pline1.Length)
{
pnet.DrawArrowElementForEdgeElement(pline2, axMapControl1.Map);
}
else
{
pnet.DrawArrowElementForEdgeElement(pline3, axMapControl1.Map);
}
remoLine = itemLine;
}
}
if (remoLine != null)
{
lis.Remove(remoLine);
}
}
}
}
}
三、结果展示
交流联系qq:875782548
这篇关于GIS管道流向分析的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!