AE開發

来源:https://www.cnblogs.com/AEkaifa/archive/2018/01/18/8313146.html
-Advertisement-
Play Games

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;u ...


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.DataSourcesFile;
using System.Collections;

namespace 考試
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
this.axTOCControl1.SetBuddyControl(this.axMapControl1);
}

List<IFeature> sFeature;
private List<IFeature> RecSelectFetures(IFeatureLayer pFeatureLayer)
{
List<IFeature> pFeatures = new List<IFeature>();
if (pFeatureLayer != null)
{
IFeatureSelection pFeatureSelection = pFeatureLayer as IFeatureSelection;
pFeatureSelection.Clear();
axMapControl1.Refresh();

IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
IGeometry pGeometry = axMapControl1.TrackRectangle();
ISpatialFilter pSpatialFilter = new SpatialFilterClass();
pSpatialFilter.Geometry = pGeometry;
pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
IFeatureCursor pFeatureCursor = pFeatureLayer.Search(pSpatialFilter, false);
IFeature pFeature = pFeatureCursor.NextFeature();
pFeatureSelection.CombinationMethod = esriSelectionResultEnum.esriSelectionResultNew;
while (pFeature != null)
{
pFeatureSelection.Add(pFeature);
pFeatures.Add(pFeature);
pFeature = pFeatureCursor.NextFeature();
}
axMapControl1.ActiveView.Refresh();
}
return pFeatures;
}

 

private double ConvertPixelsToMapUnits(IActiveView pActiveView, double pixelUnits)
{
IPoint p1 = pActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds.UpperLeft;
IPoint p2 = pActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds.UpperRight;
int x1, x2, y1, y2;
pActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(p1, out x1, out y1);
pActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(p2, out x2, out y2);
double pixelExtent = x2 - x1;
double realWorldDisplayExtent = pActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds.Width;
double sizeOfOnePixel = realWorldDisplayExtent / pixelExtent;
return pixelUnits * sizeOfOnePixel;
}

private void CopyAttribute(IFeature pSourceFea, IFeature pTargetFea)
{
IFields pSourceFlds = pSourceFea.Fields;
for (int i = 0; i < pSourceFlds.FieldCount; i++)
{
IField pSourceFld = pSourceFlds.get_Field(i);
if ((pSourceFld.Type == esriFieldType.esriFieldTypeOID) ||
(pSourceFld.Type == esriFieldType.esriFieldTypeGeometry) ||
(pSourceFld.Type == esriFieldType.esriFieldTypeBlob))

continue;

string sSourceVal = pSourceFea.get_Value(i).ToString();
if (string.IsNullOrEmpty(sSourceVal))
continue;

int iTargetFldIndex = pTargetFea.Fields.FindField(pSourceFld.Name);
if (iTargetFldIndex >= 0)
pTargetFea.set_Value(iTargetFldIndex, sSourceVal);
}
}

private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Title = "打開文件";
dlg.Filter = "(*.mdb)|*.mdb|All Files(*.*)|*.* ";
dlg.ShowDialog();
string path = dlg.FileName;

IWorkspaceFactory pAccessWorkspaceFactory;
IFeatureWorkspace pFeatureWorkspace;
IFeatureLayer pFeatureLayer;
IFeatureDataset pFeatureDataset;
pAccessWorkspaceFactory = new AccessWorkspaceFactoryClass();

IWorkspace pWorkspace = pAccessWorkspaceFactory.OpenFromFile(path, 0);
IEnumDataset pEnumDataset = pWorkspace.get_Datasets(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTAny);
pEnumDataset.Reset();
IDataset pDataset = pEnumDataset.Next();

