动态加载影像图层为例

研究了两三天算是弄出来了。本例适合影像数据量特别的大程序使用,可以动态的添加删除影像数据,还有不完善的地方,不过基本满足要求。

1.首先得到关键点的图层

m_Map = axMapControl.Map;

int l = 0;

int f = 0;

for (int j = 0; j < m_Map.LayerCount; j++)

{

if (m_Map.get_Layer(j).Name == "Points")

{

l = j;//获得Points图层

}

}

2.取得该范围

double xmax = env.XMax;

double ymax = env.YMax;

double xmin = env.XMin;

double ymin = env.YMin;

3.经纬度以及名称字段的属性信息存入arraylist

ArrayList aList = new ArrayList();

ArrayList bList = new ArrayList();

ArrayList nList = new ArrayList();

IFeatureLayer ilayer = (IFeatureLayer)m_Map.get_Layer(l);//得到点图层

IFeatureCursor pFeatureCursor;

pFeatureCursor = ilayer.FeatureClass.Search(null, false);

IFeature pFeature;

pFeature = pFeatureCursor.NextFeature();

while (pFeature != null)

{

string jdValue = Convert.ToString(pFeature.get_Value(4));

string wdValue = Convert.ToString(pFeature.get_Value(5));

string name = Convert.ToString(pFeature.get_Value(2));

pFeature = pFeatureCursor.NextFeature();

aList.Add(jdValue);//经纬度以及name存入arraylist

bList.Add(wdValue);

nList.Add(name);

}

4.遍历arraylist并判断点是否在可视范围内

if (m_Map.MapScale < 400000)

