ArcEngine服务数据加载
public static class MapServer
{
public static ILayer ReadWmtsServer(string url, string layerName)
{
IPropertySet propertySet = new PropertySetClass();
propertySet.SetProperty("url", url);
if (layerName != "")
propertySet.SetProperty("layerName", layerName);
IWMTSConnectionFactory wmtsConnectionfactory = new WMTSConnectionFactory();
var con = wmtsConnectionfactory.Open(propertySet, 0, null);
IWMTSLayer wmtsLayer = new WMTSLayer();
var n = con.FullName;
wmtsLayer.Connect(n);
var layer = wmtsLayer as ILayer;
layer.Cached = true;
layer.Name = layerName;
return layer;
}
public static ILayer ReadWmsServer(string url, string layerName)
{
IPropertySet propertyset = new PropertySetClass();
propertyset.SetProperty("url", url);
IWMSConnectionFactory pWmsFac = new WMSConnectionFactory();
var pWmsC = pWmsFac.Open(propertyset, 0, null);
var pWmsConnectionName = pWmsC.FullName as IWMSConnectionName;
ILayerFactory pLayerFactory = new EngineWMSMapLayerFactoryClass();
ILayer target = null;
if (pLayerFactory.get_CanCreate(pWmsConnectionName))
{
var pEnumLayer = pLayerFactory.Create(pWmsConnectionName);
pEnumLayer.Reset();
var pLayer = pEnumLayer.Next();
while (pLayer != null)
{
if (pLayer is IWMSMapLayer && pLayer.Name == layerName)
{
target = pLayer;
break;
}
pLayer = pEnumLayer.Next();
}
Marshal.ReleaseComObject(pEnumLayer);
}
return target;
}
public static ILayer ReadWcsServer(string url, string layerName)
{
IPropertySet propertyset = new PropertySetClass();
propertyset.SetProperty("url", url);
IWCSConnectionFactory wcsConnectionFactory = new WCSConnectionFactory();
var wcsConnection = wcsConnectionFactory.Open(propertyset, 0, null);
var wcsConnectionName = wcsConnection.FullName as IWCSConnectionName;
WCSLayerFactory wCSLayerFactory = new WCSLayerFactoryClass();
ILayer target = null;
if (wCSLayerFactory.get_CanCreate(wcsConnectionName))
{
var pEnumLayer = wCSLayerFactory.Create(wcsConnectionName);
pEnumLayer.Reset();
var layer = pEnumLayer.Next();
while (layer != null)
{
if (layer is IWCSLayer && layer.Name == layerName)
{
target= layer;
break;
}
layer = pEnumLayer.Next();
}
}
return target;
}
public static ILayer ReadMapServer(string hostOrUrl, string serviceName, bool isLAN, string layerName)
{
ILayer target = null;
IMapServer mapServer;
var pServerObjectName = GetMapServer(hostOrUrl, serviceName, isLAN);
var pName = (IName)pServerObjectName;
var pServerObject = (IAGSServerObject)pName.Open();
var pMapServer = (IMapServer)pServerObject;
mapServer = pMapServer;
var pMapServerLayer = new MapServerLayer() as IMapServerLayer;
pMapServerLayer.ServerConnect(pServerObjectName, pMapServer.DefaultMapName);
target = pMapServerLayer as ILayer;
target.Cached = true;
if (!string.IsNullOrEmpty(layerName))
target.Name = layerName;
return target;
}
public static ILayer ReadImageServer(string url, string layerName)
{
IImageServerLayer imageServerLayer = new ImageServerLayerClass();
imageServerLayer.Initialize(url);
var raster = imageServerLayer.Raster;
IRasterLayer rasterLayer = new RasterLayerClass();
rasterLayer.CreateFromRaster(raster);
rasterLayer.Name = layerName;
return rasterLayer;
}
private static IAGSServerObjectName GetMapServer(string pHostOrUrl, string pServiceName, bool pIsLAN)
{
try
{
IPropertySet pPropertySet = new PropertySet();
if (pIsLAN)
pPropertySet.SetProperty("machine", pHostOrUrl);
else
pPropertySet.SetProperty("url", pHostOrUrl);
IAGSServerConnectionFactory pFactory = new AGSServerConnectionFactory();
var pConnection = pFactory.Open(pPropertySet, 0);
var pServerObjectNames = pConnection.ServerObjectNames;
pServerObjectNames.Reset();
var ServerObjectName = pServerObjectNames.Next();
while (ServerObjectName != null)
{
if (ServerObjectName.Name.ToLower() == pServiceName.ToLower() &&
ServerObjectName.Type == "MapServer")
break;
ServerObjectName = pServerObjectNames.Next();
}
return ServerObjectName;
}
catch
{
return null;
}
}
}
|