Select to view content in your preferred language

Creating FeatureDataset in a FileGDB using Form  C# Code

992
3
05-31-2012 03:45 AM
TauhidulIslam
Emerging Contributor
Hello Everyone,
this is Tauhid from Bangladesh. I am a beginner in ArcGIS development with C#. Now i Am trying to create a featuredataset using ISpatialReferenceDialogBox in a fileGDB. but I am stuck with the code. Of my form the groupbox named as Frame1 which is contain the cmdDataSet button . the code is given Below:

private void cmdDataSet_Click(object sender, EventArgs e)
        {
            string strdatabasePath = "C:\\" + @txtProject.Text + "\\Survey\\Data_Table\\" + @txtDatabase.Text + @txtSub.Text;

            if (!Directory.Exists(strdatabasePath) == false)
            {
                MessageBox.Show("Destination Directory was not Found, Please Create the Directory First");
            }

            IWorkspaceFactory pWSF = new FileGDBWorkspaceFactoryClass();

            Boolean blsWorkspace = pWSF.IsWorkspace("C:\\" + @txtProject.Text + "\\Survey\\GeoDatabase\\" + @txtDatabase.Text + "\\" + @txtDatabase.Text +".gdb");
            if (blsWorkspace == true)
            {
                IWorkspace pWorkspace = pWSF.OpenFromFile("C:\\" + @txtProject.Text + "\\Survey\\GeoDatabase\\" + @txtDatabase.Text + "\\" + @txtDatabase.Text + ".gdb", 0);
                IFeatureWorkspace pfeatureWorkspace = (IFeatureWorkspace)pWorkspace;
                IEnumDatasetName pEnumDatasetName = pWorkspace.get_DatasetNames(esriDatasetType.esriDTFeatureDataset);
                IDatasetName pDatasetName = pEnumDatasetName.Next();

                string theDatasetName;
                int theValue;

                while (pDatasetName == null)
                {
                    theDatasetName = pDatasetName.Name;
                    if (theDatasetName == txtSub.Text)
                    {
                        theValue = 1;
                    }
                    pDatasetName = pEnumDatasetName.Next();
                }
                if (theValue == null)
                {
                    ISpatialReferenceDialog pSpaRef = new SpatialReferenceDialogClass();
                    ISpatialReference m_SpaRef1 = pSpaRef.DoModalCreate(true, true, true, Frame1.ActiveControl);
                    IFeatureDataset pfeatDataset;
                    while m_SpaRef1 == false
                    {
                        pfeatDataset = pfeatureWorkspace.CreateFeatureDataset(txtSub.Text, m_SpaRef1);
                        MessageBox.Show("FeatureDataset Created");
                    }
                    MessageBox.Show("No Spatial Reference Found, Feature Dataset was Not Created");
                }

                   

            }

        }


But its not working. It shows error in "ISpatialReference m_SpaRef1 = pSpaRef.DoModalCreate(true, true, true, Frame1.ActiveControl);" this part of code. Can Anyone please give me the solution? I tried to find the solution but can't fix it.


Tauhid
GIS Specialist
NERCA International Ltd
0 Kudos
3 Replies
JohnFritzen
Emerging Contributor
See Rich's reply on this thread:
http://forums.arcgis.com/threads/58800-Error-from-AccessWorkspaceFactory.Create

He references documentation on singleton objects.  This may be of help to you.
0 Kudos
TauhidulIslam
Emerging Contributor
Hello John,
Thanks for your help, but this wont help either.. My main problem is in the ISpatialReferenceDialog that I am using but it won't work.can you please help me on that part of the code?

ISpatialReferenceDialog pSpaRef = new SpatialReferenceDialogClass();
                    ISpatialReference m_SpaRef1 = pSpaRef.DoModalCreate(true, true, true, Frame1.ActiveControl());

here Activecontrol is not working so that the spatial reference dialogbox won't show up while I was trying to create the feature Dataset inside a fileGeoDatabase using a button click.

Tauhid
0 Kudos
SaurabhDasgupta
Deactivated User
Hello John,
Thanks for your help, but this wont help either.. My main problem is in the ISpatialReferenceDialog that I am using but it won't work.can you please help me on that part of the code?

ISpatialReferenceDialog pSpaRef = new SpatialReferenceDialogClass();
                    ISpatialReference m_SpaRef1 = pSpaRef.DoModalCreate(true, true, true, Frame1.ActiveControl());

here Activecontrol is not working so that the spatial reference dialogbox won't show up while I was trying to create the feature Dataset inside a fileGeoDatabase using a button click.

Tauhid


Hi Tauhid,
            Instead of using
ISpatialReferenceDialog pSpaRef = new SpatialReferenceDialogClass();
ISpatialReference m_SpaRef1 = pSpaRef.DoModalCreate(true, true, true, Frame1.ActiveControl());


you can use some thing like this

ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironment();
            ISpatialReferenceResolution spatialReferenceResolution = spatialReferenceFactory.CreateProjectedCoordinateSystem((int)esriSRProjCSType.esriSRProjCS_GDA1994MGA_50) as ISpatialReferenceResolution;
            spatialReferenceResolution.ConstructFromHorizon();
            ISpatialReferenceTolerance spatialReferenceTolerance = spatialReferenceResolution as ISpatialReferenceTolerance;
            spatialReferenceTolerance.SetDefaultXYTolerance();
            ISpatialReference fdsSR = spatialReferenceResolution as ISpatialReference;

            pfeatDataset = pfeatureWorkspace.CreateFeatureDataset(fdsName, fdsSR);


Hope this helps you.

~Saurabh
0 Kudos