{

for (int j = 0; j < 35; j++)

{

double jd = double.Parse(aList[j].ToString());

double wd = double.Parse(bList[j].ToString());

//判断土层中是否已经存在某个影像数据,若存在则不进行坐标的判断

if (jd >= xmin && jd <= xmax)

{

if (wd >= ymin && wd <= ymax)

{  nameid = nList[j].ToString();//获得name属性

for (int q = 0; q < axMapControl.Map.LayerCount; q++)

{

temp = getname == nameid + ".tif";

getname = Convert.ToString(axMapControl.get_Layer(q).Name);

if(temp)

indexa = q - 1;

}

5.调用添加影像数据函数dynamicadd()(目前是本地)

//动态加载删格数据

public void dynamicadd(string strFullPath)

{

int Index = strFullPath.LastIndexOf("\\");

string fileName = strFullPath.Substring(Index + 1);

string filePath = strFullPath.Substring(0, Index);

IWorkspaceFactory workspaceFactory = new RasterWorkspaceFactory();

IRasterWorkspace rasterWorkspace = (IRasterWorkspace)workspaceFactory.OpenFromFile(filePath, 0);

IRasterDataset rasterDataset = (IRasterDataset)rasterWorkspace.OpenRasterDataset(fileName);

IRasterLayer rasterLayer = new RasterLayerClass();

rasterLayer.CreateFromDataset(rasterDataset);

axMapControl.AddLayer(rasterLayer, 2);//有心的话你会发现此函数与axMapControl.Map.AddLayer()的区别(没有插入的图层序号),可以试试哦!

}

6.判断是否已经动态加载

if (temp)

{

//MessageBox.Show(Convert.ToString(axMapControl.get_Layer(indexa).Name));//测试

axMapControl.get_Layer(indexa).MinimumScale = 250000;//设定这个图层的可见范围?

return;

}

else

{

string strFullPath = "";

strFullPath = Application.StartupPath + @"\\data\影像\" + nameid + ".tif";//这里就是影像图层的路径

dynamicadd(strFullPath);

axMapControl.get_Layer(2).MinimumScale = 250000;

break;

}

7将影像图层控制在五个以内超过了就删除

clearLayer.Add(nameid);

axMapControl.get_Layer(2).MinimumScale = 250000;

if (clearLayer.Count > 5)//当图层超过5个时清除最早加载的图层(应该是不在视图范围内的)

{

for (int e = 0; e < axMapControl.LayerCount;e++ )

{

if(axMapControl.get_Layer(e).Name.ToString() == clearLayer[0].ToString()+".tif")

{

//ILayer layer = null;

//layer = axMapControl.Map.get_Layer(e);

axMapControl.DeleteLayer(e);

}

}

8.综上所述

调用部分

//范围
IEnvelope env = axMapControl.Extent;//获取范围
fanwei(env);//可以返回string nameid再根据nameid寻找路径

主要声明的字段以及arraylist

string nameid = "";//关键的传值字段,连接影像数据的路径

string getname = "";//

bool temp =false;//判断是否已经加载的bool类型变量

ArrayList clearLayer = new ArrayList();

主要函数部分

public void fanwei(IEnvelope env)

{

m_Map = axMapControl.Map;

int l = 0;

int f = 0;

for (int j = 0; j < m_Map.LayerCount; j++)

{

if (m_Map.get_Layer(j).Name == "Points")

{

l = j;//获得Points图层为以后得到图层传递l

}

}

double xmax = env.XMax;

double ymax = env.YMax;

double xmin = env.XMin;

double ymin = env.YMin;//屏幕范围参数取值

ArrayList aList = new ArrayList();

ArrayList bList = new ArrayList();

ArrayList nList = new ArrayList();//用来存储经纬度以及名称字段的arraylist

IFeatureLayer ilayer = (IFeatureLayer)m_Map.get_Layer(l);//得到点图层

IFeatureCursor pFeatureCursor;

pFeatureCursor = ilayer.FeatureClass.Search(null, false);

IFeature pFeature;

pFeature = pFeatureCursor.NextFeature();//用来获取字段值的关键

while (pFeature != null)

{

string jdValue = Convert.ToString(pFeature.get_Value(4));

string wdValue = Convert.ToString(pFeature.get_Value(5));

string name = Convert.ToString(pFeature.get_Value(2));

pFeature = pFeatureCursor.NextFeature();

aList.Add(jdValue);//经纬度以及name存入arraylist

bList.Add(wdValue);

nList.Add(name);

}

if (m_Map.MapScale < 400000)//比例尺大于此值将进行判断

{

for (int j = 0; j < 35; j++)//在这里我知道共有35个点

{

double jd = double.Parse(aList[j].ToString());

double wd = double.Parse(bList[j].ToString());

//判断点是否在可视范围内,在范围内则取值nameid与影像数据路径相关联

//判断图层中是否已经存在某个影像数据,若存在则不进行坐标的判断

if (jd >= xmin && jd <= xmax)

{

if (wd >= ymin && wd <= ymax)

{

nameid = nList[j].ToString();//获得name属性

for (int q = 0; q < axMapControl.Map.LayerCount; q++)

{

temp = (getname == nameid + ".tif");

getname = Convert.ToString(axMapControl.get_Layer(q).Name);

if(temp)

{

indexa = q - 1;

break;//很重要!!!!

}

}

if (temp)

{

for (int e = 0; e < axMapControl.LayerCount; e++)
{
for (int r = 0; r < clearLayer.Count; r++)
{
if (axMapControl.get_Layer(e).Name.ToString() == clearLayer[r].ToString() + ".tif")
{
//ILayer layer = null;
//layer = axMapControl.Map.get_Layer(e);
axMapControl.get_Layer(e).MinimumScale = 250000;
}
}
}

return;//return还是break要注意

}

else

{

string strFullPath = "";

strFullPath = Application.StartupPath + @"\\data\影像\" + nameid + ".tif";

dynamicadd(strFullPath);

clearLayer.Add(nameid);

          

if (clearLayer.Count > 5)//当图层超过5个时清除最早加载的图层(应该是不在视图范围内的)

{

for (int e = 0; e < axMapControl.LayerCount;e++ )

{

if(axMapControl.get_Layer(e).Name.ToString() == clearLayer[0].ToString()+".tif")

{

//ILayer layer = null;

//layer = axMapControl.Map.get_Layer(e);

axMapControl.DeleteLayer(e);

}

}

}

break;

}                        }

}

}

}

}

如果有问题欢迎提出建议!刚刚做出来可能有需要完善的地方

arcengine C#关于动态添加图层的更多相关文章

  1. js动态添加事件-事件委托

    作者:白狼 出处:http://www.manks.top/javascript-dynamic-event.html 本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给 ...

  2. 后台动态添加的button,如何触发button_click事件?

    后台动态添加的button,需要在Page_Load或者Page_Init重新动态生成才能执行button_click public Panel GetContrlType() { Panel pan ...

  3. jquery动态添加的html,第三方插件无法生效的情况

    今天一个问题纠结了半天,问题如下图  问题大致就是如上,新增的内容死活点不起,插件没有生效,在一个装逼前端群里面问,给我的答案是叫我去了解事件委托,了解一下事件冒泡!! 好吧,我一上午加半个下午的时间 ...

  4. 【Java EE 学习 75 下】【数据采集系统第七天】【二进制运算实现权限管理】【使用反射初始化权限表】【权限捕获拦截器动态添加权限】

    一.使用反射动态添加权限 在该系统中,我使用struts2的时候非常规范,访问的Action的形式都是"ActionClassName_MethodName.action?参数列表" ...

  5. Hadoop学习笔记—13.分布式集群中节点的动态添加与下架

    开篇:在本笔记系列的第一篇中,我们介绍了如何搭建伪分布与分布模式的Hadoop集群.现在,我们来了解一下在一个Hadoop分布式集群中,如何动态(不关机且正在运行的情况下)地添加一个Hadoop节点与 ...

  6. Net作业调度(五)—quartz.net动态添加job设计

    介绍 在实际项目使用中quartz.net中,都希望有一个管理界面可以动态添加job,而避免每次都要上线发布. 也看到有园子的同学问过.这里就介绍下实现动态添加job的几种方式, 也是二次开发的核心模 ...

  7. vue中v-bind:class动态添加class

    1.html代码 <template v-for='item in names'> <div id="app" class="selectItem&qu ...

  8. js表单动态添加数据并提交

    情景1:已经存在form对象了,动态为form增加对象并提交 function formAppendSubmit(){ var myform=$('#newArticleForm'); //得到for ...

  9. [转]jquery append 动态添加的元素事件on 不起作用的解决方案

    用jquery添加新元素很容易,面对jquery append 动态添加的元素事件on 不起作用我们该如何解决呢?on方法中要先找到原选择器(如例.info),再找到动态添加的选择器(如列.delet ...

随机推荐

  1. 获取sql执行时间

    sql server中获取要执行的sql或sql块的执行时间,方法之一如下: declare @begin datetime,@end datetime set @begin =getdate() - ...

  2. 编写Linux/Unix守护进程

    原文: http://www.cnblogs.com/haimingwey/archive/2012/04/25/2470190.html 守护进程在Linux/Unix系统中有着广泛的应用.有时,开 ...

  3. 01_change_schema.sql

    set echo on feedback on spool ./log/01_change_schema.log -- -- schema change to v_idocdata_un -- -- ...

  4. php 数据库并发处理

    在并行系统中并发问题永远不可忽视.尽管PHP语言原生没有提供多线程机制,那并不意味着所有的操作都是线程安全的.尤其是在操作诸如订单.支付等业务系统中,更需要注意操作数据库的并发问题. 接下来我通过一个 ...

  5. Oulipo HDU 1686 KMP模板

    题目大意:求模式串在主串中的出现次数. 题目思路:KMP模板题 #include<iostream> #include<algorithm> #include<cstri ...

  6. 门面模式(Facade)解析

    门面模式使用一个门面类来包装一些复杂的类,对外提供一个简单的访问方法. 见如下代码: class CPU { public void startup() { System.out.println(&q ...

  7. ibatis 自动生成map,bean,dao

    1.下载 AbatorForEclipse1.1.0 地址:http://download.csdn.net/detail/fym548/9426877 点击Archive按钮选择下载的,然后重启My ...

  8. 转:WebDriver进行屏幕截图

    例: 打开百度首页 ,进行截图 01 packagecom.example.tests;  02 importjava.io.File;  03 importorg.apache.commons.io ...

  9. hdu_5726_GCD(线段树维护区间+预处理)

    题目链接:hdu_5726_GCD 题意: 给你n个数(n<=1e5)然后m个询问(m<=1e5),每个询问一个区间,问你这个区间的GCD是多少,并且输出从1到n有多少个区间的GCD和这个 ...

  10. VS2010 C#调用C++ DLL文件

    http://www.soaspx.com/dotnet/csharp/csharp_20110406_7469.html http://www.cnblogs.com/warensoft/archi ...