dwg 파일에서 도면층 이름으로 지정한 도면층을 추출하여arcgis에 대응하는 벡터 도면층으로

4593 단어 ArcGIS 개발
사고방식:dwg 파일을 얻는데 dwg 파일은 요소류의 개념이 없기 때문에arcengine로 읽을 때 읽는 층은 네 가지로 나뉜다. 그것이 바로 점선면과 주석이다.구체적인 코드는 다음과 같습니다.
       private void GetLayer()   
        {
        string sFolderPath = textBox1.Text.Substring(0, textBox1.Text.LastIndexOf("\\"));
        string sFeaClsName = textBox1.Text.Substring(textBox1.Text.LastIndexOf("\\") + 1);
        IWorkspaceFactory pWorkspaceFactory = new CadWorkspaceFactoryClass();
        IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(sFolderPath, 0);


        IFeatureDataset pFeatureDataset = pFeatureWorkspace.OpenFeatureDataset(sFeaClsName);
        IFeatureClassContainer pFeatureClassContainer = (IFeatureClassContainer)pFeatureDataset;

        nameName1 = new string[allname.Count];
        for (int i = 0; i < allname.Count; i++)
        {
            nameName1[i] = allname[i];
        }

        QueryFilter pfile = new QueryFilterClass();
        pfile.WhereClause = "Layer = "  + "'1-  '";

        for (int i = 0; i < pFeatureClassContainer.ClassCount; i++)
        {
            IFeatureClass featureClass = pFeatureClassContainer.get_Class(i);
            if (featureClass.FeatureType != esriFeatureType.esriFTAnnotation )
            {
                int c = featureClass.Fields.FieldCount;

                if (featureClass.ShapeType == esriGeometryType.esriGeometryPoint)
                {
                    IFeatureCursor pcur = featureClass.Search(pfile, false);
                    if (pcur.NextFeature() != null)
                    {
                        SaveFeatureclass(featureClass, pcur, "1-  ");
                    }
                }
            }
        }
    }

    private void SaveFeatureclass(IFeatureClass featureClass, IFeatureCursor pfeatureCur, string featureclassName)
    {
        try
        {
            IWorkspaceFactory pWSF = new ShapefileWorkspaceFactoryClass();
            IFeatureWorkspace pFWS = (IFeatureWorkspace)pWSF.OpenFromFile(textBox2.Text, 0);

            IFields pFields = new FieldsClass();
            IFieldsEdit pFieldsEdit;
            pFieldsEdit = (IFieldsEdit)pFields;

            for (int i = 0; i < featureClass.Fields.FieldCount; i++)
            {
                pFieldsEdit.AddField(featureClass.Fields.Field[i]);
            }
            IFeatureClass pclass = pFWS.CreateFeatureClass(featureclassName, pFields, featureClass.CLSID, featureClass.EXTCLSID, featureClass.FeatureType, "Shape", "");
            InsertFeaturesUsingCursor(pfeatureCur, pclass);
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message,"  ");
        }
       
    }

    public void InsertFeaturesUsingCursor(IFeatureCursor cursor, IFeatureClass targetFeatureClass)
    {
        using (ComReleaser comReleaser = new ComReleaser())
        {
            IFeatureBuffer featureBuffer = targetFeatureClass.CreateFeatureBuffer();
            comReleaser.ManageLifetime(featureBuffer);

            IFeatureCursor insertCursor = targetFeatureClass.Insert(true);
            comReleaser.ManageLifetime(insertCursor);

            IFeature sourceFeature = cursor.NextFeature();

            while (sourceFeature != null)
            {
                //              Simplify,        ,     
                featureBuffer.Shape = sourceFeature.ShapeCopy;

                for (int i = 0; i < sourceFeature.Fields.FieldCount; i++)
                {
                    IField field = sourceFeature.Fields.get_Field(i);
                    if (field.Type != esriFieldType.esriFieldTypeOID && field.Type != esriFieldType.esriFieldTypeGeometry && field.Type != esriFieldType.esriFieldTypeGlobalID && field.Type != esriFieldType.esriFieldTypeGUID)
                    {
                        string fieldName = field.Name;
                        int index = featureBuffer.Fields.FindField(fieldName);
                        if (index > -1)
                            featureBuffer.set_Value(index, sourceFeature.get_Value(i));
                    }

                }
                insertCursor.InsertFeature(featureBuffer);
                sourceFeature = cursor.NextFeature();
            }

            // Flush the buffer to the geodatabase.
            insertCursor.Flush();
            ComReleaser.ReleaseCOMObject(cursor);

        }
        IFeatureClassManage targetFeatureClassManage = targetFeatureClass as IFeatureClassManage;
        targetFeatureClassManage.UpdateExtent();
    }

좋은 웹페이지 즐겨찾기