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