Delete a feature

737
4
09-08-2011 06:50 AM
JustinConklin
New Contributor
I am trying to delete a feature programmatically, and what seems easy is not working properly. 
I have tried several methods all result in the feature being deleted, but not the row in the table.  I then get a failed to draw because there is no shape associated with the row. I tried all three methods below inside and outside of an edit session with the same results. 

Thanks in advance

Justin

 

The feature was created with:

Dim pFeature As IFeature = pFeatureClass.CreateFeature
            pFeature.Shape = pPoint
pFeature.store


I have tried:

pCursor = pFC.Update(pQF, False)
        pFeature = pCursor.NextFeature
pCursor.DeleteFeature()

also tried:

pSelFeats.Search(Nothing, False, pCursor)
        Dim pFeature As IFeature = pCursor.NextFeature
        pFeature.Delete()

also tried:

pSelFeats.Search(Nothing, False, pCursor)
        Dim pFeature As IFeature = pCursor.NextFeature

Dim pRow As IRow = pFeature
        pRow.Delete()
0 Kudos
4 Replies
DuncanHornby
MVP Notable Contributor
Justin,

I'm surprised the pFeature.Delete did not work which suggests to me the source of your problem is something else, what format is your data store as? If it's ArcSDE then maybe some weird locking is going on?  I would try you code on a small sample of say a shapefile?

Duncan
0 Kudos
JustinConklin
New Contributor
Duncan,

Thanks for your reply.  I am doing this on a test data set stored as a shapefile.  I am accessing the feature class through the map as opposed to the providing the path.  I suppose a locking issue is possible.  I will investigate.  Thanks.

Could it be an issue with the feature not being created properly in the first place?
0 Kudos
DuncanHornby
MVP Notable Contributor
Justin,

As I understand it a Feature is nothing more than a row in a table where one of the fields just happens to hold a geometry rather than all fields being non-spatial data. So I don't see why you can't have a row (feature) where all values are set to NULL, this should still be a valid row in your table (featureclass). Anybody out there do correct me if I am wrong?

So you dataset is a "simple" shapefile and when you issue a delete is sets everything to NULL but does does not remove the row from the table? Maybe you could post up your code for us to see?

Duncan
0 Kudos
JustinConklin
New Contributor
Duncan,

When I delete the row the row (with attributes and Shape field) remain in tact.  In the directory there was an additional lock file being created that I still cannot explain, so I am going another route.  Thanks for the help.


Justin
0 Kudos