Select to view content in your preferred language

How do you export a parcel fabric with code

3771
5
06-14-2011 08:14 AM
CarlosOrtiz
Emerging Contributor
How do you export a parcel fabric Parcel Polygons to a standard feature class with c# or vb.net.
My organization changed from standard topology to a Parcel Fabric and now I have to rewrite my maintenance applications to move data from the maintenance server where the Parcel Fabric is to a production SDE with just Feature Classes. I planned on using a feature cursor to move the data because I have some other things that need to be done before they are exported, however I can find no examples and I am at a loss at where to start.

Any eamples would be appreciated.

Carlos Ortiz
Tags (2)
0 Kudos
5 Replies
ChristineLeslie
Esri Contributor
Hi Carlos

I do have an example, -just need to dig it out, put it together and post it.

I will do so shortly - keep watching this thread...

PS this can be done pretty easily in python as well.

Christine
0 Kudos
ChrisBuscaglia
Esri Contributor
Carlos, Christine should be able to help you with the .net code, but if you want a quick python example I've attached one.

Do everything in the screenshot below, everything else is used to created stacked condominium parcels for publication (you may not need that).  Of course, you'll also have to replace the SDE connection info and Parcel Fabric name.

Hope this helps

Chris
0 Kudos
ChristineLeslie
Esri Contributor
Below is a sample of code that will export the selected fabric parcels sublayer to a feature class.
In this solution, a form comes up prompting the user for the name of the output feature class.
This was written quite a while ago, so you may not need to unlock fields like this code does.

Hope this helps

Christine

