public static void ConverTool(IFeatureClass feature,string fold) { Geoprocessor gp = new Geoprocessor(); gp.OverwriteOutput = true; ESRI.ArcGIS.ConversionTools.FeatureClassToShapefile Conver = new FeatureClassToShapefile(); Conver.Input_Features=feature; Conver.Output_Folder = fold; gp.Execute(Conver, null); }
/// <summary> /// Cria um shapefile a partir de um featureCursor /// </summary> /// <param name="feature">Feature desejada</param> public static void CriarShapefile(IFeatureLayer fLayer, IFeature feature, string pasta, IActiveView activeView, bool adicionarSaidaNoMapa, IFeatureWorkspace pFeatureWorkspaceShp) { if (feature != null) { #region Deletando shapefiles que possam existir já no diretório DirectoryInfo dirInf = new DirectoryInfo(pasta); FileInfo[] fi = dirInf.GetFiles(); for (int i = 0; i < fi.Length; i++) { if (fi[i].Name.Contains(fLayer.FeatureClass.AliasName) && !fi[i].Name.Contains(".lock")) { fi[i].Delete(); } } #endregion IWorkspace pScratchWorkspace; IScratchWorkspaceFactory pScratchWorkspaceFactory; pScratchWorkspaceFactory = new ScratchWorkspaceFactoryClass(); pScratchWorkspace = pScratchWorkspaceFactory.DefaultScratchWorkspace; IFeatureSelection pNewSelSet = fLayer as IFeatureSelection; IEnvelope pEnv = activeView.Extent.Envelope; IGeometry pEnvGeo = pEnv as IEnvelope; ISpatialFilter pSF = new SpatialFilterClass(); pSF.Geometry = pEnvGeo; pSF.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; IQueryFilter qf = new QueryFilterClass(); qf.WhereClause = (fLayer as IFeatureLayerDefinition).DefinitionExpression; pNewSelSet.SelectFeatures(qf, esriSelectionResultEnum.esriSelectionResultNew, false); Geoprocessor gp = new Geoprocessor(); gp.AddOutputsToMap = adicionarSaidaNoMapa; FeatureClassToShapefile fcToShapeFile = new FeatureClassToShapefile(); fcToShapeFile.Input_Features = fLayer; fcToShapeFile.Output_Folder = pasta; IGeoProcessorResult result = gp.Execute(fcToShapeFile, null) as IGeoProcessorResult; string nomeArquivoSaida = gp.GetMessage(3); IFeatureClass pFeatureClassShp = pFeatureWorkspaceShp.OpenFeatureClass(fLayer.FeatureClass.AliasName); GisUtils.TratarSubtiposDominiosShapefile(fLayer, pasta, pFeatureWorkspaceShp, pFeatureClassShp); pFeatureClassShp = null; GC.Collect(); GC.WaitForPendingFinalizers(); } }