ArcGIS AddIn开发之:固定距离+节点生成点
2015-11-30 20:59
316 查看
用途:用以确定线状地物的控制点,设立界桩等控规、水域确权划界的业务需求。
此处只列出核心代码:
此处只列出核心代码:
private int generatePntsByFeature(IFeature pFeature,IFeatureLayer pPointLyr,int pntid) { IFeatureCursor pPointCursor = pPointLyr.FeatureClass.Insert(true); IWorkspaceEdit pwsEdit = (IWorkspaceEdit)((IDataset)pPointLyr.FeatureClass).Workspace; pwsEdit.StartEditing(false); pwsEdit.StartEditOperation(); string leixing = "", lnxuhao = "", suozaixiangzhen = "", leftorright = "", rivername = "", riverduanname = "", rvzimu = "", lxzimu = ""; if (chkJiaShan.Checked) //此处为某项目的特殊需求,用以实现对该项目相关属性的写入 { leixing = cmbLineType.Items[cmbLineType.SelectedIndex].ToString(); lnxuhao = pFeature.get_Value(pFeature.Fields.FindField("线段编号")).ToString(); suozaixiangzhen = pFeature.get_Value(pFeature.Fields.FindField("所在乡镇")).ToString(); leftorright = pFeature.get_Value(pFeature.Fields.FindField(cmbLeftOrRight.Items[cmbLeftOrRight.SelectedIndex].ToString())).ToString(); rivername = pFeature.get_Value(pFeature.Fields.FindField(cmbRiverName.Items[cmbRiverName.SelectedIndex].ToString())).ToString(); riverduanname = pFeature.get_Value(pFeature.Fields.FindField(cmbRiverDuanName.Items[cmbRiverDuanName.SelectedIndex].ToString())).ToString(); NCPinYinHelpercs ncp = new NCPinYinHelpercs(); rvzimu = rivername; lxzimu = leixing; //lxzimu = ncp.GetShortPinyin(leixing); if (leixing != "中心线") { //lxzimu = ncp.GetShortPinyin(leftorright.Substring(0, 1)) + "-" + lxzimu; lxzimu = leftorright.Substring(0, 1) + "-" + lxzimu; } } string pntArray = ""; if (rdVertex.Checked) <span style="font-family:Microsoft YaHei;">//根据线的节点生成点</span> { IPointCollection pntCol = (IPointCollection)pFeature.Shape; for (int i = 0; i < pntCol.PointCount; i++) { if (i == 0 && !chkOverLayPoint.Checked) { //检查首点是否重复 ISpatialFilter psf = new SpatialFilterClass(); ITopologicalOperator ptptmp =pntCol.get_Point(0) as ITopologicalOperator; IGeometry pgm = ptptmp.Buffer(0.2); psf.Geometry = pgm; psf.SpatialRel = esriSpatialRelEnum.esriSpatialRelEnvelopeIntersects; IFeatureCursor ptmpCursor = pPointLyr.FeatureClass.Search(psf, false); IFeature ptmpFeature = ptmpCursor.NextFeature(); if (ptmpFeature != null) { pntArray = "," + ptmpFeature.get_Value(ptmpFeature.Fields.FindField("信息点编号")).ToString(); continue; } } IFeatureBuffer pntFeatureBuffer = pPointLyr.FeatureClass.CreateFeatureBuffer(); pntFeatureBuffer.Shape = pntCol.get_Point(i); if (chkJiaShan.Checked) //项目需求,对属性的写入 { string nid = rvzimu + "-" + lxzimu + "-D" + pntid.ToString(); pntArray = pntArray + "," + nid; pntFeatureBuffer.set_Value(pntFeatureBuffer.Fields.FindField("信息点编号"), nid); pntFeatureBuffer.set_Value(pntFeatureBuffer.Fields.FindField("源序号"), leixing + "_" + lnxuhao); pntFeatureBuffer.set_Value(pntFeatureBuffer.Fields.FindField("所在乡镇"), suozaixiangzhen); pntFeatureBuffer.set_Value(pntFeatureBuffer.Fields.FindField("河道名称"), rivername); pntFeatureBuffer.set_Value(pntFeatureBuffer.Fields.FindField("河段名称"), riverduanname); pntFeatureBuffer.set_Value(pntFeatureBuffer.Fields.FindField("线段类型"), leixing); } else { //编号写入一个默认的字段中 pntFeatureBuffer.set_Value(pntFeatureBuffer.Fields.FindField("PointId"),pntid); } pPointCursor.InsertFeature(pntFeatureBuffer); pntid++; } pPointCursor.Flush(); } else if (rdEqualDis.Checked) //按照一定间距生成节点 { IPolyline pln = pFeature.Shape as IPolyline; IPoint pnt = null; for (double i = SplitDis; i < pln.Length; i = i + SplitDis) { if (i == 0) { if (!chkOverLayPoint.Checked) { //检查首点是否重复时 //检查首点是否重复 ISpatialFilter psf = new SpatialFilterClass(); ITopologicalOperator ptptmp =pln.FromPoint as ITopologicalOperator; IGeometry pgm = ptptmp.Buffer(0.2); psf.Geometry = pgm; psf.SpatialRel = esriSpatialRelEnum.esriSpatialRelEnvelopeIntersects; IFeatureCursor ptmpCursor = pPointLyr.FeatureClass.Search(psf, false); IFeature ptmpFeature = ptmpCursor.NextFeature(); if (ptmpFeature != null) { pntArray = "," + ptmpFeature.get_Value(ptmpFeature.Fields.FindField("信息点编号")).ToString(); continue; } else { //不包含,取首点 pnt = pln.FromPoint; } } else { //不检查时,直接取首点 pnt = pln.FromPoint; } } else if(i>0 && (pln.Length - i < 0.2 * SplitDis)) { //此代码的含义为最后一个点时,如果点很接近终点,则直接使用终点,不进行操作 break; } else { pnt = getpntAtDis(pln, i); } string nid; IFeatureBuffer pNewFeature = pPointLyr.FeatureClass.CreateFeatureBuffer(); nid = rvzimu + "-" + lxzimu + "-D" + pntid.ToString(); pNewFeature.Shape = pnt; pNewFeature.set_Value(pNewFeature.Fields.FindField("信息点编号"), nid); pNewFeature.set_Value(pNewFeature.Fields.FindField("源序号"), leixing + "-" + lnxuhao); pNewFeature.set_Value(pNewFeature.Fields.FindField("所在乡镇"), suozaixiangzhen); pNewFeature.set_Value(pNewFeature.Fields.FindField("河道名称"), rivername); pNewFeature.set_Value(pNewFeature.Fields.FindField("河段名称"), riverduanname); //pNewFeature.set_Value(pNewFeature.Fields.FindField("线段类型"), leixing); pPointCursor.InsertFeature(pNewFeature); pntArray = pntArray + "," + nid; pntid++; } //处理终点 pnt = pln.ToPoint; string nid2; IFeatureBuffer pNewFeature2 = pPointLyr.FeatureClass.CreateFeatureBuffer(); nid2 = rvzimu + "-" + lxzimu + "-D" + pntid.ToString(); pNewFeature2.Shape = pnt; pNewFeature2.set_Value(pNewFeature2.Fields.FindField("信息点编号"), nid2); pNewFeature2.set_Value(pNewFeature2.Fields.FindField("源序号"), leixing + "-" + lnxuhao); pNewFeature2.set_Value(pNewFeature2.Fields.FindField("所在乡镇"), suozaixiangzhen); pNewFeature2.set_Value(pNewFeature2.Fields.FindField("河道名称"), rivername); pNewFeature2.set_Value(pNewFeature2.Fields.FindField("河段名称"), riverduanname); //pNewFeature.set_Value(pNewFeature.Fields.FindField("线段类型"), leixing); pPointCursor.InsertFeature(pNewFeature2); pntArray = pntArray + "," + nid2; pntid++; pPointCursor.Flush(); } else if (rdMix.Checked) //节点+固定距离生成节点模式 { IPointCollection pntCol = (IPointCollection)pFeature.Shape; IPolyline pln = pFeature.Shape as IPolyline; //先生成节点序列,两两判断节点间距离,如果过长,则生成splitdis的等分点 IPoint CurrentPoint, PrePoint; for (int i = 0; i < pntCol.PointCount; i++) { if (i == 0 && !chkOverLayPoint.Checked) { //检查首点是否重复 ISpatialFilter psf = new SpatialFilterClass(); ITopologicalOperator ptptmp = pntCol.get_Point(0) as ITopologicalOperator; IGeometry pgm = ptptmp.Buffer(0.2); psf.Geometry = pgm; psf.SpatialRel = esriSpatialRelEnum.esriSpatialRelEnvelopeIntersects; IFeatureCursor ptmpCursor = pPointLyr.FeatureClass.Search(psf, false); IFeature ptmpFeature = ptmpCursor.NextFeature(); if (ptmpFeature != null) { pntArray = "," + ptmpFeature.get_Value(ptmpFeature.Fields.FindField("信息点编号")).ToString(); continue; } } IFeatureBuffer pntFeatureBuffer; string nid; //是否需要增加中点 if (i > 0) { CurrentPoint = pntCol.get_Point(i); PrePoint = pntCol.get_Point(i - 1); IPointCollection tmpPolyline = new PolylineClass(); tmpPolyline.AddPoint(PrePoint); tmpPolyline.AddPoint(CurrentPoint); double lenght = Math.Sqrt((CurrentPoint.X - PrePoint.X) * (CurrentPoint.X - PrePoint.X) + (CurrentPoint.Y - PrePoint.Y) * (CurrentPoint.Y - PrePoint.Y)); //此时需要增加中点 for (int zi = 0; zi < Math.Round(Math.Round(lenght / SplitDis) - 1);zi++ ) { IPoint pnt = getpntAtDis((IPolyline)tmpPolyline, (zi+1)*SplitDis); nid = rvzimu + "-" + lxzimu + "-D" + pntid.ToString(); pntArray = pntArray + "," + nid; pntFeatureBuffer = pPointLyr.FeatureClass.CreateFeatureBuffer(); pntFeatureBuffer.Shape = pnt; pntFeatureBuffer.set_Value(pntFeatureBuffer.Fields.FindField("信息点编号"), nid); pntFeatureBuffer.set_Value(pntFeatureBuffer.Fields.FindField("源序号"), leixing + "_" + lnxuhao); pntFeatureBuffer.set_Value(pntFeatureBuffer.Fields.FindField("所在乡镇"), suozaixiangzhen); pntFeatureBuffer.set_Value(pntFeatureBuffer.Fields.FindField("河道名称"), rivername); pntFeatureBuffer.set_Value(pntFeatureBuffer.Fields.FindField("河段名称"), riverduanname); //pntFeatureBuffer.set_Value(pntFeatureBuffer.Fields.FindField("线段类型"), leixing); pPointCursor.InsertFeature(pntFeatureBuffer); pntid++; } } nid = rvzimu + "-" + lxzimu + "-D" + pntid.ToString(); pntArray = pntArray + "," + nid; pntFeatureBuffer = pPointLyr.FeatureClass.CreateFeatureBuffer(); pntFeatureBuffer.Shape = pntCol.get_Point(i); pntFeatureBuffer.set_Value(pntFeatureBuffer.Fields.FindField("信息点编号"), nid); pntFeatureBuffer.set_Value(pntFeatureBuffer.Fields.FindField("源序号"), leixing + "_" + lnxuhao); pntFeatureBuffer.set_Value(pntFeatureBuffer.Fields.FindField("所在乡镇"), suozaixiangzhen); pntFeatureBuffer.set_Value(pntFeatureBuffer.Fields.FindField("河道名称"), rivername); pntFeatureBuffer.set_Value(pntFeatureBuffer.Fields.FindField("河段名称"), riverduanname); //pntFeatureBuffer.set_Value(pntFeatureBuffer.Fields.FindField("线段类型"), leixing); pPointCursor.InsertFeature(pntFeatureBuffer); pntid++; } pPointCursor.Flush(); } else { } string ssstmp = pntArray.Remove(0,1); pFeature.set_Value(pFeature.Fields.FindField("点序列"),ssstmp); //去掉第一个, pwsEdit.StopEditOperation(); pwsEdit.StopEditing(true); return pntid; } private IPoint getpntAtDis(IPolyline pln, double dis) { IConstructPoint pCPoint = new PointClass(); pCPoint.ConstructAlong(pln, esriSegmentExtension.esriNoExtension, dis, false); return (IPoint)pCPoint; }
相关文章推荐
- homerHEVC代码阅读(12)——基础结构之其他结构
- fibonacci数列(五种)
- Acm - 隔壁老王买酒问题
- LeetCode 36 Valid Sudoku(有效数独)
- js延迟加载
- ArcGIS 环境配置
- ZOJ 3582 Back to the Past [概率DP]
- 用指针函数输出学生成绩
- 【学习总结】【多线程】 安全隐患 & 通讯 & 线程的状态
- LeetCode_Jump Game
- 浅谈熵与贝叶斯
- string、vector
- HDOJ 1000 java版
- homerHEVC代码阅读(11)——基础结构之output_set_t、video_frame_t
- C语言精华代码
- 寻找相同元素的指针
- android H264码流中的SPS获取
- 数据结构例程——归并排序
- android开发技巧总结(68个常用用法)
- Web Services 指南之:Web Services 的特性