public static ILayer OpenAnnotationLayer(IFeatureClass pfc) { IFDOGraphicsLayerFactory pfdof = new FDOGraphicsLayerFactoryClass(); IFeatureDataset pFDS = pfc.FeatureDataset; IWorkspace pWS = pFDS.Workspace; IFeatureWorkspace pFWS = pWS as IFeatureWorkspace; ILayer pLayer = pfdof.OpenGraphicsLayer(pFWS, pFDS, (pfc as IDataset).Name); return(pLayer); }
public IFeatureLayer AddFeatureClassToMap(string layerName) { IFeatureWorkspace feaWorkSpace = this.m_workSpace as IFeatureWorkspace; IFeatureClass featClass = feaWorkSpace.OpenFeatureClass(layerName); if (featClass.FeatureType == esriFeatureType.esriFTAnnotation) { IDataset dataSet = featClass as IDataset; IFDOGraphicsLayerFactory pGLF = new FDOGraphicsLayerFactoryClass(); IFDOGraphicsLayer pFDOGLayer = pGLF.OpenGraphicsLayer((IFeatureWorkspace)dataSet.Workspace, featClass.FeatureDataset, dataSet.Name) as IFDOGraphicsLayer; ((IFeatureLayer)pFDOGLayer).Name = layerName; return((IFeatureLayer)pFDOGLayer); } else { IFeatureLayer feaLyr = new FeatureLayerClass(); feaLyr.FeatureClass = featClass; feaLyr.Name = layerName; return(feaLyr); } }
public void AppendAnnoElementsSDE(IFeatureClass pSrcFClass, IFeatureClass pTargetFClass) { try { IFields pOFlds; IFields pIFlds; pOFlds = pTargetFClass.Fields; pIFlds = pSrcFClass.Fields; IField pFld; int[] lSrcFlds; int[] lTrgFlds; IDataset pDataset; int lFld, lExFld, i; lExFld = 0; for (lFld = 0; lFld < pIFlds.FieldCount; lFld++) { pFld = pIFlds.get_Field(lFld); if (pFld.Type != esriFieldType.esriFieldTypeOID && pFld.Type != esriFieldType.esriFieldTypeGeometry && pFld.Name.ToUpper() != "ELEMENT" && pFld.Name.ToUpper() != "ANNOTATIONCLASSID" && pFld.Name.ToUpper() != "ZORDER" && pFld.Editable) { lExFld++; } } lSrcFlds = new int[lExFld]; lTrgFlds = new int[lExFld]; i = 0; for (lFld = 0; lFld < pIFlds.FieldCount; lFld++) { pFld = pIFlds.get_Field(lFld); if (pFld.Type != esriFieldType.esriFieldTypeOID && pFld.Type != esriFieldType.esriFieldTypeGeometry && pFld.Name.ToUpper() != "ELEMENT" && pFld.Name.ToUpper() != "ANNOTATIONCLASSID" && pFld.Name.ToUpper() != "ZORDER" && pFld.Editable) { lSrcFlds[i] = lFld; lTrgFlds[i] = pOFlds.FindField(pFld.Name); i++; } } IFeatureCursor pICursor; pICursor = pSrcFClass.Search(null, false); IFeature pIFeat; pIFeat = pICursor.NextFeature(); IFDOGraphicsLayerFactory pGLF; pGLF = new FDOGraphicsLayerFactoryClass(); pDataset = pTargetFClass as IDataset; IFDOGraphicsLayer pFDOGLayer; pFDOGLayer = pGLF.OpenGraphicsLayer((IFeatureWorkspace)pDataset.Workspace, pTargetFClass.FeatureDataset, pDataset.Name) as IFDOGraphicsLayer; IFDOAttributeConversion pFDOACon; pFDOACon = pFDOGLayer as IFDOAttributeConversion; ; pFDOGLayer.BeginAddElements(); pFDOACon.SetupAttributeConversion2(lExFld, lSrcFlds, lTrgFlds); IAnnotationFeature pAnnoFeature; IClone pAClone; IElement pGSElement; while (pIFeat != null) { pAnnoFeature = pIFeat as IAnnotationFeature; pAClone = pAnnoFeature.Annotation as IClone; pGSElement = pAClone.Clone() as IElement; pFDOGLayer.DoAddFeature(pIFeat, pGSElement, 0); pIFeat = pICursor.NextFeature(); } pFDOGLayer.EndAddElements(); } catch (Exception ex) { MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void AppendAnnoElements(ILayer pSrcLayer, IFeatureClass pTargetFC,IActiveView activeview) { //首先从cad的注记层得到一个注记,然后得到他的Annotation,再赋给新建的要素 //IQueryFilter queryfilter = new QueryFilterClass(); //queryfilter.WhereClause = "Layer = '" + filter + "'"; try { IFeatureLayer pSrcFLayer = pSrcLayer as IFeatureLayer; IFeatureClass pSrcFC = pSrcFLayer.FeatureClass; IFeature cadFeat; IElement featElement; IDataset pDataset; pDataset = pTargetFC as IDataset; IFDOGraphicsLayer pFDOGLayer; IFDOGraphicsLayerFactory pGLF = new FDOGraphicsLayerFactoryClass(); ICoverageAnnotationLayer pCadAnnoLayer; pCadAnnoLayer = pSrcLayer as ICoverageAnnotationLayer; IWorkspace pWorkspace = pDataset.Workspace as IWorkspace; IWorkspaceEdit pWorkspaceEdit = pWorkspace as IWorkspaceEdit; IScreenDisplay screendis = activeview.ScreenDisplay; pFDOGLayer = pGLF.OpenGraphicsLayer((IFeatureWorkspace)pDataset.Workspace, pTargetFC.FeatureDataset, pDataset.Name) as IFDOGraphicsLayer; pCadAnnoLayer.StartGeneratingGraphics(null, screendis, false); pCadAnnoLayer.NextFeatureAndGraphic(out cadFeat, out featElement); //IFeature newFeature; IFeature cadFeature; IAnnotationFeature pAnnoFeature; IPolygon poly = new PolygonClass(); //IEnvelope box; pWorkspaceEdit.StartEditing(false); pWorkspaceEdit.StartEditOperation(); //int index; //pFDOGLayer.BeginAddElements(); int count = 0; //pstepro.StepValue = 1; IFeatureBuffer featbuffer = pTargetFC.CreateFeatureBuffer(); IFeatureCursor featCur = pTargetFC.Insert(true); while (cadFeat != null && featElement != null) { //pFDOGLayer.DoAddFeature(cadFeat, featElement, 0); //判断分在那一个层 count++; //pstepro.Position = count;//进度条增加 cadFeature = pSrcFC.GetFeature(cadFeat.OID); //if (cadFeature.get_Value(cadFeature.Fields.FindField("Layer")).ToString() != filter) //{ // pCadAnnoLayer.NextFeatureAndGraphic(out cadFeat, out featElement); // continue; //} //newFeature = pTargetFC.CreateFeature(); poly = cadFeat.ShapeCopy as IPolygon; featbuffer.Shape = poly as IGeometry; pAnnoFeature = featbuffer as IAnnotationFeature; pAnnoFeature.Annotation = featElement; int index1 = getLayerIndex(cadFeature.get_Value(cadFeature.Fields.FindField("Layer")).ToString()); featbuffer.set_Value(4, index1); featCur.InsertFeature(featbuffer); //newFeature.Store(); /////////////// pCadAnnoLayer.NextFeatureAndGraphic(out cadFeat, out featElement); } featCur.Flush(); //pFDOGLayer.EndAddElements(); pWorkspaceEdit.StopEditOperation(); pWorkspaceEdit.StopEditing(true); } catch (Exception ex) { MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public IFeatureLayer AddFeatureClassToMap(string layerName) { IFeatureWorkspace feaWorkSpace = this.m_workSpace as IFeatureWorkspace; IFeatureClass featClass = feaWorkSpace.OpenFeatureClass(layerName); if (featClass.FeatureType == esriFeatureType.esriFTAnnotation) { IDataset dataSet = featClass as IDataset; IFDOGraphicsLayerFactory pGLF = new FDOGraphicsLayerFactoryClass(); IFDOGraphicsLayer pFDOGLayer = pGLF.OpenGraphicsLayer((IFeatureWorkspace)dataSet.Workspace, featClass.FeatureDataset, dataSet.Name) as IFDOGraphicsLayer; ((IFeatureLayer)pFDOGLayer).Name = layerName; return (IFeatureLayer)pFDOGLayer; } else { IFeatureLayer feaLyr = new FeatureLayerClass(); feaLyr.FeatureClass = featClass; feaLyr.Name = layerName; return feaLyr; } }
private void method_3(object object_0) { frmOpenFile file = new frmOpenFile { Text = "添加数据", AllowMultiSelect = true }; file.AddFilter(new MyGxFilterDatasets(), true); if (file.DoModalOpen() == DialogResult.OK) { IFeatureClass featureClass; IFeatureLayer layer; System.Windows.Forms.Cursor.Current = Cursors.WaitCursor; IArray array = new ArrayClass(); IArray items = file.Items; int index = 0; while (true) { if (index >= items.Count) { break; } IGxDataset dataset = items.get_Element(index) as IGxDataset; if (dataset != null) { IDataset dataset2 = dataset.Dataset; if (dataset2 != null) { if (dataset2.Type == esriDatasetType.esriDTFeatureClass) { featureClass = (IFeatureClass)dataset2; if (featureClass.FeatureType == esriFeatureType.esriFTAnnotation) { layer = new FDOGraphicsLayerClass { FeatureClass = featureClass, Name = featureClass.AliasName }; } else { layer = new FeatureLayerClass { FeatureClass = featureClass, Name = featureClass.AliasName }; } array.Add(layer); } else { IFDOGraphicsLayerFactory factory; if (dataset2.Type == esriDatasetType.esriDTCadDrawing) { IEnumGxObject children = (dataset as IGxObjectContainer).Children; children.Reset(); for (IGxDataset dataset3 = children.Next() as IGxDataset; dataset3 != null; dataset3 = children.Next() as IGxDataset) { featureClass = dataset3.Dataset as IFeatureClass; if (featureClass.FeatureType == esriFeatureType.esriFTAnnotation) { factory = new FDOGraphicsLayerFactoryClass(); layer = (IFeatureLayer) factory.OpenGraphicsLayer( (IFeatureWorkspace)featureClass.FeatureDataset.Workspace, featureClass.FeatureDataset, featureClass.AliasName); } else { layer = new FeatureLayerClass { FeatureClass = featureClass, Name = featureClass.AliasName }; } array.Add(layer); } } else if (dataset2.Type == esriDatasetType.esriDTFeatureDataset) { IFeatureClassContainer container = (IFeatureClassContainer)dataset2; index = 0; while (index < (container.ClassCount - 1)) { featureClass = container.get_Class(index); if (featureClass.FeatureType == esriFeatureType.esriFTAnnotation) { factory = new FDOGraphicsLayerFactoryClass(); layer = (IFeatureLayer) factory.OpenGraphicsLayer( (IFeatureWorkspace)featureClass.FeatureDataset.Workspace, featureClass.FeatureDataset, featureClass.AliasName); } else { layer = new FeatureLayerClass { FeatureClass = featureClass, Name = featureClass.AliasName }; } array.Add(layer); index++; } } else if (dataset2.Type == esriDatasetType.esriDTTin) { ITinLayer unk = new TinLayerClass { Dataset = (ITin)dataset2, Name = dataset2.Name }; array.Add(unk); } else if ((dataset2.Type == esriDatasetType.esriDTRasterDataset) || (dataset2.Type == esriDatasetType.esriDTRasterBand)) { bool flag = true; if (!((IRasterPyramid)dataset2).Present) { if (ApplicationRef.PyramidPromptType == PyramidPromptType.AlwaysBuildNoPrompt) { ((IRasterPyramid)dataset2).Create(); } else if (ApplicationRef.PyramidPromptType == PyramidPromptType.AlwaysPrompt) { switch (BuildPyramidSet.Show()) { case DialogResult.Yes: ((IRasterPyramid)dataset2).Create(); break; case DialogResult.Cancel: flag = false; break; } } } if (flag) { RasterLayerClass class3 = new RasterLayerClass { Cached = true }; IRasterLayer layer3 = class3; layer3.CreateFromDataset((IRasterDataset)dataset2); layer3.Name = dataset2.Name; array.Add(layer3); } } else if (dataset2.Type == esriDatasetType.esriDTTable) { try { IRasterCatalogTable pCatalog = new RasterCatalogTableClass { Table = (ITable)dataset2 }; pCatalog.Update(); IRasterCatalogLayer layer4 = new RasterCatalogLayerClass(); layer4.Create(pCatalog); layer4.Name = dataset2.BrowseName; array.Add(layer4); } catch { } } } } } index++; } int count = array.Count; ILayer layer5 = null; for (index = count - 1; index >= 0; index--) { layer5 = array.get_Element(index) as ILayer; if (layer5 is IRasterCatalogLayer) { if (object_0 is IMap) { (object_0 as IMap).AddLayer(layer5); } else if (object_0 is IGroupLayer) { (object_0 as IGroupLayer).Add(layer5); } array.Remove(index); count--; } } for (index = count - 1; index >= 0; index--) { layer5 = array.get_Element(index) as ILayer; if (layer5 is IRasterLayer) { if (object_0 is IMap) { (object_0 as IMap).AddLayer(layer5); } else if (object_0 is IGroupLayer) { (object_0 as IGroupLayer).Add(layer5); } array.Remove(index); count--; } } for (index = count - 1; index >= 0; index--) { layer5 = array.get_Element(index) as ILayer; if (layer5 is ITinLayer) { if (object_0 is IMap) { (object_0 as IMap).AddLayer(layer5); } else if (object_0 is IGroupLayer) { (object_0 as IGroupLayer).Add(layer5); } array.Remove(index); count--; } } for (index = count - 1; index >= 0; index--) { layer5 = array.get_Element(index) as ILayer; if (layer5 is IFeatureLayer) { layer = layer5 as IFeatureLayer; featureClass = layer.FeatureClass; if ((featureClass.ShapeType == esriGeometryType.esriGeometryPolygon) || (featureClass.ShapeType == esriGeometryType.esriGeometryEnvelope)) { if (object_0 is IMap) { (object_0 as IMap).AddLayer(layer5); } else if (object_0 is IGroupLayer) { (object_0 as IGroupLayer).Add(layer5); } array.Remove(index); count--; } } } for (index = count - 1; index >= 0; index--) { layer5 = array.get_Element(index) as ILayer; if (layer5 is IFeatureLayer) { layer = layer5 as IFeatureLayer; featureClass = layer.FeatureClass; if (((((featureClass.ShapeType == esriGeometryType.esriGeometryLine) || (featureClass.ShapeType == esriGeometryType.esriGeometryBezier3Curve)) || ((featureClass.ShapeType == esriGeometryType.esriGeometryCircularArc) || (featureClass.ShapeType == esriGeometryType.esriGeometryEllipticArc))) || (featureClass.ShapeType == esriGeometryType.esriGeometryPath)) || (featureClass.ShapeType == esriGeometryType.esriGeometryPolyline)) { if (object_0 is IMap) { (object_0 as IMap).AddLayer(layer5); } else if (object_0 is IGroupLayer) { (object_0 as IGroupLayer).Add(layer5); } array.Remove(index); count--; } } } for (index = count - 1; index >= 0; index--) { layer5 = array.get_Element(index) as ILayer; if (layer5 is IFeatureLayer) { layer = layer5 as IFeatureLayer; featureClass = layer.FeatureClass; if ((featureClass.ShapeType == esriGeometryType.esriGeometryMultipoint) || (featureClass.ShapeType == esriGeometryType.esriGeometryPoint)) { if (object_0 is IMap) { (object_0 as IMap).AddLayer(layer5); } else if (object_0 is IGroupLayer) { (object_0 as IGroupLayer).Add(layer5); } array.Remove(index); count--; } } } for (index = count - 1; index >= 0; index--) { layer5 = array.get_Element(index) as ILayer; if (object_0 is IMap) { (object_0 as IMap).AddLayer(layer5); } else if (object_0 is IGroupLayer) { (object_0 as IGroupLayer).Add(layer5); } array.Remove(index); } System.Windows.Forms.Cursor.Current = Cursors.Default; } }
public static ILayer OpenAnnotationLayer(IFeatureClass pfc) { IFDOGraphicsLayerFactory pfdof = new FDOGraphicsLayerFactoryClass(); IFeatureDataset pFDS = pfc.FeatureDataset; IWorkspace pWS = pFDS.Workspace; IFeatureWorkspace pFWS = pWS as IFeatureWorkspace; ILayer pLayer = pfdof.OpenGraphicsLayer(pFWS, pFDS, (pfc as IDataset).Name); return pLayer; }
public void AppendAnnoElementsSDE(IFeatureClass pSrcFClass, IFeatureClass pTargetFClass) { try { IFields pOFlds; IFields pIFlds; pOFlds = pTargetFClass.Fields; pIFlds = pSrcFClass.Fields; IField pFld; int[] lSrcFlds; int[] lTrgFlds; IDataset pDataset; int lFld, lExFld, i; lExFld = 0; for (lFld = 0; lFld < pIFlds.FieldCount; lFld++) { pFld = pIFlds.get_Field(lFld); if (pFld.Type != esriFieldType.esriFieldTypeOID && pFld.Type != esriFieldType.esriFieldTypeGeometry && pFld.Name.ToUpper() != "ELEMENT" && pFld.Name.ToUpper() != "ANNOTATIONCLASSID" && pFld.Name.ToUpper() != "ZORDER" && pFld.Editable) { lExFld++; } } lSrcFlds = new int[lExFld]; lTrgFlds = new int[lExFld]; i = 0; for (lFld = 0; lFld < pIFlds.FieldCount; lFld++) { pFld = pIFlds.get_Field(lFld); if (pFld.Type != esriFieldType.esriFieldTypeOID && pFld.Type != esriFieldType.esriFieldTypeGeometry && pFld.Name.ToUpper() != "ELEMENT" && pFld.Name.ToUpper() != "ANNOTATIONCLASSID" && pFld.Name.ToUpper() != "ZORDER" && pFld.Editable) { lSrcFlds[i] = lFld; lTrgFlds[i] = pOFlds.FindField(pFld.Name); i++; } } IFeatureCursor pICursor; pICursor = pSrcFClass.Search(null, false); IFeature pIFeat; pIFeat = pICursor.NextFeature(); IFDOGraphicsLayerFactory pGLF; pGLF = new FDOGraphicsLayerFactoryClass(); pDataset = pTargetFClass as IDataset; IFDOGraphicsLayer pFDOGLayer; pFDOGLayer = pGLF.OpenGraphicsLayer((IFeatureWorkspace)pDataset.Workspace, pTargetFClass.FeatureDataset, pDataset.Name) as IFDOGraphicsLayer; IFDOAttributeConversion pFDOACon; pFDOACon = pFDOGLayer as IFDOAttributeConversion;; pFDOGLayer.BeginAddElements(); pFDOACon.SetupAttributeConversion2(lExFld, lSrcFlds, lTrgFlds); IAnnotationFeature pAnnoFeature; IClone pAClone; IElement pGSElement; while (pIFeat != null) { pAnnoFeature = pIFeat as IAnnotationFeature; pAClone = pAnnoFeature.Annotation as IClone; pGSElement = pAClone.Clone() as IElement; pFDOGLayer.DoAddFeature(pIFeat, pGSElement, 0); pIFeat = pICursor.NextFeature(); } pFDOGLayer.EndAddElements(); } catch (Exception ex) { MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void AppendAnnoElements(ILayer pSrcLayer, IFeatureClass pTargetFC, IActiveView activeview) { //首先从cad的注记层得到一个注记,然后得到他的Annotation,再赋给新建的要素 //IQueryFilter queryfilter = new QueryFilterClass(); //queryfilter.WhereClause = "Layer = '" + filter + "'"; try { IFeatureLayer pSrcFLayer = pSrcLayer as IFeatureLayer; IFeatureClass pSrcFC = pSrcFLayer.FeatureClass; IFeature cadFeat; IElement featElement; IDataset pDataset; pDataset = pTargetFC as IDataset; IFDOGraphicsLayer pFDOGLayer; IFDOGraphicsLayerFactory pGLF = new FDOGraphicsLayerFactoryClass(); ICoverageAnnotationLayer pCadAnnoLayer; pCadAnnoLayer = pSrcLayer as ICoverageAnnotationLayer; IWorkspace pWorkspace = pDataset.Workspace as IWorkspace; IWorkspaceEdit pWorkspaceEdit = pWorkspace as IWorkspaceEdit; IScreenDisplay screendis = activeview.ScreenDisplay; pFDOGLayer = pGLF.OpenGraphicsLayer((IFeatureWorkspace)pDataset.Workspace, pTargetFC.FeatureDataset, pDataset.Name) as IFDOGraphicsLayer; pCadAnnoLayer.StartGeneratingGraphics(null, screendis, false); pCadAnnoLayer.NextFeatureAndGraphic(out cadFeat, out featElement); //IFeature newFeature; IFeature cadFeature; IAnnotationFeature pAnnoFeature; IPolygon poly = new PolygonClass(); //IEnvelope box; pWorkspaceEdit.StartEditing(false); pWorkspaceEdit.StartEditOperation(); //int index; //pFDOGLayer.BeginAddElements(); int count = 0; //pstepro.StepValue = 1; IFeatureBuffer featbuffer = pTargetFC.CreateFeatureBuffer(); IFeatureCursor featCur = pTargetFC.Insert(true); while (cadFeat != null && featElement != null) { //pFDOGLayer.DoAddFeature(cadFeat, featElement, 0); //判断分在那一个层 count++; //pstepro.Position = count;//进度条增加 cadFeature = pSrcFC.GetFeature(cadFeat.OID); //if (cadFeature.get_Value(cadFeature.Fields.FindField("Layer")).ToString() != filter) //{ // pCadAnnoLayer.NextFeatureAndGraphic(out cadFeat, out featElement); // continue; //} //newFeature = pTargetFC.CreateFeature(); poly = cadFeat.ShapeCopy as IPolygon; featbuffer.Shape = poly as IGeometry; pAnnoFeature = featbuffer as IAnnotationFeature; pAnnoFeature.Annotation = featElement; int index1 = getLayerIndex(cadFeature.get_Value(cadFeature.Fields.FindField("Layer")).ToString()); featbuffer.set_Value(4, index1); featCur.InsertFeature(featbuffer); //newFeature.Store(); /////////////// pCadAnnoLayer.NextFeatureAndGraphic(out cadFeat, out featElement); } featCur.Flush(); //pFDOGLayer.EndAddElements(); pWorkspaceEdit.StopEditOperation(); pWorkspaceEdit.StopEditing(true); } catch (Exception ex) { MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } }