三调管理信息系统
三调管理信息系统
1、系统主界面
2、右键功能
3、测量功能
4、图层选择
部分源码
部分源码-数据添加
//添加ShapeFile
public static void AddShapefile(AxMapControl mapControl)
{
OpenFileDialog pOpenFileDialog = new OpenFileDialog();
pOpenFileDialog.CheckFileExists = true;
pOpenFileDialog.Title = “打开Shape文件”;
pOpenFileDialog.Filter = “Shape文件(*.shp)|*.shp”;
pOpenFileDialog.Multiselect = true;
if (pOpenFileDialog.ShowDialog()==DialogResult.OK)
{
string[] strShapeFiles = pOpenFileDialog.FileNames;
for (int i = 0; i < strShapeFiles.Length; i++)
{
IWorkspaceFactory pWorkspaceFactory;
IFeatureWorkspace pFeatureWorkspace;
IFeatureLayer pFeatureLayer;
string pFullPath = strShapeFiles[i];
int pIndex = pFullPath.LastIndexOf(“\\”);
string pFilePath = pFullPath.Substring(0, pIndex); //文件路径
string pFileName = pFullPath.Substring(pIndex + 1); //文件名
//实例化ShapefileWorkspaceFactory工作空间,打开Shape文件
pWorkspaceFactory = new ShapefileWorkspaceFactory();
pFeatureWorkspace = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(pFilePath, 0);
//创建并实例化要素集
IFeatureClass pFeatureClass = pFeatureWorkspace.OpenFeatureClass(pFileName);
pFeatureLayer = new FeatureLayer();
pFeatureLayer.FeatureClass = pFeatureClass;
pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName;
mapControl.Map.AddLayer(pFeatureLayer);
mapControl.ActiveView.Refresh();
}
}
}
//添加栅格文件
public static void AddRasterfile(AxMapControl mapControl)
{
OpenFileDialog pOpenFileDialog = new OpenFileDialog();
pOpenFileDialog.CheckFileExists = true;
pOpenFileDialog.Title = “打开Raster文件”;
pOpenFileDialog.Filter = “栅格文件 (*.*)|*.bmp;*.tif;*.jpg;*.img|(*.bmp)|*.bmp|(*.tif)|*.tif|(*.jpg)|*.jpg|(*.img)|*.img”;
pOpenFileDialog.Multiselect = true;
if (pOpenFileDialog.ShowDialog()==DialogResult.OK)
{
string[] strRasterArr = pOpenFileDialog.FileNames;
for (int i = 0; i < strRasterArr.Length; i++)
{
string pRasterFileName = strRasterArr[i];
string pPath = System.IO.Path.GetDirectoryName(pRasterFileName);
string pFileName = System.IO.Path.GetFileName(pRasterFileName);
IWorkspaceFactory pWorkspaceFactory = new RasterWorkspaceFactory();
IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(pPath, 0);
IRasterWorkspace pRasterWorkspace = pWorkspace as IRasterWorkspace;
IRasterDataset pRasterDataset = pRasterWorkspace.OpenRasterDataset(pFileName);
//影像金字塔判断与创建
IRasterPyramid3 pRasPyrmid;
pRasPyrmid = pRasterDataset as IRasterPyramid3;
if (pRasPyrmid != null)
{
if (!(pRasPyrmid.Present))
{
pRasPyrmid.Create(); //创建金字塔
}
}
IRaster pRaster;
pRaster = pRasterDataset.CreateDefaultRaster();
IRasterLayer pRasterLayer;
pRasterLayer = new RasterLayerClass();
pRasterLayer.CreateFromRaster(pRaster);
ILayer pLayer = pRasterLayer as ILayer;
mapControl.AddLayer(pLayer, 0);
mapControl.ActiveView.Refresh();
}
}
}
//添加CAD文件
public static void AddCADByLayer(AxMapControl mapControl)
{
IWorkspaceFactory pWorkspaceFactory;
IFeatureWorkspace pFeatureWorkspace;
IFeatureLayer pFeatureLayer;
IFeatureClass pFeatureClass;
OpenFileDialog pOpenFileDialog = new OpenFileDialog();
pOpenFileDialog.Filter = “CAD(*.dwg)|*.dwg”;
pOpenFileDialog.Title = “打开CAD数据文件”;
pOpenFileDialog.Multiselect = false;
if (pOpenFileDialog.ShowDialog()==DialogResult.OK)
{
string pFullPath = pOpenFileDialog.FileName;
//获取文件名和文件路径
int pIndex = pFullPath.LastIndexOf(“\\”);
string pFilePath = pFullPath.Substring(0, pIndex);
string pFileName = pFullPath.Substring(pIndex + 1);
pWorkspaceFactory = new CadWorkspaceFactory();
pFeatureWorkspace = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(pFilePath, 0);
//加载CAD文件中的线文件
pFeatureClass = pFeatureWorkspace.OpenFeatureClass(pFileName + “:polyline”);
pFeatureLayer = new FeatureLayerClass();
pFeatureLayer.Name = pFileName;
pFeatureLayer.FeatureClass = pFeatureClass;
mapControl.Map.AddLayer(pFeatureLayer);
mapControl.ActiveView.Refresh();
}
}
//添加GDB
private void BTN_OpenGDB_ItemClick(object sender, ItemClickEventArgs e)
{
MyFolderBrowserDialog mfbd = new MyFolderBrowserDialog();
if (mfbd.ShowDialog(this) == DialogResult.OK)
{
listFLayer = new List<IFeatureLayer>();
axMapControl1.ClearLayers();//清空地图
TabCt_AddAttributes.TabPages.Clear();//清空属性表
string strGDB_Path = mfbd.DirectoryPath;
//strZHQSelGDBPath = mfbd.DirectoryPath;
FileGDBWorkspaceFactory fac = new FileGDBWorkspaceFactory();
IFeatureWorkspace pFtWS = (IFeatureWorkspace)fac.OpenFromFile(strGDB_Path, 0);
IWorkspace pWork = (IWorkspace)pFtWS;
IEnumDataset pEnumDs = pWork.get_Datasets(esriDatasetType.esriDTFeatureClass);
IDataset pDs = pEnumDs.Next();
axMapControl1.Map.ClearLayers();
//tslbStatus.Text = “正在加载要素…”;
statusStrip1.Refresh();
while (pDs != null)
{
IFeatureClass temp = pDs as IFeatureClass;
IFeatureLayer tempLayer = new FeatureLayer();
tempLayer.FeatureClass = temp;
tempLayer.Name = tempLayer.FeatureClass.AliasName;
listFLayer.Add(tempLayer);
axMapControl1.AddLayer(tempLayer);
axTOCControl1.Refresh();
//listBox_unck_FtLy.Items.Add(tempLayer.FeatureClass.AliasName);
//tspCombx_unck_SFZ.Items.Add(tempLayer.FeatureClass.AliasName);
pDs = pEnumDs.Next();
}
//tslbStatus.Text = “加载完成!”;
tlSpStLb_GDBPath.Caption = “当前数据库:” + strGDB_Path;
//tlSpStLb.Text += ” 当前数据库:” + Path.GetFileName(strGDB_Path);
statusStrip1.Refresh();
}
}
部分源码-打开属性表(动态添加属性表控件)
public partial class UCFormAttribute : DevExpress.XtraEditors.XtraUserControl
{
public UCFormAttribute()
{
InitializeComponent();
}
IFeatureLayer pTocFeatureLayer = null;
public void InitData(IFeatureLayer pTocFtLayer)
{
gridControl1.DataSource = null;
pTocFeatureLayer = pTocFtLayer;
gridControl1.DataSource= FeatureLayterToDataTable(pTocFeatureLayer.FeatureClass);
// groupControl1.Text = pTocFeatureLayer.FeatureClass.AliasName;
}
public IMap pMap = null;
public AxMapControl pMapControl = null;
private DataTable FeatureLayterToDataTable(IFeatureClass pFeatCls)
{
DataTable dt = new DataTable();
IFeature pFeature = null;
DataTable pFeatDT = new DataTable(); //创建数据表
DataRow pDataRow = null; //数据表行变量
DataColumn pDataCol = null; //数据表列变量
IField pField = null;
for (int i = 0; i < pFeatCls.Fields.FieldCount; i++)
{
pDataCol = new DataColumn();
pField = pFeatCls.Fields.get_Field(i);
pDataCol.ColumnName = pField.Name; //获取字段名作为列标题
pDataCol.DataType = Type.GetType(“System.Object”);//定义列字段类型
pFeatDT.Columns.Add(pDataCol); //在数据表中添加字段信息
}
IFeatureCursor pFeatureCursor = pFeatCls.Search(null, true);
pFeature = pFeatureCursor.NextFeature();
while (pFeature != null)
{
pDataRow = pFeatDT.NewRow();
//获取字段属性
for (int k = 0; k < pFeatDT.Columns.Count; k++)
{
pDataRow[k] = pFeature.get_Value(k);
}
pFeatDT.Rows.Add(pDataRow); //在数据表中添加字段属性信息
pFeature = pFeatureCursor.NextFeature();
}
//释放指针
System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatureCursor);
dt = pFeatDT;
return dt;
}
int selObjID= -1;
private void gridView1_MouseUp(object sender, MouseEventArgs e)
{
int selectindex = gridView1.SelectedRowsCount;
if (e.Button == MouseButtons.Right && selectindex == 1)
{
DataRow dr = gridView1.GetDataRow(gridView1.FocusedRowHandle);
selObjID = Convert.ToInt32(dr[0].ToString());
popupMenu1.ShowPopup(Control.MousePosition);
}
}
private void TSMenuIt_Panto_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
IFeature pFeature =pTocFeatureLayer.FeatureClass.GetFeature(selObjID);
clsFlashFeatureClass.PanToFeature(pFeature, pMapControl);
}
private void TSMenuIt_Zoomto_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
IFeature pFeature = pTocFeatureLayer.FeatureClass.GetFeature(selObjID);
clsFlashFeatureClass.ZoomToFeature(pFeature, pMapControl);
}
private void TSMenuIt_Flash_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
IFeature pFeature = pTocFeatureLayer.FeatureClass.GetFeature(selObjID);
clsFlashFeatureClass.FlashFeature(pFeature, pMapControl);
}
}
部分源码-创建mdb gdb
public static class clsCreateDataBaseHelper
{
/// <summary>
/// 创建mdb数据库,返回其工作空间
/// </summary>
/// <param name=”strMdbPath”></param>
/// <returns></returns>
private static IWorkspace CreateMdb(string strMdbPath)
{
string sPathFloder = System.IO.Path.GetDirectoryName(strMdbPath);
string sPathName = System.IO.Path.GetFileName(strMdbPath);
//string sFileExtension = System.IO.Path.GetExtension(strMdbPath).ToUpper();
IWorkspaceName pWorkspaceName = null;
string sWorkspaceId = “esriDataSourcesGDB.AccessWorkspaceFactory”;
pWorkspaceName = ((IWorkspaceFactory)Activator.CreateInstance(Type.GetTypeFromProgID(sWorkspaceId))).Create(sPathFloder, sPathName, null, 0);
IName name = (IName)pWorkspaceName;
IWorkspace workspace = (IWorkspace)name.Open();
return workspace;
}
/// <summary>
/// 创建gdb数据库,返回其工作空间
/// </summary>
/// <param name=”strGdbPath”></param>
/// <returns></returns>
private static IWorkspace CreateGdb(string strGdbPath)
{
string sPathFloder = System.IO.Path.GetDirectoryName(strGdbPath);
string sPathName = System.IO.Path.GetFileName(strGdbPath);
string sWorkspaceId = “esriDataSourcesGDB.FileGDBWorkspaceFactory”;
IWorkspaceName pWorkspaceName = null;
pWorkspaceName = ((IWorkspaceFactory)Activator.CreateInstance(Type.GetTypeFromProgID(sWorkspaceId))).Create(sPathFloder, sPathName, null, 0);
IName name = (IName)pWorkspaceName;
IWorkspace workspace = (IWorkspace)name.Open();
return workspace;
}
public static IWorkspace CreateMdb()
{
IWorkspace workspace = null;
SaveFileDialog ofd = new SaveFileDialog();
ofd.Filter = “mdb文件(*.mdb)|*.mdb”;
ofd.AddExtension = true;
ofd.Title = “新建mdb数据库”;
if (ofd.ShowDialog() == DialogResult.OK)
{
workspace = CreateMdb(ofd.FileName);
}
return workspace;
}
public static IWorkspace CreateGdb()
{
IWorkspace workspace = null;
FolderBrowserDialog fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() == DialogResult.OK)
{
string foldername = fbd.SelectedPath;
string strGDBPath = foldername + “.gdb”;
//string gdbName = Path.GetFileName(strGDBPath);
//Computer computer = new Computer();
//computer.FileSystem.RenameDirectory(fbd.SelectedPath, gdbName);
workspace = CreateGdb(strGDBPath);
DirectoryInfo di = new DirectoryInfo(foldername);
di.Delete(false);
}
return workspace;
}
}
欢迎交流:18798835893