当前位置:文档之家› GIS二次开发编程学习总结

GIS二次开发编程学习总结

1、从集合体中提取点集的方法
m_GeoPtCol = new List>();
switch (m_Geometry.GeometryType)
{
case geoGEOMETRYTYPE.GEO_GEOMETRY_POLYLINE:
pGeoCol = m_Geometry as GeometryCollection;
for (int i = 0; i < pGeoCol.Count; i++)
{
IPath pPath;
pPath = pGeoCol.GetAt(i) as IPath;
IPointArray pPtAry;
pPtAry = pPath as IPointArray;
m_GeoPtCol.Add(PtArrayToPtLst(pPtAry));
}
break;
case geoGEOMETRYTYPE.GEO_GEOMETRY_POLYGON:
pGeoCol = m_Geometry as GeometryCollection;
for (int i = 0; i < pGeoCol.Count; i++)
{
IRing pRing;
pRing = pGeoCol.GetAt(i) as IRing;
IPointArray pPtAry;
pPtAry = pRing as IPointArray;
m_GeoPtCol.Add(PtArrayToPtLst(pPtAry));
}
break;
case geoGEOMETRYTYPE.GEO_GEOMETRY_POINT:
List ptLst = new List();
ptLst.Add(m_Geometry as Point);
m_GeoPtCol.Add(ptLst);
break;
}
}

2、手写控件的方法
lstPart.SelectedIndexChanged += new EventHandler(lstPart_SelectedIndexChanged);
dgv_Points.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(dgv_Points_CellClick);
ContextMenuStrip cMenu = new System.Windows.Forms.ContextMenuStrip();
ToolStripMenuItem item = new ToolStripMenuItem("导出坐标");
item.Click += new EventHandler(item_Click);
cMenu.Items.Add(item);

ToolStripMenuItem itemDeleteRow = new ToolStripMenuItem("删除点");
itemDeleteRow.Click += new EventHandler(itemDeleteRow_Click);
cMenu.Items.Add(itemDeleteRow);

ToolStripMenuItem itemAddPoint = new ToolStripMenuItem("添加点");
itemAddPoint.Click += new EventHandler(itemAddPoint_Click);
cMenu.Items.Add(itemAddPoint);

this.dgv_Points.ContextMenuStrip = cMenu;

顶点编辑方法
public void AlterPoint()//修改面要素顶点坐标
{
//IFeature pFeature = m_Feature;
//IFeatureClass pFeatureClass = pFeature.FeatureClass;
//if (pFeature == null)
//{
// MessageBox.Show("未选中要素!!!");
// return;
//}
IGeometry pGeometry = m_Feature.Geometry;
ILine pLine=null;
ISegmentArray pSegmentArray=new RingClass();
Point prePoint = null;
Point nextPoint = null;

ISegmentArray pPath = new PathClass();
for (int i = 0; i < dgv_Points.Rows.Count; i++)
{

if (prePoint == null)
{

nextPoint = new PointClass();
nextPoint.X = Convert.ToDouble(dgv_Points.Rows[i].Cells[1].Value);
nextPoint.Y = Convert.ToDouble(dgv_Points.Rows[i].Cells[2].Value);
pLine = new LineClass();
prePoint = nextPoint;
i++;
}
if (nextPoint != null)
{
nextPoint = new PointClass();
nextPoint.X = Convert.ToDouble(dgv_Points.Rows[i].Cells[1].Value);
nextPoint.Y = Convert.ToDouble(dgv_Points.Rows[i].Cells[2].Value);
pLine.PutCoords(prePoint, nextPoint);
pSegmentArray.Add(pLine as ISegment);
pPath.Add(pLine);
pLine = new LineClass();
prePoint = nextPoint;
}
}
if (pGeometry.GeometryType == geoGEOMETRYTYPE.GEO_GEOMETRY_POLYGON)
{
IRing pRing = pSegmentArray as IRing;
pRing.Close();
IGeometryCollection pPolygon = new PolygonClass();
pPolygon.Add(pRing);
m_Feature.Geometry = pPolygon as IGeometry;
}
if (pGeometry.GeometryType == geoGEOMETRYTYPE.GEO_GEOMETRY_POLYLINE)
{
IGeometryCollection pPolyline = new PolylineClass();
pPolyline.Add(pPath as IGeometry);
m_Feature.Geometry = pPolyline as IGeometry;
}
m_Feature.Store();
System.Runtime.InteropServices.Marshal.ReleaseComObject(m_Feature);
MFeature = m_Feature;
}

