部分重要代码

  • 格式:docx
  • 大小:1.39 MB
  • 文档页数:5

privatevoid数据读取与显示ToolStripMenuItem_Click(object sender, EventArgs e)

{

}

privatevoid读取数据ToolStripMenuItem_Click(object sender, EventArgs e)

{

string filename;

OpenFileDialog MyFileDialog = newOpenFileDialog();

MyFileDialog.Filter = "Excel Files97-03(*.xls)|*.xls|All files(*.*)|*.*";

MyFileDialog.FilterIndex = 1;

MyFileDialog.RestoreDirectory = false;

if (MyFileDialog.ShowDialog() == DialogResult.OK)

{

filename = MyFileDialog.FileName;

}

else

{

return;

}

data = newLoadExcel(filename);

if (!data.readFile())

{

return;

}

if (data != null)

{

MessageBox.Show("成功读取数据", "提示");

return;

}

}

privatevoid显示到图层ToolStripMenuItem_Click(object sender, EventArgs e)

{

if (data == null)

{

MessageBox.Show("请先读取数据", "错误");

return;

}

Display polygon = newDisplay(data, "area");

polygonLayer = polygon.getLayer();

m_mapControl.AddLayer(polygonLayer, 0);

}

privatevoid压矿分析ToolStripMenuItem_Click(object sender, EventArgs e)

{

}

privatevoid读入数据ToolStripMenuItem_Click(object sender, EventArgs e)

{

/*string filename; OpenFileDialog MyFileDialog = new OpenFileDialog();

MyFileDialog.Filter = "Excel Files(*.xls;*.xlsx)|*.xls;*.xlsx|All

files(*.*)|*.*";

MyFileDialog.FilterIndex = 1;

MyFileDialog.RestoreDirectory = false;

if (MyFileDialog.ShowDialog() == DialogResult.OK)

{

filename = MyFileDialog.FileName;

}

else

{

return;

}

DataTable MyDataTable = new DataTable();

MyDataTable = ReadExcel(filename);

int RowCount = MyDataTable.Rows.Count;

DealExel Out_Data = new DealExel();

double X;

double Y;

IPoint pPoint;

for (int i = 0; i < RowCount; i++)//转换坐标

{

string Str_Data = MyDataTable.Rows[i][2].ToString();

X = double.Parse(Str_Data) / 1000;

Str_Data = MyDataTable.Rows[i][3].ToString();

Y = double.Parse(Str_Data) / 1000;

pPoint = new ESRI.ArcGIS.Geometry.Point();

pPoint.X = X;

pPoint.Y = Y;

pPoint = GetpProjectPoint(pPoint, true);

Out_Data.Longitude.Add(pPoint.X);

Out_ytitude.Add(pPoint.Y);

}

//string FilePath = FilePath + strShapeFile;

//IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory();

//IFeatureWorkspace pFeatureWorkspace =

(IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(Folder, 0);

string storePath = System.Environment.CurrentDirectory;

IWorkspaceFactory workspacefactory = new ShapefileWorkspaceFactoryClass();

IFeatureWorkspace pFeatureWorkspace =

(IFeatureWorkspace)workspacefactory.OpenFromFile(storePath, 0);

IFeatureClass pFeatureClass;

IFields pFields = new Fields();

IFieldsEdit pFieldsEdit = (IFieldsEdit)pFields;

IField pField = new Field();

IFieldEdit pFieldEdit = (IFieldEdit)pField;

ISpatialReferenceFactory spatialReferenceFactory = new

SpatialReferenceEnvironment();

IGeographicCoordinateSystem pGCS; pGCS =

spatialReferenceFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_AGD1984);

_2 = "SHAPE";

pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;

IGeometryDefEdit pGeoDef = new GeometryDef() as IGeometryDefEdit;

IGeometryDefEdit pGeoDefEdit = (IGeometryDefEdit)pGeoDef;

pGeoDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;

pGeoDefEdit.SpatialReference_2 = pGCS;

pFieldEdit.GeometryDef_2 = pGeoDef;

pFieldsEdit.AddField(pField);

string strShapeFile = "Out_test_Data";

pFeatureClass = pFeatureWorkspace.CreateFeatureClass(strShapeFile, pFields,

null, null, esriFeatureType.esriFTSimple, "SHAPE", "");

IPolygon pPolygon = new ESRI.ArcGIS.Geometry.PolygonClass();

//IPolygon pPolygon = new ESRI.ArcGIS.Geometry.Polygon() as IPolygon ;

pPolygon = Out_Data.CreatePolygon();

IFeature pFeature = pFeatureClass.CreateFeature();

pFeature.Shape = pPolygon;