if (pDataset is IFeatureDataset)
{
pFeatureWorkspace = (IFeatureWorkspace)pAccessWorkspaceFactory.OpenFromFile(path, 0);
pFeatureDataset = pFeatureWorkspace.OpenFeatureDataset(pDataset.Name);
IEnumDataset pEnumDataset1 = pFeatureDataset.Subsets;
pEnumDataset1.Reset();
IDataset pDataset1 = pEnumDataset1.Next();

if (pDataset1 is IFeatureClass)
{
pFeatureLayer = new FeatureLayerClass();
pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass(pDataset1.Name);
pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName;
axMapControl1.Map.AddLayer(pFeatureLayer);
axMapControl1.ActiveView.Refresh();
}


}
else
{
pFeatureWorkspace = (IFeatureWorkspace)pWorkspace;
pFeatureLayer = new FeatureLayerClass();
pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass(pDataset.Name);
pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName;
axMapControl1.Map.AddLayer(pFeatureLayer);
axMapControl1.ActiveView.Refresh();
}
}

private void axMapControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
{
IMap pMap = axMapControl1.Map;
IActiveView pActiveView = pMap as IActiveView;
IFeatureLayer pFeatureLayer = pMap.get_Layer(0) as IFeatureLayer;
IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
IPoint point = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);
ITopologicalOperator pTOpo = point as ITopologicalOperator;
double length;
length = ConvertPixelsToMapUnits(pActiveView, 4);
IGeometry pBuffer = pTOpo.Buffer(length);
IGeometry pGeomentry = pBuffer.Envelope;
ISelectionEnvironment pSelEnv = new SelectionEnvironment();//新建選擇環境
IRgbColor pColor = new RgbColor();
pColor.Red = 255;
pSelEnv.DefaultColor = pColor;//設置高亮顏色
pMap.SelectByShape(pBuffer, pSelEnv, false);//選擇圖
axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null);

List<IFeature> S = RecSelectFetures(pFeatureLayer);
sFeature = S;
if (S.Count > 0)
{
treeList1.ClearNodes();
try
{
treeList1.BeginUpdate();
int k = 0;
for (int i = 0; i < S.Count; i++)
{
for (int j = 0; j < S[i].Fields.FieldCount; j++)
{
IField pFiled = S[i].Fields.get_Field(j);
treeList1.Columns.Add();
treeList1.Columns[j].Caption = pFiled.Name;
treeList1.Columns[j].VisibleIndex = j;
}
string sFirseFidValue = S[i].get_Value(0).ToString();
treeList1.AppendNode(new object[] { sFirseFidValue }, null);
for (int m = 1; m < S[i].Fields.FieldCount; m++)
{
object FieldValue;
if (S[i].Class.Fields.get_Field(m).Name == "SHAPE")
{
FieldValue = S[i].Shape.GeometryType.ToString();
}
else
{
FieldValue = S[i].get_Value(m).ToString();
}
treeList1.Nodes[k][m] = FieldValue;
}
k = k + 1;
}
}


catch (Exception exc)
{
MessageBox.Show("錯誤" + exc.ToString());
}
finally
{
treeList1.EndUpdate();
}
}
}