public void DeletePoint()
{
//getPtCol();
int rowIndex = -1;
rowIndex = dgv_Points.CurrentRow.Index;
IGeometry pGeometry = m_Feature.Geometry;
ILine pLine = null;
ISegmentArray pSegmentArray = new RingClass();
Point prePoint = null;
Point nextPoint = null;
ISegmentArray pPath = new PathClass();
for (int i = 0; i < dgv_Points.Rows.Count; i++)
{
if (prePoint == null)
{
if (i == rowIndex)
{
continue;
}
nextPoint = new PointClass();
nextPoint.X = Convert.ToDouble(dgv_Points.Rows[i].Cells[1].Value);
nextPoint.Y = Convert.ToDouble(dgv_Points.Rows[i].Cells[2].Value);
pLine = new LineClass();
prePoint = nextPoint;
i++;
}


if (nextPoint != null)
{
if (i == rowIndex)
{
continue;
}
nextPoint = new PointClass();
nextPoint.X = Convert.ToDouble(dgv_Points.Rows[i].Cells[1].Value);
nextPoint.Y = Convert.ToDouble(dgv_Points.Rows[i].Cells[2].Value);
pLine.PutCoords(prePoint, nextPoint);
pSegmentArray.Add(pLine as ISegment);
pPath.Add(pLine as ISegment);
pLine = new LineClass();
prePoint = nextPoint;
}
}
if (pGeometry.GeometryType == geoGEOMETRYTYPE.GEO_GEOMETRY_POLYGON)
{
IRing pRing = pSegmentArray as IRing;
pRing.Close();
IPointArray pPtAry;
pPtAry = pRing as IPointArray;
IGeometryCollection pPolygon = new PolygonClass();
pPolygon.Add(pRing);
m_Feature.Geometry = pPolygon as IGeometry;
}
if (pGeometry.GeometryType == geoGEOMETRYTYPE.GEO_GEOMETRY_POLYLINE)
{
IGeometryCollection pPolyline = new PolylineClass();
pPolyline.Add(pPath as IGeometry);
m_Feature.Geometry = pPolyline as IGeometry;
}
m_Feature.Store();
System.Runtime.InteropServices.Marshal.ReleaseComObject(m_Feature);
//dgv_Points.Rows.RemoveAt(rowIndex);
//dgv_Points.Update();
MFeature = m_Feature;
}

private void AddPoint()
{
int rowIndex = -1;
rowIndex = dgv_Points.CurrentRow.Index;
DataRow pRow = m_DataTable.NewRow();
pRow[0] = rowIndex;
pRow[1] = 0.0;
pRow[2] = 0.0;
m_DataTable.Rows.InsertAt(pRow,rowIndex);
dgv_Points.DataSource = m_DataTable;
//dgv_Points.Rows[rowIndex].Cells[1].Value = 0.0;
//dgv_Points.Rows[rowIndex].Cells[2].Value = 0.0;
IGeometry pGeometry = m_Feature.Geometry;
ILine pLine = null;
ISegmentArray pSegmentArray = new RingClass();
Point prePoint = null;
Point nextPoint = null;
ISegmentArray pPath = new PathClass();
for (int i = 0; i < dgv_Points.Rows.Count; i++)
{
if (prePoint == null)
{
nextPoint = new PointClass();
nextPoint.X = Convert.ToDouble(dgv_Points.Rows[i].Cells[1].Value);
nextPoint.Y = Convert.ToDouble(dgv_Points.Rows[i].Cells[2].Value);
pLine = new LineClass();
prePoint = nextPoint;
i++;
}
if (nextPoint != null)


{
if (i == rowIndex)
{
continue;
}
nextPoint = new PointClass();
nextPoint.X = Convert.ToDouble(dgv_Points.Rows[i].Cells[1].Value);
nextPoint.Y = Convert.ToDouble(dgv_Points.Rows[i].Cells[2].Value);
pLine.PutCoords(prePoint, nextPoint);
pSegmentArray.Add(pLine as ISegment);
pPath.Add(pLine as ISegment);
pLine = new LineClass();
prePoint = nextPoint;
}
}
if (pGeometry.GeometryType == geoGEOMETRYTYPE.GEO_GEOMETRY_POLYGON)
{
IRing pRing = pSegmentArray as IRing;
pRing.Close();
IPointArray pPtAry;
pPtAry = pRing as IPointArray;
IGeometryCollection pPolygon = new PolygonClass();
pPolygon.Add(pRing);
m_Feature.Geometry = pPolygon as IGeometry;
}
if (pGeometry.GeometryType == geoGEOMETRYTYPE.GEO_GEOMETRY_POLYLINE)
{
IGeometryCollection pPolyline = new PolylineClass();
pPolyline.Add(pPath as IGeometry);
m_Feature.Geometry = pPolyline as IGeometry;
}
m_Feature.Store();
System.Runtime.InteropServices.Marshal.ReleaseComObject(m_Feature);
//dgv_Points.Update();
AlterPoint();
MFeature = m_Feature;
}


相关主题
文本预览
相关文档 最新文档