【原创】利用ESRI自带的符号库进行符号化
生活随笔
收集整理的這篇文章主要介紹了
【原创】利用ESRI自带的符号库进行符号化
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
ArcGIS中自帶有豐富的符號(hào)庫(kù),在ArcGIS Server中使用符號(hào)庫(kù)的符號(hào)進(jìn)行符號(hào)化思路如下:
1.首先要知道符號(hào)庫(kù)中的符號(hào)分為哪些種類,才能在進(jìn)行符號(hào)化時(shí)對(duì)應(yīng)不同類型圖層進(jìn)行相應(yīng)的符號(hào)化;
2.其次要知道符號(hào)庫(kù)中有那些符號(hào),才能知道要用哪個(gè)符號(hào)進(jìn)行符號(hào)化;
3.知道了符號(hào)的名稱后,獲取符號(hào);
4.利用這個(gè)符號(hào)進(jìn)行符號(hào)化。
步驟1
Dim mapserver As AGSServer = New AGSServer()
mapserver.InitializeVar(_Map)
Dim soc As ESRI.ArcGIS.Server.ServerContext = mapserver.GetSOC()
'------------------------------------------------------
Dim _StyleGallery As IStyleGallery = Nothing
'------------------------------------------------------
If _StyleGallery Is Nothing Then
_StyleGallery = CType(soc.CreateObject ("esriDisplay.ServerStyleGallery"), ESRI.ArcGIS.Display.ServerStyleGallery) 'New ServerStyleGallery()
End If
'定義Style文件
'********************************************************
'IstyleGaleryStorage.DefaultStylePath將返回Style文件的缺省目錄。
'IstyleGalleryStorage.TargetFile屬性允許程序員新建一個(gè)Style文件作為添加、刪除和更新樣式條目的目標(biāo)文件。
'********************************************************
Dim _StyleStor As IStyleGalleryStorage = _StyleGallery 'IStyleGalleryStorage對(duì)象是用于管理IStyleGallery對(duì)象的
'定義Style文件的默認(rèn)路徑
Dim _ServerStylePath = _StyleStor.DefaultStylePath & "ESRI.ServerStyle" 'IStyleGalleryStorage:efaultStylePath下存儲(chǔ)的是默認(rèn)的Style文件夾路徑
_StyleStor.TargetFile = _ServerStylePath '此處指定目標(biāo)文件
Dim SGClass As IStyleGalleryClass = Nothing
Dim count As Integer = _StyleGallery.ClassCount
Dim styleclassNames(count) As String
For i As Integer = 0 To count - 1
SGClass = _StyleGallery.Class(i)
styleclassNames(i) = SGClass.Name
Next
這樣,所有StyleGalleryClass的名稱都獲取到了,具體有以下種類:
1 Reference Systems, 2 Maplex Labels, 3 Shadows, 4 Area Patches, 5 Line Patches, 6 Labels, 7 Representation Markers, 8 North Arrows, 9 Scale Bars, 10 Legend Items, 11 Scale Texts, 12 Color Ramps, 13 Borders,Backgrounds, 14 Colors, 15 Vectorization Settings, 16 Fill Symbols, 17 Line Symbols, 18 Marker Symbols, 19 Text Symbols, 20 Representation Rules, 21 Hatches
常用的有:Marker Symbols Line Symbols Fill Symbols Borders等
步驟2
1 Dim mapserver As AGSServer = New AGSServer()
2
3 mapserver.InitializeVar(_Map)
4
5 Dim soc As ESRI.ArcGIS.Server.ServerContext = mapserver.GetSOC()
6 '------------------------------------------------------
7 Dim _StyleGallery As IStyleGallery = Nothing
8 '------------------------------------------------------
9
10
11 If _StyleGallery Is Nothing Then
12
13 _StyleGallery = CType(soc.CreateObject("esriDisplay.ServerStyleGallery"), ESRI.ArcGIS.Display.ServerStyleGallery) 'New ServerStyleGallery()
14
15 End If
16
17 '定義Style文件
18 '********************************************************
19 'IstyleGaleryStorage.DefaultStylePath將返回Style文件的缺省目錄。
20 'IstyleGalleryStorage.TargetFile屬性允許程序員新建一個(gè)Style文件作為添加、刪除和更新樣式條目的目標(biāo)文件。
21 '********************************************************
22
23 Dim _StyleStor As IStyleGalleryStorage = _StyleGallery 'IStyleGalleryStorage對(duì)象是用于管理IStyleGallery對(duì)象的
24
25 '定義Style文件的默認(rèn)路徑
26 Dim _ServerStylePath = _StyleStor.DefaultStylePath & "ESRI.ServerStyle" 'IStyleGalleryStorage:efaultStylePath下存儲(chǔ)的是默認(rèn)的Style文件夾路徑
27 _StyleStor.TargetFile = _ServerStylePath '此處指定目標(biāo)文件
28
29 '將游標(biāo)重設(shè)在開(kāi)始位置
30 _EnumStyleGallery.Reset()
31
32 Try
33 '返回第一個(gè)IStyleGalleryItem
34 Dim _StyleGalleryItem As IStyleGalleryItem = _EnumStyleGallery.Next()
35
36 While Not _StyleGalleryItem Is Nothing
37 '獲取所有的符號(hào)名,可以綁定到DropDownList讓用戶選擇
38 _StyleGalleryItem.Name
39
40 Exit Function
41 End If
42
43 _StyleGalleryItem = _EnumStyleGallery.Next()
44
45 End While
46
47 Catch ex As Exception
48
49 Finally
50 '釋放COM對(duì)象
51 System.Runtime.InteropServices.Marshal.ReleaseComObject(_EnumStyleGallery)
52 End Try
步驟3
獲取ISymbol對(duì)象
在步驟2的過(guò)程中,獲取到了IStyleGalleryItem 對(duì)象
Dim symbol as ISymbol=_StyleGalleryItem.Item
步驟4
1 Dim mapserver As AGSServer = New AGSServer()
2
3 mapserver.InitializeVar(Map)
4
5 Dim soc As ESRI.ArcGIS.Server.ServerContext = mapserver.GetSOC()
6
7 Dim CatoMap As ESRI.ArcGIS.Carto.IMap = mapserver.GetMap()
8
9 Dim layers As ESRI.ArcGIS.Carto.IEnumLayer = CatoMap.Layers
10
11 layers.Reset()
12
13 Dim layer As ESRI.ArcGIS.Carto.ILayer = layers.Next()
14
15 While Not layer Is Nothing
16
17 If layer.Name = LayerName Then
18 Exit While
19 End If
20 layer = layers.Next()
21
22 End While
23
24 Dim geoFeatLayer As ESRI.ArcGIS.Carto.IGeoFeatureLayer = CType(layer, ESRI.ArcGIS.Carto.IGeoFeatureLayer)
25
26 Dim pSimRen As ESRI.ArcGIS.Carto.ISimpleRenderer = CType(soc.CreateObject("esriCarto.SimpleRenderer"), ESRI.ArcGIS.Carto.ISimpleRenderer)
27
28
29
30 Dim pFLayer As ESRI.ArcGIS.Carto.IFeatureLayer = layer
31 Dim pFClass As ESRI.ArcGIS.Geodatabase.IFeatureClass = pFLayer.FeatureClass
32
33 Select Case pFClass.ShapeType
34
35 Case esriGeometryType.esriGeometryPoint
36
37 symbol = LoadSymbol(_StyleClassNames(0), SymbolName)
38
39 Exit Select
40 Case esriGeometryType.esriGeometryPolyline
41 '線和面的與點(diǎn)的相同
42 Case esriGeometryType.esriGeometryPolygon
43
44
45 End Select
46 pSimRen.Symbol = symbol
47 geoFeatLayer.Renderer = pSimRen
48
49 Map.Refresh()
50
51 soc.ReleaseContext()
這里是以點(diǎn)為例,線面的類似
1 using System;
2 using System.Data;
3 using System.Configuration;
4 using System.Web;
5 using System.Web.Security;
6 using System.Web.UI;
7 using System.Web.UI.WebControls;
8 using System.Web.UI.WebControls.WebParts;
9 using System.Web.UI.HtmlControls;
10
11
12 using ESRI.ArcGIS.ADF.Web.UI.WebControls;
13 using ESRI.ArcGIS.Server.WebControls;
14
15 using ESRI.ArcGIS.ADF.Web;
16 using ESRI.ArcGIS.ADF;
17
18 using ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer;
19 using ESRI.ArcGIS.ADF.Web.DataSources.Graphics;
20 using ESRI.ArcGIS.ADF.Web.DataSources;
21
22 using ESRI.ArcGIS.Geometry;
23 using ESRI.ArcGIS.Server;
24 using ESRI.ArcGIS.Geodatabase;
25 using ESRI.ArcGIS.Carto;
26 using ESRI.ArcGIS.ADF.Connection;
27 using ESRI.ArcGIS.Display;
28
29
30
31 /// <summary>
32 /// AGSBase 的摘要說(shuō)明
33 /// </summary>
34 public class AGSServer
35 {
36 private IMapServer m_pMapServer;
37 private IMap m_pMap;
38 private IServerContext m_pSOC;
39 private ESRI.ArcGIS.ADF.ArcGISServer.MapDescription m_MapDes;
40 private IMapFunctionality m_pMapFunc;
41
42
43 public AGSServer(){
44 //構(gòu)造函數(shù)
45 m_pMapServer = null;
46 m_pMap = null;
47 m_pSOC = null;
48 m_MapDes = null;
49
50 }
51
52 public void InitializeVar(ESRI.ArcGIS.ADF.Web.UI.WebControls.Map mapCtrl)
53 {
54 m_pMapFunc = mapCtrl.GetFunctionality(0);
55 MapResourceLocal mapResLocal = m_pMapFunc.Resource as MapResourceLocal;
56
57 m_pSOC = mapResLocal.ServerContextInfo.ServerContext;
58 m_pMapServer = m_pSOC.ServerObject as IMapServer;
59 IMapServerObjects pMapServerObjs = m_pMapServer as IMapServerObjects;
60 m_pMap = pMapServerObjs.get_Map(m_pMapServer.DefaultMapName);
61
62 m_MapDes = mapResLocal.MapDescription;
63
64 return;
65 }
66
67 public IMapFunctionality GetMapFunctionality()
68 {
69 return m_pMapFunc;
70 }
71
72 public IMap GetMap()
73 {
74 return m_pMap;
75 }
76
77 public IMapServer GetMapServer()
78 {
79
80 return m_pMapServer;
81
82 }
83
84
85 public ESRI.ArcGIS.ADF.ArcGISServer.MapDescription GetMapDescription()
86 {
87
88 return m_MapDes;
89 }
90
91 public IServerContext GetSOC()
92 {
93
94 return m_pSOC;
95
96 }
97
98
99 }
總結(jié)
以上是生活随笔為你收集整理的【原创】利用ESRI自带的符号库进行符号化的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Apache Ivy
- 下一篇: 不要重复 DAO!