private void barButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
string serror = "";
for (int i = 0; i < sFeature.Count; i++)
{
IFeature pFeature = sFeature[i];
IFeatureClass pSourceFeaCls = pFeature.Class as IFeatureClass;
if (pSourceFeaCls == null)
return;
IWorkspace pSourceWks = (pSourceFeaCls as IDataset).Workspace;
ISpatialReference pSourceSpr = ((pSourceFeaCls as IDataset) as IGeoDataset).SpatialReference;

//string localFilePath, fileNameExt, newFileName, FilePath;
SaveFileDialog sfd = new SaveFileDialog();
//設置文件類型
sfd.Filter = "Shape(*.shp)|*.shp|All Files(*.*)|*.*";
sfd.CreatePrompt = false;
if (sfd.ShowDialog() != DialogResult.OK)
return;

//得到文件名和路徑
string strShppath = System.IO.Path.GetDirectoryName(sfd.FileName);
string strShpFile = System.IO.Path.GetFileNameWithoutExtension(sfd.FileName);

//創建shp工作空間
IWorkspaceFactory pWksFac = new ShapefileWorkspaceFactory();
IFeatureWorkspace pFeaWks = (IFeatureWorkspace)pWksFac.OpenFromFile(strShppath, 0);

//創建欄位集
IFields pFlds = new FieldsClass();
IFieldsEdit pFldsEdt = (IFieldsEdit)pFlds;
//創建基礎欄位
IField pFld = new FieldClass();
IFieldEdit pFldEdt = (IFieldEdit)pFld;
string strShapeFieldName = "shape";
pFldEdt.Name_2 = strShapeFieldName;
pFldEdt.Type_2 = esriFieldType.esriFieldTypeGeometry;
//為esriFieldTypeGeometry類型的欄位創建幾何定義
IGeometryDef pGeoDef = new GeometryDefClass();
IGeometryDefEdit pGeoDefEdit = (IGeometryDefEdit)pGeoDef;
pGeoDefEdit.GeometryType_2 = pSourceFeaCls.Fields.get_Field(1).GeometryDef.GeometryType;//設置shp文件的幾何類型
pGeoDefEdit.SpatialReference_2 = pSourceSpr;//設置shp文件的空間參考
pFldEdt.GeometryDef_2 = pGeoDef;
pFldsEdt.AddField(pFld);
//創建其他欄位
for (int j = 2; j < pSourceFeaCls.Fields.FieldCount; j++)
{
pFld = new FieldClass();
pFldEdt = (IFieldEdit)pFld;
pFldEdt.Name_2 = pSourceFeaCls.Fields.get_Field(j).Name;
pFldEdt.Type_2 = pSourceFeaCls.Fields.get_Field(j).Type;
pFldsEdt.AddField(pFld);
}
//創建空白shp文件
pFeaWks.CreateFeatureClass(strShpFile, pFlds, null, null, esriFeatureType.esriFTSimple, strShapeFieldName, "");
//打開Shapefile,獲取FeaCls
IWorkspace pTargetWks = pWksFac.OpenFromFile(strShppath, 0);
if (pTargetWks == null)
return;
IFeatureClass pTargetFeaCls = (pTargetWks as IFeatureWorkspace).OpenFeatureClass(strShpFile);

int ifeaCount = pSourceFeaCls.FeatureCount(null);
IFeatureCursor pFeaCur = pSourceFeaCls.Search(null, false);
IFeature pSourceFea = pFeaCur.NextFeature();
if (pSourceFea == null)
return;
bool blok = false;

IWorkspaceEdit pWksEdt = pTargetWks as IWorkspaceEdit;
pWksEdt.StartEditing(false);
pWksEdt.RedoEditOperation();
try
{
while (pSourceFea != null)
{
IFeature pTargetFea = pTargetFeaCls.CreateFeature();
if (pTargetFea != null)
{
pTargetFea.Shape = pSourceFea.Shape;
CopyAttribute(pSourceFea, pTargetFea);
pTargetFea.Store();
}
pSourceFea = pFeaCur.NextFeature();
}
blok = true;
}
catch (Exception exc)
{
serror = exc.Message;
}
finally
{
if (blok)
pWksEdt.StopEditOperation();
else
pWksEdt.AbortEditOperation();
pWksEdt.StopEditing(blok);
if (blok)
MessageBox.Show("導出成功,共計導出" + ifeaCount + "條記錄");
else
MessageBox.Show("導出失敗" + serror);
}
}
}

  private ISymbol GetSymbol(IColor pColor)
        {
            ISymbol pSymbol;
            ISimpleFillSymbol pSymbolFillSymbol = new SimpleFillSymbolClass();
            pSymbolFillSymbol.Color = pColor;
            pSymbolFillSymbol.Outline.Width = 0.4;
            pSymbol = pSymbolFillSymbol as ISymbol;
            return pSymbol;
        }
       
        private IRandomColorRamp GetColorRamp(int size)
        {
            IRandomColorRamp pRandomColorRamp = new RandomColorRampClass();
            pRandomColorRamp.StartHue = 10;
            pRandomColorRamp.EndHue = 300;
            pRandomColorRamp.MaxSaturation = 100;
            pRandomColorRamp.MinSaturation = 0;
            pRandomColorRamp.MaxValue = 100;
            pRandomColorRamp.MinValue = 0;
            pRandomColorRamp.Size = size;
            bool ok = true;
            pRandomColorRamp.CreateRamp(out ok);
            return pRandomColorRamp;
        }

        private void barButtonItem4_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            IMap pMap = this.axMapControl1.ActiveView.FocusMap;
            if (pMap.LayerCount == 0)
            {
                MessageBox.Show("地圖為空,請載入地圖!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            IGeoFeatureLayer pGeoLayer = this.axMapControl1.get_Layer(0) as IGeoFeatureLayer;
            ITable pTable = pGeoLayer.FeatureClass as ITable;
            ICursor pCursor;
            IQueryFilter pQueryFilter = new QueryFilter();
            pQueryFilter.AddField("OBJECTID");
            pCursor = pTable.Search(pQueryFilter, true);//獲取欄位
            IEnumerator pEnumreator;

            //獲取欄位中各要素屬性唯一值
            IDataStatistics pDataStatistics = new DataStatisticsClass();
            pDataStatistics.Field = "OBJECTID";//獲取統計欄位
            pDataStatistics.Cursor = pCursor;
            pEnumreator = pDataStatistics.UniqueValues;
            int fieldcount = pDataStatistics.UniqueValueCount;//唯一值個數,以此確定顏色帶範圍

            IUniqueValueRenderer pUniqueValueR = new UniqueValueRendererClass();
            pUniqueValueR.FieldCount = 1;//單值渲染
            pUniqueValueR.set_Field(0, "OBJECTID");//渲染欄位
            IEnumColors pEnumColor = GetColorRamp(fieldcount).Colors;
            pEnumColor.Reset();

            while (pEnumreator.MoveNext())
            {
                string value = pEnumreator.Current.ToString();
                if (value != null)
                {
                    IColor pColor = pEnumColor.Next();
                    ISymbol pSymbol = GetSymbol(pColor);
                    pUniqueValueR.AddValue(value, "OBJECTID", pSymbol);
                    //pUniqueValueR.set_Symbol(value, pSymbol);

                }

            }
            pGeoLayer.Renderer = pUniqueValueR as IFeatureRenderer;
            this.axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
            this.axTOCControl1.Update();
        }
    }

