【原创】利用ESRI自带的符号库进行符号化
ArcGIS中自带有丰富的符号库,在ArcGIS Server中使用符号库的符号进行符号化思路如下:
1.首先要知道符号库中的符号分为哪些种类,才能在进行符号化时对应不同类型图层进行相应的符号化;
2.其次要知道符号库中有那些符号,才能知道要用哪个符号进行符号化;
3.知道了符号的名称后,获取符号;
4.利用这个符号进行符号化。
步骤1
1.首先要知道符号库中的符号分为哪些种类,才能在进行符号化时对应不同类型图层进行相应的符号化;
2.其次要知道符号库中有那些符号,才能知道要用哪个符号进行符号化;
3.知道了符号的名称后,获取符号;
4.利用这个符号进行符号化。
步骤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属性允许程序员新建一个Style文件作为添加、删除和更新样式条目的目标文件。 '******************************************************** Dim _StyleStor As IStyleGalleryStorage = _StyleGallery 'IStyleGalleryStorage对象是用于管理IStyleGallery对象的 '定义Style文件的默认路径 Dim _ServerStylePath = _StyleStor.DefaultStylePath & "ESRI.ServerStyle" 'IStyleGalleryStorage:efaultStylePath下存储的是默认的Style文件夹路径 _StyleStor.TargetFile = _ServerStylePath '此处指定目标文件 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属性允许程序员新建一个Style文件作为添加、删除和更新样式条目的目标文件。 21 '******************************************************** 22 23 Dim _StyleStor As IStyleGalleryStorage = _StyleGallery 'IStyleGalleryStorage对象是用于管理IStyleGallery对象的 24 25 '定义Style文件的默认路径 26 Dim _ServerStylePath = _StyleStor.DefaultStylePath & "ESRI.ServerStyle" 'IStyleGalleryStorage:efaultStylePath下存储的是默认的Style文件夹路径 27 _StyleStor.TargetFile = _ServerStylePath '此处指定目标文件 28 29 '将游标重设在开始位置 30 _EnumStyleGallery.Reset() 31 32 Try 33 '返回第一个IStyleGalleryItem 34 Dim _StyleGalleryItem As IStyleGalleryItem = _EnumStyleGallery.Next() 35 36 While Not _StyleGalleryItem Is Nothing 37 '获取所有的符号名,可以绑定到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对象 51 System.Runtime.InteropServices.Marshal.ReleaseComObject(_EnumStyleGallery) 52 End Try
步骤3
获取ISymbol对象
在步骤2的过程中,获取到了IStyleGalleryItem 对象
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 '线和面的与点的相同 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()
这里是以点为例,线面的类似
-
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 的摘要说明 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 //构造函数 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 }