private void CreateLayer(IName name) { ILayerFactoryHelper helper = new LayerFactoryHelperClass(); try { IEnumLayer layer = helper.CreateLayersFromName(name); layer.Reset(); for (ILayer layer2 = layer.Next(); layer2 != null; layer2 = layer.Next()) { this.axMapControl1.AddLayer(layer2, 0); this.axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, layer2, null); } } catch (Exception) { MessageBox.Show("无法打开指定文档!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Hand); } }
private ILayer method_1(string string_1) { IFileName name = new FileNameClass { Path = string_1 }; ILayerFactoryHelper helper = new LayerFactoryHelperClass(); try { IEnumLayer layer = helper.CreateLayersFromName(name as IName); layer.Reset(); return(layer.Next()); } catch (Exception exception) { Logger.Current.Error("", exception, ""); } return(null); }
public void Execute(ESRI.ArcGIS.esriSystem.IArray paramvalues, ESRI.ArcGIS.esriSystem.ITrackCancel TrackCancel, ESRI.ArcGIS.Geoprocessing.IGPEnvironmentManager envMgr, ESRI.ArcGIS.Geodatabase.IGPMessages message) { try { IGPUtilities3 gpUtilities3 = new GPUtilitiesClass(); if (TrackCancel == null) { TrackCancel = new CancelTrackerClass(); } // find feature class inside the given feature dataset IGPParameter osmFeatureDatasetParameter = paramvalues.get_Element(in_osmFeatureDatasetNumber) as IGPParameter; IDEFeatureDataset osmFeatureDataset = gpUtilities3.UnpackGPValue(osmFeatureDatasetParameter) as IDEFeatureDataset; string osmPointFeatureClassString = ((IDataElement)osmFeatureDataset).Name + "_osm_pt"; string osmLineFeatureClassString = ((IDataElement)osmFeatureDataset).Name + "_osm_ln"; string osmPolygonFeatureClassString = ((IDataElement)osmFeatureDataset).Name + "_osm_ply"; IFeatureClass osmPointFeatureClass = gpUtilities3.OpenFeatureClassFromString(((IDataElement)osmFeatureDataset).CatalogPath + "/" + osmPointFeatureClassString); IFeatureClass osmLineFeatureClass = gpUtilities3.OpenFeatureClassFromString(((IDataElement)osmFeatureDataset).CatalogPath + "/" + osmLineFeatureClassString); IFeatureClass osmPoylgonFeatureClass = gpUtilities3.OpenFeatureClassFromString(((IDataElement)osmFeatureDataset).CatalogPath + "/" + osmPolygonFeatureClassString); // open the specified layers holding the symbology and editing templates IGPParameter osmPointSymbolTemplateParameter = paramvalues.get_Element(in_osmPointLayerNumber) as IGPParameter; IGPValue osmGPPointLayerValue = gpUtilities3.UnpackGPValue(osmPointSymbolTemplateParameter); IGPParameter outputPointGPParameter = paramvalues.get_Element(out_osmPointLayerNumber) as IGPParameter; IGPValue outputPointLayerGPValue = gpUtilities3.UnpackGPValue(outputPointGPParameter); bool isLayerOnDisk = false; // create a clone of the source layer // we will then go ahead and adjust the data source (dataset) of the cloned layer IObjectCopy objectCopy = new ObjectCopyClass(); ICompositeLayer adjustedPointTemplateLayer = objectCopy.Copy(osmGPPointLayerValue) as ICompositeLayer; IGPGroupLayer osmPointGroupTemplateLayer = adjustedPointTemplateLayer as IGPGroupLayer; ICompositeLayer compositeLayer = gpUtilities3.Open((IGPValue)osmPointGroupTemplateLayer) as ICompositeLayer; //ICompositeLayer adjustedPointTemplateLayer = osmGPPointLayerValue as ICompositeLayer; //IGPGroupLayer osmPointGroupTemplateLayer = osmGPPointLayerValue as IGPGroupLayer; //IClone cloneSource = osmPointGroupTemplateLayer as IClone; //ICompositeLayer compositeLayer = m_gpUtilities3.Open((IGPValue)cloneSource.Clone()) as ICompositeLayer; if (compositeLayer == null) { ILayerFactoryHelper layerFactoryHelper = new LayerFactoryHelperClass(); IFileName layerFileName = new FileNameClass(); layerFileName.Path = osmGPPointLayerValue.GetAsText(); IEnumLayer enumLayer = layerFactoryHelper.CreateLayersFromName((IName)layerFileName); enumLayer.Reset(); compositeLayer = enumLayer.Next() as ICompositeLayer; isLayerOnDisk = true; } IFeatureLayerDefinition2 featureLayerDefinition2 = null; ISQLSyntax sqlSyntax = null; IGPLayer adjustedPointGPLayer = null; if (compositeLayer != null) { for (int layerIndex = 0; layerIndex < compositeLayer.Count; layerIndex++) { IFeatureLayer2 geoFeatureLayer = compositeLayer.get_Layer(layerIndex) as IFeatureLayer2; if (geoFeatureLayer != null) { if (geoFeatureLayer.ShapeType == osmPointFeatureClass.ShapeType) { try { ((IDataLayer2)geoFeatureLayer).Disconnect(); } catch { } ((IDataLayer2)geoFeatureLayer).DataSourceName = ((IDataset)osmPointFeatureClass).FullName; ((IDataLayer2)geoFeatureLayer).Connect(((IDataset)osmPointFeatureClass).FullName); featureLayerDefinition2 = geoFeatureLayer as IFeatureLayerDefinition2; if (featureLayerDefinition2 != null) { string queryDefinition = featureLayerDefinition2.DefinitionExpression; sqlSyntax = ((IDataset)osmPointFeatureClass).Workspace as ISQLSyntax; string delimiterIdentifier = sqlSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierPrefix); if (String.IsNullOrEmpty(queryDefinition) == false) { string stringToReplace = queryDefinition.Substring(0, 1); queryDefinition = queryDefinition.Replace(stringToReplace, delimiterIdentifier); } featureLayerDefinition2.DefinitionExpression = queryDefinition; } } } } adjustedPointGPLayer = gpUtilities3.MakeGPLayerFromLayer((ILayer)compositeLayer); // save the newly adjusted layer information to disk if (isLayerOnDisk == true) { ILayerFile pointLayerFile = new LayerFileClass(); if (pointLayerFile.get_IsPresent(outputPointLayerGPValue.GetAsText())) { try { File.Delete(outputPointLayerGPValue.GetAsText()); } catch (Exception ex) { message.AddError(120041, ex.Message); return; } } pointLayerFile.New(outputPointLayerGPValue.GetAsText()); pointLayerFile.ReplaceContents((ILayer)compositeLayer); pointLayerFile.Save(); adjustedPointGPLayer = gpUtilities3.MakeGPLayerFromLayer((ILayer)pointLayerFile.Layer); } // IGPLayer adjustedPointGPLayer = gpUtilities3.MakeGPLayerFromLayer((ILayer)compositeLayer); gpUtilities3.AddInternalLayer2((ILayer)compositeLayer, adjustedPointGPLayer); gpUtilities3.PackGPValue((IGPValue)adjustedPointGPLayer, outputPointGPParameter); } isLayerOnDisk = false; IGPParameter osmLineSymbolTemplateParameter = paramvalues.get_Element(in_osmLineLayerNumber) as IGPParameter; IGPValue osmGPLineLayerValue = gpUtilities3.UnpackGPValue(osmLineSymbolTemplateParameter) as IGPValue; IGPParameter outputLineGPParameter = paramvalues.get_Element(out_osmLineLayerNumber) as IGPParameter; IGPValue outputLineLayerGPValue = gpUtilities3.UnpackGPValue(outputLineGPParameter); IGPValue adjustedLineTemplateLayer = objectCopy.Copy(osmGPLineLayerValue) as IGPValue; IGPGroupLayer osmLineGroupTemplateLayer = adjustedLineTemplateLayer as IGPGroupLayer; compositeLayer = gpUtilities3.Open((IGPValue)osmLineGroupTemplateLayer) as ICompositeLayer; if (compositeLayer == null) { ILayerFactoryHelper layerFactoryHelper = new LayerFactoryHelperClass(); IFileName layerFileName = new FileNameClass(); layerFileName.Path = osmGPLineLayerValue.GetAsText(); IEnumLayer enumLayer = layerFactoryHelper.CreateLayersFromName((IName)layerFileName); enumLayer.Reset(); compositeLayer = enumLayer.Next() as ICompositeLayer; isLayerOnDisk = true; } if (compositeLayer != null) { for (int layerIndex = 0; layerIndex < compositeLayer.Count; layerIndex++) { IFeatureLayer2 geoFeatureLayer = compositeLayer.get_Layer(layerIndex) as IFeatureLayer2; if (geoFeatureLayer.ShapeType == osmLineFeatureClass.ShapeType) { try { ((IDataLayer2)geoFeatureLayer).Disconnect(); } catch { } ((IDataLayer2)geoFeatureLayer).DataSourceName = ((IDataset)osmLineFeatureClass).FullName; ((IDataLayer2)geoFeatureLayer).Connect(((IDataset)osmLineFeatureClass).FullName); featureLayerDefinition2 = geoFeatureLayer as IFeatureLayerDefinition2; if (featureLayerDefinition2 != null) { string queryDefinition = featureLayerDefinition2.DefinitionExpression; sqlSyntax = ((IDataset)osmLineFeatureClass).Workspace as ISQLSyntax; string delimiterIdentifier = sqlSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierPrefix); if (string.IsNullOrEmpty(queryDefinition) == false) { string stringToReplace = queryDefinition.Substring(0, 1); queryDefinition = queryDefinition.Replace(stringToReplace, delimiterIdentifier); } featureLayerDefinition2.DefinitionExpression = queryDefinition; } } } // save the newly adjusted layer information to disk if (isLayerOnDisk == true) { ILayerFile lineLayerFile = new LayerFileClass(); if (lineLayerFile.get_IsPresent(outputLineLayerGPValue.GetAsText())) { try { File.Delete(outputLineLayerGPValue.GetAsText()); } catch (Exception ex) { message.AddError(120042, ex.Message); return; } } lineLayerFile.New(outputLineLayerGPValue.GetAsText()); lineLayerFile.ReplaceContents((ILayer)compositeLayer); lineLayerFile.Save(); } IGPLayer adjustLineGPLayer = gpUtilities3.MakeGPLayerFromLayer((ILayer)compositeLayer); gpUtilities3.AddInternalLayer2((ILayer)compositeLayer, adjustLineGPLayer); gpUtilities3.PackGPValue((IGPValue)adjustLineGPLayer, outputLineGPParameter); } isLayerOnDisk = false; IGPParameter osmPolygonSymbolTemplateParameter = paramvalues.get_Element(in_osmPolygonLayerNumber) as IGPParameter; IGPValue osmGPPolygonLayerValue = gpUtilities3.UnpackGPValue(osmPolygonSymbolTemplateParameter); IGPParameter outputPolygonGPParameter = paramvalues.get_Element(out_osmPolygonLayerNumber) as IGPParameter; IGPValue outputPolygonLayerGPValue = gpUtilities3.UnpackGPValue(outputPolygonGPParameter); IGPValue adjustedPolygonTemplateLayer = objectCopy.Copy(osmGPPolygonLayerValue) as IGPValue; IGPGroupLayer osmPolygonGroupTemplateLayer = adjustedPolygonTemplateLayer as IGPGroupLayer; compositeLayer = gpUtilities3.Open((IGPValue)osmPolygonGroupTemplateLayer) as ICompositeLayer; if (compositeLayer == null) { ILayerFactoryHelper layerFactoryHelper = new LayerFactoryHelperClass(); IFileName layerFileName = new FileNameClass(); layerFileName.Path = osmGPPolygonLayerValue.GetAsText(); IEnumLayer enumLayer = layerFactoryHelper.CreateLayersFromName((IName)layerFileName); enumLayer.Reset(); compositeLayer = enumLayer.Next() as ICompositeLayer; isLayerOnDisk = true; } if (compositeLayer != null) { for (int layerIndex = 0; layerIndex < compositeLayer.Count; layerIndex++) { IFeatureLayer2 geoFeatureLayer = compositeLayer.get_Layer(layerIndex) as IFeatureLayer2; if (geoFeatureLayer.ShapeType == osmPoylgonFeatureClass.ShapeType) { try { ((IDataLayer2)geoFeatureLayer).Disconnect(); } catch { } ((IDataLayer2)geoFeatureLayer).DataSourceName = ((IDataset)osmPoylgonFeatureClass).FullName; ((IDataLayer2)geoFeatureLayer).Connect(((IDataset)osmPoylgonFeatureClass).FullName); featureLayerDefinition2 = geoFeatureLayer as IFeatureLayerDefinition2; if (featureLayerDefinition2 != null) { string queryDefinition = featureLayerDefinition2.DefinitionExpression; sqlSyntax = ((IDataset)osmPoylgonFeatureClass).Workspace as ISQLSyntax; string delimiterIdentifier = sqlSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierPrefix); if (String.IsNullOrEmpty(queryDefinition) == false) { string stringToReplace = queryDefinition.Substring(0, 1); queryDefinition = queryDefinition.Replace(stringToReplace, delimiterIdentifier); } featureLayerDefinition2.DefinitionExpression = queryDefinition; } } } // save the newly adjusted layer information to disk if (isLayerOnDisk == true) { ILayerFile polygonLayerFile = new LayerFileClass(); if (polygonLayerFile.get_IsPresent(outputPolygonLayerGPValue.GetAsText())) { try { File.Delete(outputPolygonLayerGPValue.GetAsText()); } catch (Exception ex) { message.AddError(120043, ex.Message); return; } } polygonLayerFile.New(outputPolygonLayerGPValue.GetAsText()); polygonLayerFile.ReplaceContents((ILayer)compositeLayer); polygonLayerFile.Save(); } IGPLayer adjustedPolygonGPLayer = gpUtilities3.MakeGPLayerFromLayer((ILayer)compositeLayer); gpUtilities3.AddInternalLayer2((ILayer)compositeLayer, adjustedPolygonGPLayer); gpUtilities3.PackGPValue((IGPValue)adjustedPolygonGPLayer, outputPolygonGPParameter); } } catch (Exception ex) { message.AddError(-10, ex.Message); } }
public void Execute(ESRI.ArcGIS.esriSystem.IArray paramvalues, ESRI.ArcGIS.esriSystem.ITrackCancel TrackCancel, ESRI.ArcGIS.Geoprocessing.IGPEnvironmentManager envMgr, ESRI.ArcGIS.Geodatabase.IGPMessages message) { try { IGPUtilities3 gpUtilities3 = new GPUtilitiesClass(); if (TrackCancel == null) { TrackCancel = new CancelTrackerClass(); } // find feature class inside the given feature dataset IGPParameter osmFeatureDatasetParameter = paramvalues.get_Element(in_osmFeatureDatasetNumber) as IGPParameter; IDEFeatureDataset osmFeatureDataset = gpUtilities3.UnpackGPValue(osmFeatureDatasetParameter) as IDEFeatureDataset; string osmPointFeatureClassString = ((IDataElement)osmFeatureDataset).Name + "_osm_pt"; string osmLineFeatureClassString = ((IDataElement)osmFeatureDataset).Name + "_osm_ln"; string osmPolygonFeatureClassString = ((IDataElement)osmFeatureDataset).Name + "_osm_ply"; IFeatureClass osmPointFeatureClass = gpUtilities3.OpenFeatureClassFromString(((IDataElement)osmFeatureDataset).CatalogPath + "/" + osmPointFeatureClassString); IFeatureClass osmLineFeatureClass = gpUtilities3.OpenFeatureClassFromString(((IDataElement)osmFeatureDataset).CatalogPath + "/" + osmLineFeatureClassString); IFeatureClass osmPoylgonFeatureClass = gpUtilities3.OpenFeatureClassFromString(((IDataElement)osmFeatureDataset).CatalogPath + "/" + osmPolygonFeatureClassString); // open the specified layers holding the symbology and editing templates IGPParameter osmPointSymbolTemplateParameter = paramvalues.get_Element(in_osmPointLayerNumber) as IGPParameter; IGPValue osmGPPointLayerValue = gpUtilities3.UnpackGPValue(osmPointSymbolTemplateParameter); IGPParameter outputPointGPParameter = paramvalues.get_Element(out_osmPointLayerNumber) as IGPParameter; IGPValue outputPointLayerGPValue = gpUtilities3.UnpackGPValue(outputPointGPParameter); bool isLayerOnDisk = false; // create a clone of the source layer // we will then go ahead and adjust the data source (dataset) of the cloned layer IObjectCopy objectCopy = new ObjectCopyClass(); ICompositeLayer adjustedPointTemplateLayer = objectCopy.Copy(osmGPPointLayerValue) as ICompositeLayer; IGPGroupLayer osmPointGroupTemplateLayer = adjustedPointTemplateLayer as IGPGroupLayer; ICompositeLayer compositeLayer = gpUtilities3.Open((IGPValue)osmPointGroupTemplateLayer) as ICompositeLayer; //ICompositeLayer adjustedPointTemplateLayer = osmGPPointLayerValue as ICompositeLayer; //IGPGroupLayer osmPointGroupTemplateLayer = osmGPPointLayerValue as IGPGroupLayer; //IClone cloneSource = osmPointGroupTemplateLayer as IClone; //ICompositeLayer compositeLayer = m_gpUtilities3.Open((IGPValue)cloneSource.Clone()) as ICompositeLayer; if (compositeLayer == null) { ILayerFactoryHelper layerFactoryHelper = new LayerFactoryHelperClass(); IFileName layerFileName = new FileNameClass(); layerFileName.Path = osmGPPointLayerValue.GetAsText(); IEnumLayer enumLayer = layerFactoryHelper.CreateLayersFromName((IName)layerFileName); enumLayer.Reset(); compositeLayer = enumLayer.Next() as ICompositeLayer; isLayerOnDisk = true; } IFeatureLayerDefinition2 featureLayerDefinition2 = null; ISQLSyntax sqlSyntax = null; IGPLayer adjustedPointGPLayer = null; if (compositeLayer != null) { for (int layerIndex = 0; layerIndex < compositeLayer.Count; layerIndex++) { IFeatureLayer2 geoFeatureLayer = compositeLayer.get_Layer(layerIndex) as IFeatureLayer2; if (geoFeatureLayer != null) { if (geoFeatureLayer.ShapeType == osmPointFeatureClass.ShapeType) { try { ((IDataLayer2)geoFeatureLayer).Disconnect(); } catch { } ((IDataLayer2)geoFeatureLayer).DataSourceName = ((IDataset)osmPointFeatureClass).FullName; ((IDataLayer2)geoFeatureLayer).Connect(((IDataset)osmPointFeatureClass).FullName); featureLayerDefinition2 = geoFeatureLayer as IFeatureLayerDefinition2; if (featureLayerDefinition2 != null) { string queryDefinition = featureLayerDefinition2.DefinitionExpression; sqlSyntax = ((IDataset)osmPointFeatureClass).Workspace as ISQLSyntax; string delimiterIdentifier = sqlSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierPrefix); if (String.IsNullOrEmpty(queryDefinition) == false) { string stringToReplace = queryDefinition.Substring(0, 1); queryDefinition = queryDefinition.Replace(stringToReplace, delimiterIdentifier); } featureLayerDefinition2.DefinitionExpression = queryDefinition; } } } } adjustedPointGPLayer = gpUtilities3.MakeGPLayerFromLayer((ILayer)compositeLayer); // save the newly adjusted layer information to disk if (isLayerOnDisk == true) { ILayerFile pointLayerFile = new LayerFileClass(); if (pointLayerFile.get_IsPresent(outputPointLayerGPValue.GetAsText())) { try { File.Delete(outputPointLayerGPValue.GetAsText()); } catch (Exception ex) { message.AddError(120041,ex.Message); return; } } pointLayerFile.New(outputPointLayerGPValue.GetAsText()); pointLayerFile.ReplaceContents((ILayer)compositeLayer); pointLayerFile.Save(); adjustedPointGPLayer = gpUtilities3.MakeGPLayerFromLayer((ILayer)pointLayerFile.Layer); } // IGPLayer adjustedPointGPLayer = gpUtilities3.MakeGPLayerFromLayer((ILayer)compositeLayer); gpUtilities3.AddInternalLayer2((ILayer)compositeLayer, adjustedPointGPLayer); gpUtilities3.PackGPValue((IGPValue)adjustedPointGPLayer, outputPointGPParameter); } isLayerOnDisk = false; IGPParameter osmLineSymbolTemplateParameter = paramvalues.get_Element(in_osmLineLayerNumber) as IGPParameter; IGPValue osmGPLineLayerValue = gpUtilities3.UnpackGPValue(osmLineSymbolTemplateParameter) as IGPValue; IGPParameter outputLineGPParameter = paramvalues.get_Element(out_osmLineLayerNumber) as IGPParameter; IGPValue outputLineLayerGPValue = gpUtilities3.UnpackGPValue(outputLineGPParameter); IGPValue adjustedLineTemplateLayer = objectCopy.Copy(osmGPLineLayerValue) as IGPValue; IGPGroupLayer osmLineGroupTemplateLayer = adjustedLineTemplateLayer as IGPGroupLayer; compositeLayer = gpUtilities3.Open((IGPValue)osmLineGroupTemplateLayer) as ICompositeLayer; if (compositeLayer == null) { ILayerFactoryHelper layerFactoryHelper = new LayerFactoryHelperClass(); IFileName layerFileName = new FileNameClass(); layerFileName.Path = osmGPLineLayerValue.GetAsText(); IEnumLayer enumLayer = layerFactoryHelper.CreateLayersFromName((IName)layerFileName); enumLayer.Reset(); compositeLayer = enumLayer.Next() as ICompositeLayer; isLayerOnDisk = true; } if (compositeLayer != null) { for (int layerIndex = 0; layerIndex < compositeLayer.Count; layerIndex++) { IFeatureLayer2 geoFeatureLayer = compositeLayer.get_Layer(layerIndex) as IFeatureLayer2; if (geoFeatureLayer.ShapeType == osmLineFeatureClass.ShapeType) { try { ((IDataLayer2)geoFeatureLayer).Disconnect(); } catch { } ((IDataLayer2)geoFeatureLayer).DataSourceName = ((IDataset)osmLineFeatureClass).FullName; ((IDataLayer2)geoFeatureLayer).Connect(((IDataset)osmLineFeatureClass).FullName); featureLayerDefinition2 = geoFeatureLayer as IFeatureLayerDefinition2; if (featureLayerDefinition2 != null) { string queryDefinition = featureLayerDefinition2.DefinitionExpression; sqlSyntax = ((IDataset)osmLineFeatureClass).Workspace as ISQLSyntax; string delimiterIdentifier = sqlSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierPrefix); if (string.IsNullOrEmpty(queryDefinition) == false) { string stringToReplace = queryDefinition.Substring(0, 1); queryDefinition = queryDefinition.Replace(stringToReplace, delimiterIdentifier); } featureLayerDefinition2.DefinitionExpression = queryDefinition; } } } // save the newly adjusted layer information to disk if (isLayerOnDisk == true) { ILayerFile lineLayerFile = new LayerFileClass(); if (lineLayerFile.get_IsPresent(outputLineLayerGPValue.GetAsText())) { try { File.Delete(outputLineLayerGPValue.GetAsText()); } catch (Exception ex) { message.AddError(120042, ex.Message); return; } } lineLayerFile.New(outputLineLayerGPValue.GetAsText()); lineLayerFile.ReplaceContents((ILayer)compositeLayer); lineLayerFile.Save(); } IGPLayer adjustLineGPLayer = gpUtilities3.MakeGPLayerFromLayer((ILayer)compositeLayer); gpUtilities3.AddInternalLayer2((ILayer)compositeLayer, adjustLineGPLayer); gpUtilities3.PackGPValue((IGPValue)adjustLineGPLayer, outputLineGPParameter); } isLayerOnDisk = false; IGPParameter osmPolygonSymbolTemplateParameter = paramvalues.get_Element(in_osmPolygonLayerNumber) as IGPParameter; IGPValue osmGPPolygonLayerValue = gpUtilities3.UnpackGPValue(osmPolygonSymbolTemplateParameter); IGPParameter outputPolygonGPParameter = paramvalues.get_Element(out_osmPolygonLayerNumber) as IGPParameter; IGPValue outputPolygonLayerGPValue = gpUtilities3.UnpackGPValue(outputPolygonGPParameter); IGPValue adjustedPolygonTemplateLayer = objectCopy.Copy(osmGPPolygonLayerValue) as IGPValue; IGPGroupLayer osmPolygonGroupTemplateLayer = adjustedPolygonTemplateLayer as IGPGroupLayer; compositeLayer = gpUtilities3.Open((IGPValue)osmPolygonGroupTemplateLayer) as ICompositeLayer; if (compositeLayer == null) { ILayerFactoryHelper layerFactoryHelper = new LayerFactoryHelperClass(); IFileName layerFileName = new FileNameClass(); layerFileName.Path = osmGPPolygonLayerValue.GetAsText(); IEnumLayer enumLayer = layerFactoryHelper.CreateLayersFromName((IName)layerFileName); enumLayer.Reset(); compositeLayer = enumLayer.Next() as ICompositeLayer; isLayerOnDisk = true; } if (compositeLayer != null) { for (int layerIndex = 0; layerIndex < compositeLayer.Count; layerIndex++) { IFeatureLayer2 geoFeatureLayer = compositeLayer.get_Layer(layerIndex) as IFeatureLayer2; if (geoFeatureLayer.ShapeType == osmPoylgonFeatureClass.ShapeType) { try { ((IDataLayer2)geoFeatureLayer).Disconnect(); } catch { } ((IDataLayer2)geoFeatureLayer).DataSourceName = ((IDataset)osmPoylgonFeatureClass).FullName; ((IDataLayer2)geoFeatureLayer).Connect(((IDataset)osmPoylgonFeatureClass).FullName); featureLayerDefinition2 = geoFeatureLayer as IFeatureLayerDefinition2; if (featureLayerDefinition2 != null) { string queryDefinition = featureLayerDefinition2.DefinitionExpression; sqlSyntax = ((IDataset)osmPoylgonFeatureClass).Workspace as ISQLSyntax; string delimiterIdentifier = sqlSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierPrefix); if (String.IsNullOrEmpty(queryDefinition) == false) { string stringToReplace = queryDefinition.Substring(0, 1); queryDefinition = queryDefinition.Replace(stringToReplace, delimiterIdentifier); } featureLayerDefinition2.DefinitionExpression = queryDefinition; } } } // save the newly adjusted layer information to disk if (isLayerOnDisk == true) { ILayerFile polygonLayerFile = new LayerFileClass(); if (polygonLayerFile.get_IsPresent(outputPolygonLayerGPValue.GetAsText())) { try { File.Delete(outputPolygonLayerGPValue.GetAsText()); } catch (Exception ex) { message.AddError(120043, ex.Message); return; } } polygonLayerFile.New(outputPolygonLayerGPValue.GetAsText()); polygonLayerFile.ReplaceContents((ILayer)compositeLayer); polygonLayerFile.Save(); } IGPLayer adjustedPolygonGPLayer = gpUtilities3.MakeGPLayerFromLayer((ILayer)compositeLayer); gpUtilities3.AddInternalLayer2((ILayer)compositeLayer, adjustedPolygonGPLayer); gpUtilities3.PackGPValue((IGPValue)adjustedPolygonGPLayer, outputPolygonGPParameter); } } catch (Exception ex) { message.AddError(-10,ex.Message); } }