ThinkGeo.com    |     Documentation    |     Premium Support

Shapefile EditTools

Hi, Hope you can help again. I want to delete a feature in a shapefile. 


The shapefile is opened as ShapeFileReadWriteMode.ReadWrite and I get the following error: ""The process cannot access the file 'C:\Tmp.shp' because it is being used by another process."


I also get the error on the Rebuild: "Access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated."


 


             
Dim tmpLayer As MapSuite.Core.ShapeFileFeatureLayer             
tmpLayer = MapSuiteTest.MainForm.winformsMap1.FindFeatureLayer(shapefileName)
tmpLayer.Open()
tmpLayer.EditTools.BeginTransaction()
tmpLayer.EditTools.Delete("123")
tmpLayer.EditTools.CommitTransaction()
tmpLayer.Rebuild(filePath)
tmpLayer.Close()
 



 


Alta,
 
I think the exception is caused by multi thread mode, and when you want to delete a feature from a layer, the layer is using for rendering or something else, at this time, the relative shp file is locked, no other process can access it. So I want to verify with you about this thing. You need do some little testing and answer some questions.
 
First, instantiate your shape file layer and then delete a feature at the same block, don’t call Rebuild, is there any exceptions again? 
Dim tmpLayer As MapSuite.Core.ShapeFileFeatureLayer = New ShapeFileFeatureLayer(shapefile, ShapeFileReadWriteMode.ReadWrite)           
tmpLayer.Open()
tmpLayer.EditTools.BeginTransaction()
tmpLayer.EditTools.Delete(“123”)
tmpLayer.EditTools.CommitTransaction()
tmpLayer.Close()
 
Second, put Rebuild() method after Close() method, is there an y exceptions again?
tmpLayer.Open()
tmpLayer.EditTools.BeginTransaction()
tmpLayer.EditTools.Delete(“123”)
tmpLayer.EditTools.CommitTransaction()
tmpLayer.Close()
 
ShapeFileFeatureLayer.Rebuild(filePath)
 
If you still have problem, my suggestion is that you can check the TransactionResult which will be return from CommitTransaction, it contains many important things, such as transaction result status, failure reasons, etc…
 
Please let me know if you still can not solve your problem.
 
Thanks.
 
James

Thanks for the quick answer James. (You guys working night shift? ;) 
 Your code is working but I found out now that there is something else wrong. I get a "System.InvalidOperationException: Your input index is out of bound" error on the TransactionResult of the CommitTransaction . I am sure the feature exists in the shapefile, I get getFeatures.Count = 1 when I do: Dim getFeatures As Collection(Of MapSuite.Core.Feature) = tmpLayer.FeatureSource.GetFeaturesByColumnValue("ZONE_ID", oldZone) 
 and I have a ShapeFileFeatureLayer.BuildIndexFile(DATA_DIR & SHP_FILE) when I create the shapefile. 
 Any other suggestions, please?

Alta, 
  
 My company’s aim is solve your anything for anywhere anytime. So even you are not at American, you still can get the answer ASAP. 
  
 I have tested the API BuildIndexFile, it worked fine. So I think maybe your .shp file is special one which we don’t support that. 
  
 Can you send us your data and we can quickly find the reason to tell you? If your data is not small enough, you can contact support@thinkgeo.com by email. 
  
 Thanks 
  
 James 


Thanks James, I got good service every time. 
 I figured it out: I must use the feature.ID to delete and not the ColumnValue

Alta, 
  
 You’re welcom.  
  
 If you have more questions, just let me know any time. 
  
 James