i Want to add a point feature to my feature class. an i want to enter the coordinates manually.
here is what i am trying to do
pworkspaceedit = pFeatureWorkspace
pworkspaceedit.StartEditing(True)
pworkspaceedit.StartEditOperation()
Dim point As IPoint = New Point
Dim geometry As IGeometry
point.X = 100
point.Y = 100
geometry = point
pfeature = pFeatureClass.CreateFeature()
pfeature.Shape = geometry
MsgBox(pFeatureClass.FeatureCount(Nothing))
pworkspaceedit.StopEditOperation()
pworkspaceedit.StopEditing(True)
i have searched and the results are for copying from one feature class to another using icursor, creating lines from points, but havent found one for creating a point feature. all suggestions are welcome
there is no error in the code, a new empty feature is also created, but it has no attributes, MsgBox(pFeatureClass.FeatureCount(Nothing)) this i am using to display the no. of features after its created
1 Answer 1
You're missing one step. You need to store the geometry to write it to the feature class. There are various ways to do this, but the easiest way in your situation is to invoke the IFeature.Store() method. Here's some other stuff:
I assume your pFeature is an IFeature, but just to be sure we'll explicity declare it.
From documentation, point X and point Y properties are get/set, so the way you are setting your coordinates looks fine, but just for kicks lets use the method that was designed to set coordinates: IPoint.PutCoords().
Finally, you should be able to directly store an IPoint in the shape property of IFeature without having to move it to an IGeometry.
Try this:
pworkspaceedit = pFeatureWorkspace
pworkspaceedit.StartEditing(True)
pworkspaceedit.StartEditOperation()
Dim point As IPoint = New Point
point.PutCoords(100, 100)
Dim pfeature As IFeature = pFeatureClass.CreateFeature()
pfeature.Shape = point
feature.Store()
MsgBox(pFeatureClass.FeatureCount(Nothing))
pworkspaceedit.StopEditOperation()
pworkspaceedit.StopEditing(True)