-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathMainForm.cs
3872 lines (2428 loc) · 129 KB
/
MainForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.GeoAnalyst;
using ESRI.ArcGIS.DataSourcesFile;
using ESRI.ArcGIS.DataSourcesRaster;
using ESRI.ArcGIS.NetworkAnalysis;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.NetworkAnalyst;
using ESRI.ArcGIS.Location;
using ESRI.ArcGIS.Geoprocessing;
using ESRI.ArcGIS.Geoprocessor;
using ESRI.ArcGIS.AnalysisTools;
using ESRI.ArcGIS.DataManagementTools;
using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS.Analyst3D;
using ESRI.ArcGIS.SpatialAnalyst;
using ESRI.ArcGIS.Output;
namespace EngineApplication
{
public partial class MainForm : Form
{
private ControlsSynchronizer pMapControlsSynchronizer = null;
ILayer pGlobalFeatureLayer;
int pClickedCount;
INASolver pNASolveClass;
//这个用来保存
IMultipoint pMulPoint;
//
IGraphicsContainer pGC;
IPointCollection pPointC;
IMap pNetMap;
public MainForm()
{
InitializeComponent();
pMulPoint = new MultipointClass();
pPointC = pMulPoint as IPointCollection;
pClickedCount = 0;
}
public void IWorkspace__get_WorkspaceName(string workspacePath, IWorkspace workspace)
{
//Creates a new workspace name for a personal geodatabase.
IWorkspaceName workspaceName = new WorkspaceNameClass();
workspaceName.WorkspaceFactoryProgID = "esriDataSourcesGDB.AccessWorkspaceFactory";
workspaceName.PathName = workspacePath;
//Or Get a workspace name from an existing workspace.
IDataset dataset = (IDataset)workspace; //Workspaces implement IDataset
workspaceName = (IWorkspaceName)dataset.FullName;
}
public string OpenMxd()
{
string MxdPath = "";
OpenFileDialog OpenMXD = new OpenFileDialog();
OpenMXD.Title = "打开地图";
OpenMXD.InitialDirectory = "E:";
OpenMXD.Filter = "Map Documents (*.mxd)|*.mxd";
if (OpenMXD.ShowDialog() == DialogResult.OK)
{
MxdPath = OpenMXD.FileName;
}
return MxdPath;
}
/// <summary>
/// 返回一个长度为2的一维数组,string[0]表示Shape所在的文件夹,string[1]表示Shape文件名称
/// </summary>
/// <returns></returns>
public string[] OpenShapeFile()
{
string[] ShapeFile = new string[2];
OpenFileDialog OpenShpFile = new OpenFileDialog();
OpenShpFile.Title = "打开Shape文件";
OpenShpFile.InitialDirectory = "E:";
OpenShpFile.Filter = "Shape文件(*.shp)|*.shp";
if (OpenShpFile.ShowDialog() == DialogResult.OK)
{
string ShapPath = OpenShpFile.FileName;
//利用"\\"将文件路径分成两部分
int Position = ShapPath.LastIndexOf("\\");
string FilePath = ShapPath.Substring(0,Position);
string ShpName = ShapPath.Substring(Position+1);
ShapeFile[0] = FilePath;
ShapeFile[1] = ShpName;
}
return ShapeFile;
}
/// <summary>
///
/// </summary>
/// <param name="pMap"></param>
/// <param name="LayerName"></param>
/// <returns></returns>
private ILayer GetLayer(IMap pMap, string LayerName)
{
IEnumLayer pEnunLayer;
pEnunLayer = pMap.get_Layers(null, false);
pEnunLayer.Reset();
ILayer pRetureLayer;
pRetureLayer = pEnunLayer.Next();
while (pRetureLayer != null)
{
if (pRetureLayer.Name == LayerName)
{
break;
}
pRetureLayer = pEnunLayer.Next();
}
return pRetureLayer;
}
private void axTOCControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.ITOCControlEvents_OnMouseDownEvent e)
{
if (axMapControl1.LayerCount > 0)
{
esriTOCControlItem pItem = new esriTOCControlItem();
pGlobalFeatureLayer = new FeatureLayerClass();
IBasicMap pBasicMap = new MapClass();
object pOther = new object();
object pIndex = new object();
axTOCControl1.HitTest(e.x, e.y, ref pItem, ref pBasicMap, ref pGlobalFeatureLayer, ref pOther, ref pIndex);
}
if (e.button == 2)
{
context.Show(axTOCControl1, e.x, e.y);
}
}
private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (axMapControl1.LayerCount > 0)
{
if (pGlobalFeatureLayer != null)
{
axMapControl1.Map.DeleteLayer(pGlobalFeatureLayer);
}
}
}
private void 打开属性表ToolStripMenuItem_Click(object sender, EventArgs e)
{
FormTable Ft = new FormTable(pGlobalFeatureLayer as IFeatureLayer);
Ft.Show();
}
public IWorkspace Get_Workspace(string _pWorkspacePath)
{
IWorkspaceName pWorkspaceName = new WorkspaceNameClass();
pWorkspaceName.WorkspaceFactoryProgID = "esriDataSourcesGDB.AccessWorkspaceFactory";
pWorkspaceName.PathName = _pWorkspacePath;
IName pName = pWorkspaceName as IName;
IWorkspace pWorkspace = pName.Open() as IWorkspace;
return pWorkspace;
}
/// <summary>
///打开要素类,以下几个函数为公用,暂时放在不放在一个公用类里面
/// </summary>
/// <returns></returns>
/// <summary>
/// 获取要素类
/// </summary>
/// <param name="p_GDBFileName"></param>
/// <param name="p_FeatureClassName"></param>
/// <returns></returns>
private IFeatureClass OpenFeatureClass(string p_GDBFileName, string p_FeatureClassName)
{
IWorkspaceFactory li_WorkspaceFactory;
IWorkspace li_Workspace;
IFeatureWorkspace li_FeatureWorkspace;
IFeatureClass li_FeatureClass;
li_WorkspaceFactory = new AccessWorkspaceFactoryClass();
li_Workspace = li_WorkspaceFactory.OpenFromFile(p_GDBFileName, 0);
li_FeatureWorkspace = li_Workspace as IFeatureWorkspace;
li_FeatureClass = li_FeatureWorkspace.OpenFeatureClass(p_FeatureClassName);
return li_FeatureClass;
}
public string WsPath()
{
string WsFileName="";
OpenFileDialog OpenFile = new OpenFileDialog();
OpenFile.Filter = "个人数据库(MDB)|*.mdb";
DialogResult DialogR = OpenFile.ShowDialog();
if (DialogR == DialogResult.Cancel)
{
}
else
{
WsFileName = OpenFile.FileName;
}
return WsFileName;
}
IRgbColor GetRGB(int R,int G,int B)
{
IRgbColor pColor = new RgbColorClass();
pColor.Red = R;
pColor.Green = G;
pColor.Blue = B;
return pColor;
}
IRasterDataset OpenGDBRasterDataset(IRasterWorkspaceEx pRasterWorkspaceEx, string pDatasetName)
{
//打开存放在数据库中的栅格数据
return pRasterWorkspaceEx.OpenRasterDataset(pDatasetName);
}
IRasterDataset GetRasterCatalogItem(IRasterCatalog pCatalog, int pObjectID)
{
//栅格目录继承了IFeatureClass
IFeatureClass pFeatureClass = (IFeatureClass)pCatalog;
IRasterCatalogItem pRasterCatalogItem = (IRasterCatalogItem)pFeatureClass.GetFeature(pObjectID);
return pRasterCatalogItem.RasterDataset;
}
IMosaicDataset GetMosaicDataset(string pFGDBPath,string pMDame)
{
IWorkspaceFactory pWorkspaceFactory = new FileGDBWorkspaceFactoryClass();
IWorkspace pFgdbWorkspace = pWorkspaceFactory.OpenFromFile(pFGDBPath, 0);
IMosaicWorkspaceExtensionHelper pMosaicExentionHelper = new
MosaicWorkspaceExtensionHelperClass();
IMosaicWorkspaceExtension pMosaicExtention = pMosaicExentionHelper.FindExtension(pFgdbWorkspace);
return pMosaicExtention.OpenMosaicDataset(pMDame);
}
/// <summary>
/// 创建镶嵌数据集
/// </summary>
/// <param name="pFGDBPath"></param>
/// <param name="pMDame"></param>
/// <param name="pSrs"></param>
/// <returns></returns>
IMosaicDataset CreateMosaicDataset(string pFGDBPath, string pMDame, ISpatialReference pSrs )
{
IWorkspaceFactory pWorkspaceFactory = new FileGDBWorkspaceFactory();
IWorkspace pFgdbWorkspace = pWorkspaceFactory.OpenFromFile(pFGDBPath, 0);
ICreateMosaicDatasetParameters pCreationPars = new CreateMosaicDatasetParametersClass();
pCreationPars.BandCount = 3;
pCreationPars.PixelType = rstPixelType.PT_UCHAR;
IMosaicWorkspaceExtensionHelper pMosaicExentionHelper = new MosaicWorkspaceExtensionHelperClass();
IMosaicWorkspaceExtension pMosaicExtention = pMosaicExentionHelper.FindExtension(pFgdbWorkspace);
return pMosaicExtention.CreateMosaicDataset(pMDame, pSrs, pCreationPars, "");
}
public IRasterDataset CreateRasterDataset(string pRasterFolderPath, string pFileName,string pRasterType,ISpatialReference pSpr )
{
IRasterWorkspace2 pRasterWs = GetRasterWorkspace(pRasterFolderPath) as IRasterWorkspace2;
IPoint pPoint = new PointClass();
pPoint.PutCoords(15.0, 15.0);
int pWidth = 300;
int pHeight = 300;
double xCell = 30;
double yCell = 30;
int NumBand = 1;
IRasterDataset pRasterDataset = pRasterWs.CreateRasterDataset(pFileName, pRasterType,
pPoint, pWidth, pHeight, xCell, yCell, NumBand, rstPixelType.PT_UCHAR, pSpr,
true);
IRasterBandCollection pRasterBands = (IRasterBandCollection)pRasterDataset;
IRasterBand pRasterBand = pRasterBands.Item(0);
IRasterProps pRasterProps = (IRasterProps)pRasterBand;
pRasterProps.NoDataValue = 255;
IRaster pRaster = pRasterDataset.CreateDefaultRaster();
IPnt pPnt = new PntClass();
pPnt.SetCoords(30, 30);
IRaster2 pRaster2 = pRaster as IRaster2;
IRasterEdit pRasterEdit = (IRasterEdit)pRaster2;
IRasterCursor pRasterCursor = pRaster2.CreateCursorEx(pPnt);
do
{
IPixelBlock3 pPixelblock = pRasterCursor.PixelBlock as IPixelBlock3;
System.Array pixels = (System.Array)pPixelblock.get_PixelData(0);
for (int i = 0; i < pPixelblock.Width; i++)
for (int j = 0; j < pPixelblock.Height; j++)
if (i == j)
pixels.SetValue(Convert.ToByte(255), i, j);
else
pixels.SetValue(Convert.ToByte((i * j + 30) / 255), i, j);
pPixelblock.set_PixelData(0, (System.Array)pixels);
IPnt pUpperLeft = pRasterCursor.TopLeft;
pRasterEdit.Write(pUpperLeft, (IPixelBlock)pPixelblock);
} while (pRasterCursor.Next());
System.Runtime.InteropServices.Marshal.ReleaseComObject(pRasterEdit);
return pRasterDataset;
}
void SearchHightlight(IMap _pMap,IFeatureLayer _pFeatureLayer, IQueryFilter _pQuery, bool _Bool)
{
IFeatureCursor pFtCursor = _pFeatureLayer.Search(_pQuery, _Bool);
IFeature pFt = pFtCursor.NextFeature();
while (pFt != null)
{
_pMap.SelectFeature(_pFeatureLayer as ILayer, pFt);
pFt = pFtCursor.NextFeature();
}
}
void Search(IFeatureClass _pFeatureClass,bool _Bool)
{
IFeature pFt1, pFt2;
IFeatureCursor pFtCursor;
if (_Bool == false)
{
pFtCursor = _pFeatureClass.Search(null, _Bool);
pFt1 = pFtCursor.NextFeature();
while (pFt1 != null)
{
pFt2 = pFtCursor.NextFeature();
if (pFt1 == pFt2)
{
MessageBox.Show("Recycling 参数是 false");
}
pFt1 = pFtCursor.NextFeature();
}
}
else
{
pFtCursor = _pFeatureClass.Search(null, _Bool);
pFt1 = pFtCursor.NextFeature();
while (pFt1 != null)
{
pFt2 = pFtCursor.NextFeature();
if (pFt1 == pFt2)
{
MessageBox.Show("Recycling 参数是true");
}
pFt1 = pFtCursor.NextFeature();
}
}
}
private IPolygon FlatBuffer(IPolyline _pLine, double _pBufferDis)
{
object o = System.Type.Missing;
//分别对输入的线平移两次(正方向和负方向)
IConstructCurve pConCurve = new PolylineClass();
pConCurve.ConstructOffset(_pLine, _pBufferDis, ref o, ref o);
IPointCollection pCol = pConCurve as IPointCollection;
IConstructCurve pCurve = new PolylineClass();
pCurve.ConstructOffset(_pLine, -1 * _pBufferDis, ref o, ref o);
//把第二次平移的线的所有节点翻转
IPolyline addline = pCurve as IPolyline;
addline.ReverseOrientation();
//把第二条的所有节点放到第一条线的IPointCollection里面
IPointCollection pCol2 = addline as IPointCollection;
pCol.AddPointCollection(pCol2);
//用面去初始化一个IPointCollection
IPointCollection myPCol = new PolygonClass();
myPCol.AddPointCollection(pCol);
//把IPointCollection转换为面
IPolygon pPolygon = myPCol as IPolygon;
//简化节点次序
pPolygon.SimplifyPreserveFromTo();
return pPolygon;
}
/// <summary>
/// 通过线创建面
/// </summary>
/// <param name="pPolyline">线</param>
/// <returns>面</returns>
IPolygon ConstructPolygonFromPolyline(IPolyline _pPolyline)
{
IGeometryCollection pPolygonGeoCol = new PolygonClass();
if ((_pPolyline != null) && (!_pPolyline.IsEmpty))
{
IGeometryCollection pPolylineGeoCol = _pPolyline as IGeometryCollection;
ISegmentCollection pSegCol = new RingClass();
ISegment pSegment = null;
object missing = Type.Missing;
for (int i = 0; i < pPolylineGeoCol.GeometryCount; i++)
{
ISegmentCollection pPolylineSegCol = pPolylineGeoCol.get_Geometry(i) as ISegmentCollection;
for (int j = 0; j < pPolylineSegCol.SegmentCount; j++)
{
pSegment = pPolylineSegCol.get_Segment(j);
pSegCol.AddSegment(pSegment, ref missing, ref missing);
}
pPolygonGeoCol.AddGeometry(pSegCol as IGeometry, ref missing, ref missing);
}
}
return pPolygonGeoCol as IPolygon;
}
void GPIntsect()
{
ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();
ESRI.ArcGIS.AnalysisTools.Intersect pIntsect = new ESRI.ArcGIS.AnalysisTools.Intersect();
gp.OverwriteOutput = true;
//设置工作空间 // IGpEnumList gpEnumEnv = gp.ListEnvironments("*");
gp.SetEnvironmentValue("workspace", @".\data\分析用的空间数据");
pIntsect.in_features = ".\data分析用的空间数据\\县界面.shp;.\data分析用的空间数据\\地级市.shp";
pIntsect.out_feature_class = "Result.shp";
pIntsect.cluster_tolerance = 0.5;
pIntsect.join_attributes = "All";
pIntsect.output_type = "INPUT";
gp.Execute(pIntsect, null);
}
private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
{
if(pFlag==1)//缓冲区空间查询
{
IActiveView pActView = axMapControl1.Map as IActiveView;
IPoint pPoint = pActView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);
ITopologicalOperator pTopo = pPoint as ITopologicalOperator;
IGeometry pGeo = pTopo.Buffer(500);
ESRI.ArcGIS.Display.IRgbColor rgbColor = new ESRI.ArcGIS.Display.RgbColorClass();
rgbColor.Red = 255;
ESRI.ArcGIS.Display.IColor color = rgbColor; // Implicit Cast
ESRI.ArcGIS.Display.ISimpleFillSymbol simpleFillSymbol = new ESRI.ArcGIS.Display.SimpleFillSymbolClass();
simpleFillSymbol.Color = color;
ESRI.ArcGIS.Display.ISymbol symbol = simpleFillSymbol as ESRI.ArcGIS.Display.ISymbol;
pActView.ScreenDisplay.SetSymbol(symbol);
pActView.ScreenDisplay.DrawPolygon(pGeo);
axMapControl1.Map.SelectByShape(pGeo, null, false);
axMapControl1.FlashShape(pGeo, 1000, 2, symbol);
axMapControl1.ActiveView.Refresh();
}
if (pFlag == 2)
{
pNetMap = axMapControl1.Map;
pGC = pNetMap as IGraphicsContainer;
IActiveView pActView = pNetMap as IActiveView;
IPoint pPoint = pActView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);
object o = Type.Missing;
object o1 = Type.Missing;
pPointC.AddPoint(pPoint, ref o, ref o1);
IElement Element;
ITextElement Textelement = new TextElementClass();
Element = Textelement as IElement;
pClickedCount++;
Textelement.Text = pClickedCount.ToString();
Element.Geometry = pActView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);
pGC.AddElement(Element, 0);
pActView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
IFeatureClass pFeatureClass = pNaContext.NAClasses.get_ItemByName("Stops") as IFeatureClass;
NASolve(pNaContext, pFeatureClass, pPointC, 5000);
IGPMessages gpMessages = new GPMessagesClass();
bool pBool = pNASolveClass.Solve(pNaContext, gpMessages, null);
}
if (pFlag == 3)//有向网络
{
IWorkspace pWs = GetMDBWorkspace(@".\data\Geometric.mdb");
IFeatureWorkspace pFtWs = pWs as IFeatureWorkspace;
IFeatureDataset pFtDataset = pFtWs.OpenFeatureDataset("work");
double s = 0;
IPolyline pPolyline = new PolylineClass();
SolvePath(axMapControl1.Map, GetGeometricNetwork(pFtDataset, "TestGeometric"), "Weight", pPointC, 1000, ref pPolyline, ref s);
IRgbColor pColor = new RgbColorClass();
pColor.Red = 255;
IElement pElement = new LineElementClass();
ILineSymbol linesymbol = new SimpleLineSymbolClass();
linesymbol.Color = pColor as IColor;
linesymbol.Width = 100;
pElement.Geometry = pPolyline;
pGC.AddElement(pElement, 2);
axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
if (pFlag == 4)
{
if(axMapControl1.Map.get_Layer(0)!=null)
{
IRasterLayer pRasterLayer = axMapControl1.Map.get_Layer(0) as IRasterLayer;
IRasterSurface pRasterSurface = new RasterSurfaceClass();
pRasterSurface.PutRaster(pRasterLayer.Raster, 0);
ISurface pSurface = pRasterSurface as ISurface;
IPolyline pPolyline = axMapControl1.TrackLine() as IPolyline;
IPoint pPoint =null ;
IPolyline pVPolyline =null;
IPolyline pInPolyline= null;
object pRef=0.13;
bool pBool =true;
double pZ1 = pSurface.GetElevation(pPolyline.FromPoint);
double pZ2= pSurface.GetElevation(pPolyline.ToPoint);
IPoint pPoint1 = new PointClass();
pPoint1.Z = pZ1;
pPoint1.X = pPolyline.FromPoint.X;
pPoint1.Y = pPolyline.FromPoint.Y;
IPoint pPoint2 = new PointClass();
pPoint2.Z = pZ2;
pPoint2.X = pPolyline.ToPoint.X;
pPoint2.Y = pPolyline.ToPoint.Y;
pSurface.GetLineOfSight(pPoint1, pPoint2, out pPoint, out pVPolyline,
out pInPolyline, out pBool, false, false, ref pRef);//大爷的,设置为true居然通不过bApplyCurvature和bApplyRefraction两项设置为true,surface必须定义成具有ZUnits的投影坐标
//This member should not be used in .NET. As a substitute, .NET developers must use IGeoDatabaseBridge2.GetLineOfSight.
//楼主,用IGeoDatabaseBridge2.GetLineOfSight.方法试试
if (pVPolyline != null)
{
IElement pLineElementV = new LineElementClass();
pLineElementV.Geometry = pVPolyline;
ILineSymbol pLinesymbolV = new SimpleLineSymbolClass();
pLinesymbolV.Width = 2;
IRgbColor pColorV = new RgbColorClass();
pColorV.Green =255;
pLinesymbolV.Color = pColorV;
ILineElement pLineV = pLineElementV as ILineElement;
pLineV.Symbol = pLinesymbolV;
axMapControl1.ActiveView.GraphicsContainer.AddElement(pLineElementV, 0);
}
if (pInPolyline != null)
{
IElement pLineElementIn = new LineElementClass();
pLineElementIn.Geometry = pInPolyline;
ILineSymbol pLinesymbolIn = new SimpleLineSymbolClass();
pLinesymbolIn.Width = 2;
IRgbColor pColorIn = new RgbColorClass();
pColorIn.Red = 255;
pLinesymbolIn.Color = pColorIn;
ILineElement pLineIn = pLineElementIn as ILineElement;
pLineIn.Symbol = pLinesymbolIn;
axMapControl1.ActiveView.GraphicsContainer.AddElement(pLineElementIn, 1);
}
axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
axMapControl1.TrackCancel.Cancel();
}
}
}
public ITinLayer GetTINLayer(string pPath)//打开TIN文件
{
ITinWorkspace pTinWorkspace;
IWorkspace pWS;
IWorkspaceFactory pWSFact = new TinWorkspaceFactoryClass();
ITinLayer pTinLayer = new TinLayerClass();
string pathToWorkspace = System.IO.Path.GetDirectoryName(pPath);
string tinName = System.IO.Path.GetFileName(pPath);
ITin pTin;
pWS = pWSFact.OpenFromFile(pathToWorkspace, 0);
pTinWorkspace = pWS as ITinWorkspace;
if (pTinWorkspace.get_IsTin(tinName))
{
pTin = pTinWorkspace.OpenTin(tinName);
pTinLayer.Dataset = pTin;
pTinLayer.ClearRenderers();
return pTinLayer;
}
else
{
MessageBox.Show("该目录不包含Tin文件");
return null;
}
}
/// <summary>
/// 创建Tin
/// </summary>
/// <param name="pFeatureClass"></param>
/// <param name="pField"></param>
/// <param name="pPath"></param>
/// <returns></returns>
public ITin CreateTin(IFeatureClass pFeatureClass, IField pField,string pPath)
{
IGeoDataset pGeoDataset = pFeatureClass as IGeoDataset;
ITinEdit pTinEdit = new TinClass();
pTinEdit.InitNew(pGeoDataset.Extent);
object pObj = Type.Missing;
pTinEdit.AddFromFeatureClass(pFeatureClass, null, pField,null, esriTinSurfaceType.esriTinMassPoint, ref pObj);
pTinEdit.SaveAs(pPath, ref pObj);
pTinEdit.Refresh();
return pTinEdit as ITin;
}
public IRaster DensityAnalyst(IFeatureClass pFeatureClass,string pFieldName, double pCellSize, double pRadius)
{
//辅助对象,设置密度分析时候的参数
IFeatureClassDescriptor pFDescr = new FeatureClassDescriptorClass();
pFDescr.Create(pFeatureClass, null, pFieldName);
IDensityOp pDensityOp = new RasterDensityOpClass();
//设置环境
IRasterAnalysisEnvironment pEnv = pDensityOp as IRasterAnalysisEnvironment;
object object_cellSize = (System.Object)pCellSize;
pEnv.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref object_cellSize);
System.Double double_radio_dis = pRadius;
object object_radio_dis = (System.Object)double_radio_dis;
object Missing = Type.Missing;
//核函数密度制图方法生成栅格数据
IRaster pRaster = pDensityOp.KernelDensity(pFDescr as IGeoDataset, ref object_radio_dis, ref Missing) as IRaster;
return pRaster;
}
/// <summary>
/// 创建泰森多边形
/// </summary>
/// <param name="pFeatureClass"></param>
/// <param name="pTin"></param>
void CreateVr(IFeatureClass pFeatureClass ,ITin pTin)
{
ITinNodeCollection pTinColl = pTin as ITinNodeCollection;
pTinColl.ConvertToVoronoiRegions(pFeatureClass, null, null, "", "");
}
public ESRI.ArcGIS.Geodatabase.IFeatureCursor GetAllFeaturesFromPointSearchInGeoFeatureLayer(Double pSearchTolerance, IPoint pPoint, IFeatureClass pFeatureClass)
{
if (pSearchTolerance < 0 || pPoint == null || pFeatureClass == null)
{
return null;
}
ESRI.ArcGIS.Geometry.IEnvelope pEnvelope = pPoint.Envelope;
pEnvelope.Expand(pSearchTolerance, pSearchTolerance, false);
//ITopologicalOperator pTopo = pPoint as ITopologicalOperator;
//IGeometry pGeo = pTopo.Buffer(pSearchTolerance);
System.String pShapeFieldName = pFeatureClass.ShapeFieldName;
ESRI.ArcGIS.Geodatabase.ISpatialFilter pSpatialFilter = new ESRI.ArcGIS.Geodatabase.SpatialFilterClass();
pSpatialFilter.Geometry = pEnvelope;
pSpatialFilter.SpatialRel = ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum.esriSpatialRelEnvelopeIntersects;
pSpatialFilter.GeometryField = pShapeFieldName;
ESRI.ArcGIS.Geodatabase.IFeatureCursor pFeatureCursor = pFeatureClass.Search(pSpatialFilter, false);
return pFeatureCursor;
}
/// <summary>
/// 要插值的要素类,插值的字段名,阈值,栅格大小,指数
/// </summary>
/// <param name="_pFeatureClass"></param>
/// <param name="_pFieldName"></param>
/// <param name="_pDistance"></param>
/// <param name="_pCell"></param>
/// <param name="_pPower"></param>
/// <returns></returns>
public IGeoDataset IDW(IFeatureClass _pFeatureClass, string _pFieldName, double _pDistance, double _pCell, int _pPower)
{
IGeoDataset Geo = _pFeatureClass as IGeoDataset;
object pExtent = Geo.Extent;