private void barButtonItem3_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{

}

private void axTOCControl1_OnMouseDown(object sender, ITOCControlEvents_OnMouseDownEvent e)
{

}

}
}


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • EventManager.py test.py ...
  • 後端開發:1、高級java軟體架構師實戰培訓視頻教程2、大型SpringMVC,Mybatis,Redis,Solr,Nginx,SSM分散式電商項目視頻教程3、Spark Streaming實時流處理項目實戰4、Java校招面試 Google面試官親授5、Java開發企業級許可權管理系統6、Java ...
  • 為瞭解決公司的項目在集群環境下查找日誌不便的問題,我在做過簡單調研後,選用Elastic公司的Elastic Stack產品作為我們的日誌收集,存儲,分析工具。 Elastic Stack是ELK(Elasticsearch,Logstash,Kibana)從5版本開始的新名稱,那麼的他們都能幹什麼 ...
  • 後端開發:1、高級java軟體架構師實戰培訓視頻教程2、大型SpringMVC,Mybatis,Redis,Solr,Nginx,SSM分散式電商項目視頻教程3、Spark Streaming實時流處理項目實戰4、Java校招面試 Google面試官親授5、Java開發企業級許可權管理系統6、Java ...
  • 元組與列表類似,不同之處在於元組的元素不能修改。 元組使用小括弧,列表使用方括弧。 元組創建很簡單,只需要在括弧中添加元素,並使用逗號隔開即可: 也可以省略括弧: 創建空元組: 元組中只包含一個元素時,需要在元素後面添加逗號“,”來消除歧義,否則括弧會被當作運算符使用(思考,會當做什麼運算符來用): ...
  • 一個爬取網易國內今日熱點新聞的小腳本。 需要用到requests、BeautifulSoup、Pandas(用於處理數據和導出Excel) 網易國內新聞url:http://news.163.com/domestic/ get url獲得response,requests對象,BeautifulSo ...
  • 本篇文章更適合具有一定開發經驗,一定功底,且對底層代碼有所研究的朋友!!! 本篇文章主要採用理論和代碼實例相結合方式來論述委托和事件,涉及到一些邊界技術,如軟體架構的OCP原則(開-閉原則), 軟體架構解耦,設計模式(Sender-Order)和事件驅動模型,有一定難度和深度,不適合初級者。 第一部 ...
  • 這篇文章其實是老外寫的,我只是把它翻譯一下,因為我用asp.net做上傳,有一個60+M的文件一直上傳不了,查了好多資料都是說把Web.config里的system.web>>httpRuntime節點下的maxRequestLength屬性改大一點,預設是4096kb,但是我照著修改之後並沒有起作 ...
