yushff

code the world。

导航

ae中栅格数据转为矢量数据 (转)

Posted on 2012-11-02 12:34  yushff  阅读(917)  评论(0编辑  收藏  举报
ILayer pLayer = pAxMapControl.get_Layer(this.cmbLayer.SelectedIndex);
IRasterLayer pRasterLayer = pLayer as IRasterLayer;

IWorkspaceFactory2 pWorkspaceFactory2 = new RasterWorkspaceFactoryClass();
IRasterWorkspace pRasterWorkspace;

int Index = pRasterLayer.FilePath.LastIndexOf("\\");
string filePath = pRasterLayer.FilePath.Substring(0, Index);
string fileName = pRasterLayer.FilePath.Substring(Index + 1);

pRasterWorkspace = (IRasterWorkspace)pWorkspaceFactory2.OpenFromFile(filePath, 0);
IRasterDataset pRasterDataset = pRasterWorkspace.OpenRasterDataset(fileName);


IGeoDataset pRasterGeoDataset = pRasterDataset as IGeoDataset;
IWorkspaceFactory2 pWorkspaceFactoryShp = new ShapefileWorkspaceFactoryClass();
//............................................................................
IWorkspace pWorkspace = pWorkspaceFactoryShp.OpenFromFile(this.tbFolderPath.Text, 0);
IConversionOp pConversionOp = new RasterConversionOpClass();
ISpatialReference pSpatialReference = pRasterGeoDataset.SpatialReference;

IGeoDataset pGeoDataset;
//....................................................................
pGeoDataset = pConversionOp.RasterDataToPolygonFeatureData(pRasterGeoDataset, pWorkspace, this.tbName.Text, true);

IDataset pDataset1 = pGeoDataset as IDataset;
IFeatureClass pFeatureClass = pDataset1 as IFeatureClass;

IFeatureLayer pFeatureLayer = new FeatureLayerClass();
pFeatureLayer.FeatureClass = pFeatureClass;

pAxMapControl.ClearLayers();
pAxMapControl.AddLayer(pFeatureLayer);
pAxMapControl.Refresh();