ArcGISEngine实现图层输出kml

ArcGIS的转换工具(ConversionTools)提供了将图层输出到kml的接口LayerToKML

这个方法被封装在ESRI.ArcGIS.ConversionTools

    LayerToKML接口的输入参数layer接收两种类型的参数:本地磁盘的图层文件(*.lyr)、内存中的图层。

n  将本地磁盘图层文件(*.lyr)输出kml

// LayerToKML接口输出kml

Geoprocessor pGeoProcessor = newGeoprocessor();

   ESRI.ArcGIS.ConversionTools.LayerToKML pLayerToKML = newESRI.ArcGIS.ConversionTools.LayerToKML();

   pLayerToKML.layer = @"D:\slayer.lyr";

   pLayerToKML.out_kmz_file = "C:\\pkm.kmz";

   pLayerToKML.layer_output_scale = 10000.0;

   pGeoProcessor.OverwriteOutput = true;

   IGeoProcessorResult resultGeo =

           (IGeoProcessorResult)pGeoProcessor.Execute(pLayerToKML, null);

   if(resultGeo.Status == esriJobStatus.esriJobSucceeded)

                    MessageBox.Show("执行成功!", "输出KML", MessageBoxButtons.OK, MessageBoxIcon.Information);

   else

                    MessageBox.Show("执行Error","输出KML",MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

n  将图层选择集输出kml

IFeatureLayer pFeatureLayer = axMapControl1.get_Layer(0) asIFeatureLayer;

//设置空间查询范围条件

ISpatialFilter pQueryFilter = newSpatialFilterClass();

pQueryFilter.Geometry =pPoly;

pQueryFilter.SpatialRel= esriSpatialRelEnum.esriSpatialRelIntersects;

//生成图层在此范围内的选择

IFeatureSelection pFeatureSele = pFeatureLayer asIFeatureSelection;

pFeatureSele.SelectFeatures(pQueryFilter,esriSelectionResultEnum.esriSelectionResultNew,false);

//IFeatureLayerDefinition接口在当前将图层选择集基础上创建新的图层

IFeatureLayerDefinition2 pFLayerDef = pFeatureLayer asIFeatureLayerDefinition2;

IFeatureLayer pNewLyr = pFLayerDef.CreateSelectionLayer("uuu", true, null, null);

// LayerToKML接口输出kml

ESRI.ArcGIS.Geoprocessor.Geoprocessor pGeoProcessor = new ESRI.ArcGIS.Geoprocessor.Geoprocessor();

    ESRI.ArcGIS.ConversionTools.LayerToKML pLayerToKML = new ESRI.ArcGIS.ConversionTools.LayerToKML();

     pLayerToKML.layer= pNewLyr;

    pLayerToKML.out_kmz_file ="C:\\NewKML.kmz" ;

    pLayerToKML.layer_output_scale = 10000.0;

    pGeoProcessor.OverwriteOutput = true;

     IGeoProcessorResult resultGeo =

                    (IGeoProcessorResult)pGeoProcessor.Execute(pLayerToKML,null);

     if (resultGeo.Status == esriJobStatus.esriJobSucceeded)

                    MessageBox.Show("执行成功!", "输出KML",MessageBoxButtons.OK, MessageBoxIcon.Information);

     else

                    MessageBox.Show("执行Error","输出KML", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值