关闭

ArcGISEngine实现图层输出kml

标签: ArcGISc#esri
981人阅读 评论(0) 收藏 举报
分类:

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);

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:417812次
    • 积分:6998
    • 等级:
    • 排名:第3435名
    • 原创:292篇
    • 转载:3篇
    • 译文:1篇
    • 评论:36条
    最新评论