private void menuItemExportTransformedSketch_Click(object sender, EventArgs e) { var dialog = new SaveFileDialog(); dialog.Filter = "Shp文件(*.shp)|*.shp"; dialog.AddExtension = true; if (dialog.ShowDialog() == DialogResult.OK) { var xmlDialog = new OpenFileDialog(); xmlDialog.Filter = "控制点坐标(*.xml)|*.xml"; if (xmlDialog.ShowDialog() == DialogResult.OK) { List <HorizontalCoordinate> sourceCoordinates, targetCoordinates; KVS.Open(dialog.FileName, out targetCoordinates, out sourceCoordinates); var param4 = LinearTransformation.GetTransformationParameter(sourceCoordinates, targetCoordinates); var pathName = Path.GetDirectoryName(dialog.FileName); var fileName = Path.GetFileNameWithoutExtension(dialog.FileName); var nVertices = m_mapDocument.GetSketchPointCount(); double[] adfX = new double[1]; double[] adfY = new double[1]; double[] adfZ = new double[1]; var shpFileName = string.Format(@"{0}\{1}_point.shp", pathName, fileName); var hSHP = Shapelib.SHPCreate(shpFileName, Shapelib.ShapeType.Point); for (int i = 0; i < nVertices; i++) { m_mapDocument.GetSketchPointInfo(i, ref adfX, ref adfY, ref adfZ, param4); var psObject = Shapelib.SHPCreateSimpleObject(Shapelib.ShapeType.Point, nVertices, adfX, adfY, adfZ); Shapelib.SHPWriteObject(hSHP, -1, psObject); } Shapelib.SHPClose(hSHP); m_outputWindow.OutputText("点文件已存为:" + shpFileName); nVertices = m_mapDocument.GetSketchPolylineCount(); shpFileName = string.Format(@"{0}\{1}_polyline.shp", pathName, fileName); hSHP = Shapelib.SHPCreate(shpFileName, Shapelib.ShapeType.PolyLine); for (int i = 0; i < nVertices; i++) { var count = m_mapDocument.GetSketchPolylinePointCount(i); adfX = new double[count]; adfY = new double[count]; adfZ = new double[count]; m_mapDocument.GetSketchPolylineInfo(i, ref adfX, ref adfY, ref adfZ, param4); var psObject = Shapelib.SHPCreateSimpleObject(Shapelib.ShapeType.PolyLine, count, adfX, adfY, adfZ); var iLine = Shapelib.SHPWriteObject(hSHP, -1, psObject); } Shapelib.SHPClose(hSHP); m_outputWindow.OutputText("线文件已存为:" + shpFileName); nVertices = m_mapDocument.GetSketchPolygonCount(); shpFileName = string.Format(@"{0}\{1}_polygon.shp", pathName, fileName); hSHP = Shapelib.SHPCreate(shpFileName, Shapelib.ShapeType.Polygon); for (int i = 0; i < nVertices; i++) { var count = m_mapDocument.GetSketchPolygonPointCount(i); adfX = new double[count]; adfY = new double[count]; adfZ = new double[count]; m_mapDocument.GetSketchPolygonInfo(i, ref adfX, ref adfY, ref adfZ, param4); var psObject = Shapelib.SHPCreateSimpleObject(Shapelib.ShapeType.Polygon, count, adfX, adfY, adfZ); var iPolygon = Shapelib.SHPWriteObject(hSHP, -1, psObject); } Shapelib.SHPClose(hSHP); m_outputWindow.OutputText("面文件已存为:" + shpFileName); } } }
private void menuItemExportSketch_Click(object sender, EventArgs e) { var dialog = new SaveFileDialog(); dialog.Filter = "Shp文件(*.shp)|*.shp"; dialog.AddExtension = true; if (dialog.ShowDialog() == DialogResult.OK) { var pathName = Path.GetDirectoryName(dialog.FileName); var fileName = Path.GetFileNameWithoutExtension(dialog.FileName); var nVertices = m_mapDocument.GetSketchPointCount(); double[] adfX = new double[1]; double[] adfY = new double[1]; double[] adfZ = new double[1]; var shpFileName = string.Format(@"{0}\{1}_point.shp", pathName, fileName); var hSHP = Shapelib.SHPCreate(shpFileName, Shapelib.ShapeType.Point); var dbfFileName = string.Format(@"{0}\{1}_point.dbf", pathName, fileName); var hDBF = Shapelib.DBFCreate(dbfFileName); int iField = Shapelib.DBFAddField(hDBF, "Id", Shapelib.DBFFieldType.FTString, 50, 0); for (int i = 0; i < nVertices; i++) { m_mapDocument.GetSketchPointInfo(i, ref adfX, ref adfY, ref adfZ); var psObject = Shapelib.SHPCreateSimpleObject(Shapelib.ShapeType.Point, nVertices, adfX, adfY, adfZ); Shapelib.SHPWriteObject(hSHP, -1, psObject); Shapelib.DBFWriteStringAttribute(hDBF, i, iField, string.Format("{0}#草图点", i + 1)); } Shapelib.DBFClose(hDBF); Shapelib.SHPClose(hSHP); m_outputWindow.OutputText("点文件已存为:" + shpFileName); nVertices = m_mapDocument.GetSketchPolylineCount(); shpFileName = string.Format(@"{0}\{1}_polyline.shp", pathName, fileName); hSHP = Shapelib.SHPCreate(shpFileName, Shapelib.ShapeType.PolyLine); dbfFileName = string.Format(@"{0}\{1}_polyline.dbf", pathName, fileName); hDBF = Shapelib.DBFCreate(dbfFileName); iField = Shapelib.DBFAddField(hDBF, "Id", Shapelib.DBFFieldType.FTInteger, 14, 0); for (int i = 0; i < nVertices; i++) { var count = m_mapDocument.GetSketchPolylinePointCount(i); adfX = new double[count]; adfY = new double[count]; adfZ = new double[count]; m_mapDocument.GetSketchPolylineInfo(i, ref adfX, ref adfY, ref adfZ); var psObject = Shapelib.SHPCreateSimpleObject(Shapelib.ShapeType.PolyLine, count, adfX, adfY, adfZ); var iLine = Shapelib.SHPWriteObject(hSHP, -1, psObject); Shapelib.DBFWriteIntegerAttribute(hDBF, i, iField, i); } Shapelib.DBFClose(hDBF); Shapelib.SHPClose(hSHP); m_outputWindow.OutputText("线文件已存为:" + shpFileName); nVertices = m_mapDocument.GetSketchPolygonCount(); shpFileName = string.Format(@"{0}\{1}_polygon.shp", pathName, fileName); hSHP = Shapelib.SHPCreate(shpFileName, Shapelib.ShapeType.Polygon); dbfFileName = string.Format(@"{0}\{1}_polygon.dbf", pathName, fileName); hDBF = Shapelib.DBFCreate(dbfFileName); iField = Shapelib.DBFAddField(hDBF, "Id", Shapelib.DBFFieldType.FTInteger, 14, 0); for (int i = 0; i < nVertices; i++) { var count = m_mapDocument.GetSketchPolygonPointCount(i); adfX = new double[count]; adfY = new double[count]; adfZ = new double[count]; m_mapDocument.GetSketchPolygonInfo(i, ref adfX, ref adfY, ref adfZ); var psObject = Shapelib.SHPCreateSimpleObject(Shapelib.ShapeType.Polygon, count, adfX, adfY, adfZ); var iPolygon = Shapelib.SHPWriteObject(hSHP, -1, psObject); Shapelib.DBFWriteIntegerAttribute(hDBF, i, iField, i); } Shapelib.DBFClose(hDBF); Shapelib.SHPClose(hSHP); m_outputWindow.OutputText("面文件已存为:" + shpFileName); } }