private void btnOK_Click(object sender, EventArgs e)
        {
            m_App = (IApplication)m_FMxApp;
            m_MxDoc = (IMxDocument )m_App.Document;
            m_FeatLayer = (IFeatureLayer)m_MxDoc.SelectedLayer;
            m_Layer2 = (ILayer)m_FeatLayer;
            m_FeatSel = (IFeatureSelection)m_Layer2;

            m_Map = m_MxDoc.FocusMap;
            for (int i = 0; i <= m_Map.LayerCount - 1; i++)
            {
                m_Layer = m_Map.get_Layer(i);
                if (m_Layer is ICadastralFabricLayer)
                {
                    m_FabricLayer = (ICadastralFabricLayer)m_Layer;
                    m_Featlayer2 = m_FabricLayer.get_CadastralSubLayer(esriCadastralFabricRenderer.esriCFRParcels);
                    if (m_Featlayer2 == m_FeatLayer)
                    {
                        IFieldsEdit m_OutputFields = new FieldsClass();

                        m_cadfabric = m_FabricLayer.CadastralFabric;
                        //get parcels table
                        m_FabricParcelsTable = m_cadfabric.get_CadastralTable(esriCadastralFabricTable.esriCFTParcels);

                        //get parcels feature class info
                        m_FeatClass = (IFeatureClass)m_FabricParcelsTable;
                        string shpName = m_FeatClass.ShapeFieldName;
                        long ShpFld = m_FeatClass.FindField(shpName);
                        m_Dataset = (IDataset)m_FeatClass;
                        m_FCName  = m_Dataset.FullName;

                        //clone parcel table fields
                        m_fields = m_FabricParcelsTable.Fields;
                        long FldCnt = m_fields.FieldCount;

                        for (long j = 0; j <= FldCnt-1; j++)
                        {
                            m_Field = m_fields.get_Field (System.Convert.ToInt32 (j));
                            if (j == ShpFld)
                            {
                                m_GeomDef = m_Field.GeometryDef;
                                m_GeomDefEdit = (IGeometryDefEdit)m_GeomDef;
                            }

                            //clone the field
                            m_CloneFld = (IClone)m_Field;
                            m_OutClone = m_CloneFld.Clone();
                            m_FldEdit = (IFieldEdit)m_OutClone;

                            if (j != ShpFld)
                            {
                                m_FldEdit.Required_2 = false;
                                m_FldEdit.DomainFixed_2 = false;
                            }
                            m_OutputFields.AddField(m_FldEdit);
                           
                        }
                     
                        //create new feature class
                        m_FeatClName = new FeatureClassNameClass();
                        m_FDatasetName = new FeatureDatasetNameClass();
                      
                        m_dataset3 = (IDataset)m_WS2;
                        m_OutWSName = m_dataset3.FullName;
                        m_WSName = (IWorkspaceName)m_OutWSName;

                        if (Fdataset == true) //export to feature class in feature dataset
                        {
                            m_FDatasetName.Name = m_dataset2.Name;
                            m_FDatasetName.WorkspaceName = m_WSName;
                            m_FeatClName.FeatureDatasetName = m_FDatasetName ;

                            m_FeatClName.ShapeType = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon;
                            m_DatasetName = (IDatasetName)m_FeatClName;
                            m_DatasetName.Name = featClassname;

                           
                            m_QF = new QueryFilterClass();
                            IFeatureClassName m_InputFeatClassName = (IFeatureClassName)m_FCName;
                            IDatasetName m_InputDSName = (IDatasetName)m_FCName;
                            IFeatureDatasetName m_FeatDatasetName = (IFeatureDatasetName)m_FDatasetName;

                            if (m_FeatSel.SelectionSet.Count == 0)
                            {
                                m_featureConverter = new FeatureDataConverterClass();
                                m_InvObj = m_featureConverter.ConvertFeatureClass(m_InputFeatClassName, m_QF, m_FeatDatasetName, m_FeatClName, m_GeomDef, m_OutputFields, null, 0, 0);
                                frmTxt.Text = null;
                                frmExportCFPolygon.ActiveForm.Close();
                            }
                            else if (m_FeatSel.SelectionSet.Count != 0) //only export selected parcels
                            {
                                m_featureConverter2 = new FeatureDataConverterClass();
                                m_InvObj = m_featureConverter2.ConvertFeatureClass(m_InputDSName, m_QF, m_FeatSel.SelectionSet, m_FeatDatasetName, m_FeatClName, m_GeomDef, m_OutputFields, null, 0, 0);
                                frmTxt.Text = null;
                                frmExportCFPolygon.ActiveForm.Close();
                            }
                        }
                        else if (FStandAlone == true) //export to stand alone feature class
                        {

                            m_GeomDefEdit.GridCount_2  = 1;
                            m_GeomDefEdit.set_GridSize(0, 0);
                            m_GeomDefEdit.SpatialReference_2 = m_GeomDef.SpatialReference;
                                                       
                            m_FeatClName.ShapeType = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon;
                            m_DatasetName = (IDatasetName)m_FeatClName;
                            m_DatasetName.Name = featClassname;
                            m_DatasetName.WorkspaceName = m_WSName;
                                                       
                            m_QF = new QueryFilterClass();
                            IFeatureClassName m_InputFeatClassName = (IFeatureClassName)m_FCName;
                            IDatasetName m_InputDSName = (IDatasetName)m_FCName;

                            if (m_FeatSel.SelectionSet.Count == 0)
                            {
                                m_featureConverter = new FeatureDataConverterClass();
                                m_InvObj = m_featureConverter.ConvertFeatureClass(m_InputFeatClassName, m_QF, null, m_FeatClName, m_GeomDef, m_OutputFields, null, 0, 0);
                                frmTxt.Text = null;
                                frmExportCFPolygon.ActiveForm.Close();
                            }
                            else if (m_FeatSel.SelectionSet.Count != 0)
                            {
                                m_featureConverter2 = new FeatureDataConverterClass();
                                m_InvObj = m_featureConverter2.ConvertFeatureClass(m_InputDSName, m_QF, m_FeatSel.SelectionSet, null, m_FeatClName, m_GeomDef, m_OutputFields, null, 0, 0);
                                frmTxt.Text = null;
                                frmExportCFPolygon.ActiveForm.Close();
                            }
                        }
                                             
                    }
                }
            }
0 Kudos
CarlosOrtiz
Emerging Contributor
Thanks for both responses.  I will disect the code and use in my application.

Thanks again.

Carlos Ortiz
0 Kudos
CarlosOrtiz
Emerging Contributor
Thanks for the code snippets but it turns out it was me not seeing the obvious.  After looking in Sql Server I noticed that the tabular table associated with the Parcels was named "ParcelFabric_Parcels"  so I started to mess with my code and found that the code I use for getting a FeatureClass worked. I had tried "ParcelFabric" and "Parcels" both failing but adding them both together "ParcelFabric_Parcels" works.  This had been the stumbling block to get the remainder of my code to work (IFeatureCursor or IExporterOperation).  Attached is an image of the TOC from ArcMap as a reference.

For anyone interested the method was get an IFeatureWorkspace from your SDE then get the IFeatureClass from the IFeatureWorkspace.OpenFeatureClass(featureClassName).  From there you can do whatever you want.

Here is the code I used:

        public IFeatureClass openMaintSDEFeatureClass(string featureClassName)
        {
          IFeatureWorkspace pFWS = (IFeatureWorkspace)ConnectToTransactionalVersion("server",
                                                                                    "instance",
                                                                                    "user",
                                                                                    "password",                                                                                                                       "database",
                                                                                    "version");
          IFeatureClass pFC = pFWS.OpenFeatureClass(featureClassName);
          return pFC;
        }

        public static IWorkspace ConnectToTransactionalVersion(String server, String
            instance, String user, String password, String database, String version)
        {
          IPropertySet propertySet = new PropertySet();
          propertySet.SetProperty("SERVER", server);
          propertySet.SetProperty("INSTANCE", instance);
          propertySet.SetProperty("DATABASE", database);
          propertySet.SetProperty("USER", user);
          propertySet.SetProperty("PASSWORD", password);
          propertySet.SetProperty("VERSION", version);

          Type factoryType = Type.GetTypeFromProgID(
              "esriDataSourcesGDB.SdeWorkspaceFactory");
          IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance
              (factoryType);
          return workspaceFactory.Open(propertySet, 0);
        }
0 Kudos