http://forums.arcgis.com/threads/11481-how-to-get-geometry-type-of-layer-using-IMapServer3-and-IMapLayerInfo-(C-)

I need to create a REST extension that will return JSON looking like that:

"layers" : [ { "MaxScale" : 0,
"MinScale" : 0,
"defaultVisibility" : true,
"geometryType" : null,
"id" : 0,
"name" : "Name",
"parentLayerId" : -1,
"subLayerIds" : [ 1, 2 ]
},
{ "MaxScale" : 0,
"MinScale" : 0,
"defaultVisibility" : false,
"geometryType" : "esriGeometryPoint",
"id" : 1,
"name" : "NAME Offices",
"parentLayerId" : 0,
"subLayerIds" : null
}
... As I'm able to get almost all informations that I want, I have only issue getting geometryType anddefaultVisibility. I was trying to find a way by looking into DOCS, I'm sure If I will be able to get IGeometry interface I should be able to get geometry type, but how to get IGeometry interface starting from IMapServer3? Or there is other way to do it? Here is a code that is creating list of layers in JSON format:
private XxxLayerInfo[] GetLayerInfos()
{
IMapServer3 mapServer = _serverObjectHelper.ServerObject as IMapServer3;
if (mapServer == null)
throw new Exception("Unable to access XXX map server."); IMapServerInfo msInfo = mapServer.GetServerInfo(mapServer.DefaultMapName);
IMapLayerInfos layerInfos = msInfo.MapLayerInfos;
int length = layerInfos.Count; XxxLayerInfo[] xxxLayerInfos = new XxxLayerInfo[c][/c]; for(int i = 0; i < length; i++)
{
IMapLayerInfo layerInfo = layerInfos.get_Element(i);
xxxLayerInfos[i] = XxxLayerInfo.CreateXxxLayerInfo(layerInfo);
} return xxxLayerInfos;
} public static XxxLayerInfo CreateXxxLayerInfo(IMapLayerInfo mapLayerInfo)
{
var layer = new XxxLayerInfo();
layer.Id = mapLayerInfo.ID;
layer.Name = mapLayerInfo.Name;
layer.GeometryType = null; //mapLayerInfo.GeometryType - HOW TO GET this?;
layer.DefaultVisibility = false; //mapLayerInfo.DefaultVisibility - HOW TO GET this?;
layer.MinScale = mapLayerInfo.MinScale;
layer.MaxScale = mapLayerInfo.MaxScale;
layer.ParentLayerId = mapLayerInfo.ParentLayerID;
layer.SubLayers = mapLayerInfo.SubLayers; return layer;
} Ok, there is a way to do it with multiply casts and few extra loops (esri why?) As what surprising is that after 2 (?) months question staid without answer - the only place for Q reg ESRI. The full desc how to do it can be found here - text in PL. If you are interested only in code, here it is: // get map info
public static MapInfo ConstructFrom(IMapServer3 mapServer3)
{
// IMapServerInfo3 contains CopyrightText prop, 1 & 2 does not
var mapServerInfo = (IMapServerInfo3)mapServer3.GetServerInfo(mapServer3.DefaultMapName); var mapInfo = new MapInfo
{
Description = mapServerInfo.Description,
MapName = mapServerInfo.Name,
CopyrightText = mapServerInfo.CopyrightText
}; IMapLayerInfos layerInfos = mapServerInfo.MapLayerInfos;
for (int i = 0; i < layerInfos.Count; i++)
{
var layerInfo = layerInfos.Element[i]; mapInfo.Layers.Add(
LayerInfo.ConstructFrom(
layerInfo,
LayerInfo.IsLayerVisible(mapServerInfo, layerInfo.ID)
));
} return mapInfo;
} // get layer info
private static readonly int[] AvaliableReports = new[] {17,18,19,20};
public static LayerInfo ConstructFrom(IMapLayerInfo mapLayerInfo, bool visible)
{
var layerInfo = new LayerInfo
{
Id = mapLayerInfo.ID,
DisplayField = mapLayerInfo.DisplayField,
ScaleUpper = (int)mapLayerInfo.MaxScale,
ScaleLower = (int)mapLayerInfo.MinScale,
Name = mapLayerInfo.Name,
Description = mapLayerInfo.Description,
DefaultVisibility = visible,
ParentLayerId = mapLayerInfo.ParentLayerID,
}; IFields fields = mapLayerInfo.Fields;
bool addFields = false;
if (fields != null)
{
for (int j = 0; j < fields.FieldCount; j++)
{
IField field = fields.Field[j]; if (field.Type == esriFieldType.esriFieldTypeString)
{
layerInfo.DictFields[field.Name] = field.AliasName;
continue;
} if(field.Type != esriFieldType.esriFieldTypeGeometry)
{
continue;
} IGeometryDef geometryDef = field.GeometryDef; layerInfo.GeometryType = Enum.GetName(typeof(esriGeometryType), geometryDef.GeometryType); switch (geometryDef.GeometryType)
{
case esriGeometryType.esriGeometryNull:
layerInfo.GeometryType = null;
break;
case esriGeometryType.esriGeometryPoint:
addFields = true;
break;
}
}
} // hack: this should be done in a proper way... but for now is enough
layerInfo.ContainsReport = AvaliableReports.Contains(layerInfo.Id); if(!addFields)
{
layerInfo.DictFields = new Dictionary<string, string>();
} if (mapLayerInfo.SubLayers == null)
{
return layerInfo;
} for (int i = 0; i < mapLayerInfo.SubLayers.Count; i++)
{
layerInfo.SubLayerIds.Add(mapLayerInfo.SubLayers.Element[i]);
} return layerInfo;
} // get default visibility
public static bool IsLayerVisible(IMapServerInfo3 mapServerInfo, int layerId)
{
ILayerDescriptions layerDescs = mapServerInfo.DefaultMapDescription.LayerDescriptions;
long c = layerDescs.Count; for (long i = 0; i < c; i++)
{
var layerDesc = (ILayerDescription3)layerDescs.Element[i]; if (layerDesc.ID == layerId)
{
return layerDesc.Visible;
}
} return false;
}

how to get geometry type of layer using IMapServer3 and IMapLayerInfo? (C#)的更多相关文章

  1. 弹出层layer的使用

    弹出层layer的使用 Intro layer是一款web弹层组件,致力于服务各个水平段的开发人员.layer官网:http://layer.layui.com/ layer侧重于用户灵活的自定义,为 ...

  2. layer弹出信息框API

    首先向大家推荐layer,在这里也非常感谢贤心的贡献,非常不错的信息框及弹出层解决方案,为一些项目的前端开发提高了很大的效率,希望layer 越办越好! 下面是API,呵呵,官方抄袭过来的,为了自己看 ...

  3. Caffe源码解析3:Layer

    转载请注明出处,楼燚(yì)航的blog,http://home.cnblogs.com/louyihang-loves-baiyan/ layer这个类可以说是里面最终的一个基本类了,深度网络呢就是 ...

  4. jQuery layer[页面弹出框]

    常见接口如下: 方法名 描述 $.layer({}) 核心接口,参数是一个对象,对象属性参见上述列表.诸如layer.alert()之类的为$.layer()的包装方法. layer.v 获取版本号. ...

  5. boost库之geometry<二>

    #include <boost/assign.hpp> #include <boost/geometry/core/point_type.hpp> #include <b ...

  6. Layer弹层组件 二次扩展,项目中直接使用。

    /************************ Layer扩展 ****************************/ /* * Layer弹出Alert提示框 * @param messag ...

  7. layer.open

    1.type-基本层类型 类型:Number,默认:0 layer提供了5种层类型.可传入的值有:0(信息框,默认)1(页面层)2(iframe层)3(加载层)4(tips层). 若你采用layer. ...

  8. Caffe中Layer注册机制

    Caffe内部维护一个注册表用于查找特定Layer对应的工厂函数(Layer Factory的设计用到了设计模式里的工厂模式).Caffe的Layer注册表是一组键值对(key, value)( La ...

  9. jquery 弹窗插件 layer 常见接口

    源自:https://www.cnblogs.com/teamobaby/p/3556584.html 常见接口如下: 方法名 描述 $.layer({}) 核心接口,参数是一个对象,对象属性参见上述 ...

随机推荐

  1. SQL优化基础 使用索引(一个小例子)

    按照本文操作和体会,会对sql优化有个基本最简单的了解,其他深入还需要更多资料和实践的学习: 1. 建表: 复制代码代码如下: create table site_user ( id int IDEN ...

  2. vuex的应用和解决的实际问题

    这是vuex的语法结构内容 简单的理解vuex: new Vue({ // state data () { return { count: 0 } }, // view template: ` < ...

  3. PDO 错误处理模式

    异常模式: $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 这个模式需要配合 try 使用 :一旦出错,就会: 1. ...

  4. tinyxml

    在TinyXML中,根据XML的各种元素来定义了一些类:        TiXmlBase:整个TinyXML模型的基类.        TiXmlAttribute:对应于XML中的元素的属性.   ...

  5. iphone X 的适配

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  6. 常量指针(pointer to constant)和指针常量(constant pointer)

    一个指针可以操作两个实体,一个是指针值(即地址),一个是间访值(即指向的实体).于是指针的常量性也分为两种:常量指针(pointer to constant)和指针常量(constant pointe ...

  7. 牛客网提高组第二场---solution

    T1 方差 根据题目要求将式子先写出来注意下面式子中的 $n$ 全部都是 $n-1$$$\begin{aligned}ans&=n^2\times \frac{1}{n}\times \sum ...

  8. [Python3网络爬虫开发实战] 4-解析库的使用

    上一章中,我们实现了一个最基本的爬虫,但提取页面信息时使用的是正则表达式,这还是比较烦琐,而且万一有地方写错了,可能导致匹配失败,所以使用正则表达式提取页面信息多多少少还是有些不方便. 对于网页的节点 ...

  9. [Python3网络爬虫开发实战] 1.9.2-Scrapyd的安装

    Scrapyd是一个用于部署和运行Scrapy项目的工具,有了它,你可以将写好的Scrapy项目上传到云主机并通过API来控制它的运行. 既然是Scrapy项目部署,基本上都使用Linux主机,所以本 ...

  10. (八)python3 迭代

    迭代:如果给定一个 list 或 tuple,我们可以通过 for 循环来遍历这个 list 或tuple,这种遍历我们称为迭代(Iteration) 字典: >>> d = {'a ...