1

Create Feature and store to different FGDB I'm creating a feature and I want to store it to a specific geodatabase. At the moment I'm using feature.Store() but it's not storing it to where I want. How do I specify a location?

I want to store it to C:\College Stuff\Dissertation2009円 stuff\Geo\Geo\Full_3D.gdb

I've been told that if I am looking to store in a particular database I will need to open the feature class from that database.

I've looked at connecting to a geodatabase using this code

 Public Shared Function FileGdbWorkspaceFromPath(ByVal FGDB_WORKSPACE As String) As IWorkspace
 Dim factoryType As Type = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory")
 Dim workspaceFactory As IWorkspaceFactory = CType(Activator.CreateInstance(factoryType), IWorkspaceFactory)
 Return workspaceFactory.OpenFromFile(FGDB_WORKSPACE, 0)
End Function

This is my CreateFeature sub

 Public Sub CreateFeature(ByVal layername1 As String, ByVal x As Double, ByVal y As Double, ByVal FeatureClass1 As IFeatureClass)
 Dim cPoint As IPoint = New ESRI.ArcGIS.Geometry.Point
 ' To individually assign a value to the coordinates, use cPoint.X = x and cPoint.Y = y.
 cPoint.PutCoords(x, y)
 ' Ensure the feature class contains points.
 If FeatureClass1.ShapeType <> esriGeometryType.esriGeometryPoint Then
 Return
 End If
 ' Build the feature.
 Dim feature As IFeature = FeatureClass1.CreateFeature()
 feature.Shape = cPoint
 ' Commit the new feature to the geodatabase.
 feature.Store()
End Sub

To create the feature do I need to connect to the geodatabase in the CreateFeature sub? How do I do that? I'm modifying someone elses code and I am new to this so that's why I am very unsure

Here is the GetFeatureClass function, this where the CreateFeature gets the feature from. GetFeatureClass gets a feature class from the active map. The feature class is a single shapefile, I want it to get a feature class that is in the active map but in a geodatabase

Public Function GetFeatureClass(ByVal layername1 As String) As IFeatureClass
 Dim mxDocument As IMxDocument
 mxDocument = m_application.Document
 Dim map As IMap = mxDocument.FocusMap
 Dim check As Boolean = False
 Dim layerCounter As Integer
 Dim FeatureClass1 As IFeatureClass = Nothing
 Dim featureLayer As IFeatureLayer
 Dim currentLayer As ILayer
 For layerCounter = 0 To map.LayerCount - 1 Step layerCounter + 1
 currentLayer = map.Layer(layerCounter)
 If (TypeOf currentLayer Is IFeatureLayer) And (currentLayer.Name = layername1) Then
 featureLayer = currentLayer
 FeatureClass1 = featureLayer.FeatureClass
 check = True
 layerCounter = map.LayerCount
 End If
 Next
 If check = False Then
 MsgBox("cannot find InputStops layer")
 Return Nothing
 End If
 Return FeatureClass1
End Function
asked Aug 16, 2013 at 21:51
2
  • Looking at your code I would suspect that the FeatureClass you are bringing into function CreateFeature as a parameter is from the wrong geodatabase as this code looks OK to me. So you need to review the code that is getting a handle on that featureclass which is code you are not showing. Try dropping a messagebox displaying the alias name to confirm what you are passing in and then work back from that? Commented Aug 19, 2013 at 11:50
  • Sorry @Hornbydd yes I have a GetFeatureClass function that gets the feature class for the active map. At the moment the feature class is a single shapefile, however, my modification is that the feature class is in a feature dataset within a geodatabase. I added the GetFeatureClass function to my original post. How can I change this, or create a new one, that will get the feature class that I want within the dataset and geodatabase? Commented Aug 21, 2013 at 15:53

1 Answer 1

1

An easy way to get hold of a FeatureClass directly is this method. The FeatureDataset is WBD and the FeatureClass is WBDLine.

Public Sub GetFeatureclass()
 Dim pGPUtil As IGPUtilities2
 Set pGPUtil = New GPUtilities
 Dim pFeatureClass As IFeatureClass
 Set pFeatureClass = pGPUtil.OpenFeatureClassFromString("c:\scratch\nhdh_dc.gdb\WBD\WBDLine")
 Debug.Print pFeatureClass.FeatureCount(Nothing)
End Sub

There are other ways but if you know the full path then this is quick and easy.

answered Aug 21, 2013 at 16:14
3
  • Thanks, I haven't gotten a chance to try it yet. How do I call that in a main method? In 2my code, there is the main part where GetFeatureClass is called. It goes 'Dim FeatureClass1 As IFeatureClass = GetFeatureClass("layername)'. How would I replicate that with your method? Commented Aug 21, 2013 at 21:33
  • When calling GetFeatureClass() how do I get set it equal to a variable. I've tried Dim feature1 As IFeatureClass = GetfeatureClass() but it does not return a variable. Commented Aug 22, 2013 at 10:23
  • My code example is a very simple procedure to show you how to use gputilities. You want to convert it into a function or place the code directly into your code. If you do not know how to create a function then you need to read up on that subject as that is basic programming which you must understand first. Commented Aug 22, 2013 at 10:53

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.