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. Sublime Text 2/3 输入法修复[Ubuntu(Debian)]

    一直想找一个可以替代sublime的IDE主要还是hi因为没有好的方法解决中文输入的问题, 今天在网上找到一个非常不错的方法,亲自实验是可行的,就记录下来了,我的系统是ubuntu16.04 Subl ...

  2. 洛谷 P3388 【模板】割点

    题目背景 割点 题目描述 给出一个n个点,m条边的无向图,求图的割点. 输入输出格式 输入格式: 第一行输入n,m 下面m行每行输入x,y表示x到y有一条边 输出格式: 第一行输出割点个数 第二行按照 ...

  3. parsley.js正确使用姿势

    1.第一式 当然要先引用:parsley.js 2.第二式 页面中定义需要使用自定义校验,注意红色的地方,必须要使用小写,重要的问题说三遍,小写,小写 <form class="for ...

  4. MySQL_将ubuntu18.04上的数据库导出并导入windows10下

    1.使用:mysqldump -uroot -p databasename>filename.sql databasename:要导出的数据库名. filename:指定导出sql文件的文件名. ...

  5. cf536c——思路题

    题目 题目:Lunar New Year and Number Division 题目大意:给定一个数字序列,可以任意分组(可调整顺序),但每组至少两个,求每组内数字和的平方的最小值 思路 首先,易证 ...

  6. CAS机制总结

    一.简介 CAS机制:(Compare and set)比较和替换 简单来说–>使用一个期望值来和当前变量的值进行比较,如果当前的变量值与我们期望的值相等,就用一个新的值来更新当前变量的值CAS ...

  7. jdk11 eclipse下开启ZGC

    平台支持 ZGC目前只在Linux/x64上可用,如果有足够的需求,将来可能会增加对其他平台的支持. 对的,目前只支持64位的linux系统. -_-' eclipse.ini配置: -XX:+Unl ...

  8. OBJECTPROPERTY用法整理

    OBJECTPROPERTY用法整理 分类: 系统表与表结构 数据库管理维护2010-06-03 16:37 2783人阅读 评论(1) 收藏 举报 数据库sql serverinsertobject ...

  9. iOS工具】rvm、Ruby环境和CocoaPods安装使用及相关报错问题解决

    〇.前言 <p>在iOS开发中 CocoaPods作为库依赖管理工具就是一把利器. 有了 CocoaPods则无需再通过拖 第三方库及第三方库所依赖的 framework静态库到项目中等麻 ...

  10. LNMP环境搭建网站

    系统:Centos7.4 一台服务器安装nginx.php.mysql 原理不是很懂,但实测如下两种环境下都能成功,这里做下记录: 1.一个干净的系统,从0开始完成所有步骤,完成LNMP搭建 2.已经 ...