一周排行
    -Advertisement-
    Play Games
  • .Net8.0 Blazor Hybird 桌面端 (WPF/Winform) 實測可以完整運行在 win7sp1/win10/win11. 如果用其他工具打包,還可以運行在mac/linux下, 傳送門BlazorHybrid 發佈為無依賴包方式 安裝 WebView2Runtime 1.57 M ...
  • 目錄前言PostgreSql安裝測試額外Nuget安裝Person.cs模擬運行Navicate連postgresql解決方案Garnet為什麼要選擇Garnet而不是RedisRedis不再開源Windows版的Redis是由微軟維護的Windows Redis版本老舊,後續可能不再更新Garne ...
  • C#TMS系統代碼-聯表報表學習 領導被裁了之後很快就有人上任了,幾乎是無縫銜接,很難讓我不想到這早就決定好了。我的職責沒有任何變化。感受下來這個系統封裝程度很高,我只要會調用方法就行。這個系統交付之後不會有太多問題,更多應該是做小需求,有大的開發任務應該也是第二期的事,嗯?怎麼感覺我變成運維了?而 ...
  • 我在隨筆《EAV模型(實體-屬性-值)的設計和低代碼的處理方案(1)》中介紹了一些基本的EAV模型設計知識和基於Winform場景下低代碼(或者說無代碼)的一些實現思路,在本篇隨筆中,我們來分析一下這種針對通用業務,且只需定義就能構建業務模塊存儲和界面的解決方案,其中的數據查詢處理的操作。 ...
  • 對某個遠程伺服器啟用和設置NTP服務(Windows系統) 打開註冊表 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpServer 將 Enabled 的值設置為 1,這將啟用NTP伺服器功 ...
  • title: Django信號與擴展:深入理解與實踐 date: 2024/5/15 22:40:52 updated: 2024/5/15 22:40:52 categories: 後端開發 tags: Django 信號 松耦合 觀察者 擴展 安全 性能 第一部分:Django信號基礎 Djan ...
  • 使用xadmin2遇到的問題&解決 環境配置: 使用的模塊版本: 關聯的包 Django 3.2.15 mysqlclient 2.2.4 xadmin 2.0.1 django-crispy-forms >= 1.6.0 django-import-export >= 0.5.1 django-r ...
  • 今天我打算整點兒不一樣的內容,通過之前學習的TransformerMap和LazyMap鏈,想搞點不一樣的,所以我關註了另外一條鏈DefaultedMap鏈,主要調用鏈為: 調用鏈詳細描述: ObjectInputStream.readObject() DefaultedMap.readObject ...
  • 後端應用級開發者該如何擁抱 AI GC?就是在這樣的一個大的浪潮下,我們的傳統的應用級開發者。我們該如何選擇職業或者是如何去快速轉型,跟上這樣的一個行業的一個浪潮? 0 AI金字塔模型 越往上它的整個難度就是職業機會也好,或者說是整個的這個運作也好,它的難度會越大,然後越往下機會就會越多,所以這是一 ...
  • @Autowired是Spring框架提供的註解,@Resource是Java EE 5規範提供的註解。 @Autowired預設按照類型自動裝配,而@Resource預設按照名稱自動裝配。 @Autowired支持@Qualifier註解來指定裝配哪一個具有相同類型的bean,而@Resourc... ...