ThinkGeo.com    |     Documentation    |     Premium Support

Cannot insert items into an STR packed R-tree after it has been built

Hello,


I'm encoutering a problem while using Transactions for InMemoryLayers.

My program adds and removes geometries in differents InMemoryLayer. The layer I use is open, the a transaction is begun, then my objects are added with the EditTools methods, then the transaction is commited, and then the layer is closed.


Not always, but I get often the following exception :


Cannot insert items into an STR packed R-tree after it has been built.


   bei GisSharpBlog.NetTopologySuite.Utilities.Assert.IsTrue(Boolean assertion, String message)

   bei GisSharpBlog.NetTopologySuite.Index.Strtree.AbstractSTRtree.Insert(Object bounds, Object item)

   bei GisSharpBlog.NetTopologySuite.Index.Strtree.STRtree.Insert(IEnvelope itemEnv, Object item)

   bei ThinkGeo.MapSuite.Core.InMemoryFeatureSource.BuildIndex()

   bei ThinkGeo.MapSuite.Core.InMemoryFeatureSource.CommitTransactionCore(TransactionBuffer transactions)

   bei ThinkGeo.MapSuite.Core.FeatureSource.CommitTransaction()

   bei ThinkGeo.MapSuite.Core.EditTools.CommitTransaction()

   bei CadRz.Kuba.Framework.Presentation.Win.Gis.LayerExtention.CommitTransaction(InMemoryFeatureLayer layer) in C:\projects\Kuba50\Implementation\Src\KubaFrameworkPresentationWin\Gis\LayerExtention.cs:Zeile 74.


I traced my program with output in order to be sure that the order of the Open() BeginTransaction() CommitTransaction() and Close() are correct, and it is correct.


I'm using the version 3.1.299, and the version numberof NetTopologySuite.dll is 1.7.3.31740.


Unfortunately I don't understand the error message, so could you please advise me ?


Thanks,

Guillaume.



Guillaume, 
  
 Inside the method InMemoryFeature.CommitTransaction, we create a new Rtree index object and insert the records into it. I am not sure why it throws that exception as by checking the code, records will not be inserted to an existed rtree object. Are you using multi-threads, could you provide a sample to help us recreate this issue? 
  
 Also here by the way, besides BeginTransaction/CommitTransaction, you can edit an InMemoryFeatureLayer in a simpler way by directly using its property InternalFeatures.  
 
            InMemoryFeatureLayer a = new InMemoryFeatureLayer();
            a.InternalFeatures.Add(new Feature(1, 1));
            a.BuildIndex();
 
 Every time the records are updated, you need to call BuildIndex() to update the index. However if you do not have many records in the layer, you even do not need an index.  
  
 If you are using multi-threads, you should be careful for both ways to make sure there is no threading conflicting on editing. 
  
 Thanks, 
  
 Ben 
  
  


Hello Ben, 
  
 Thanks for your answer, 
  
 I have a multithreaded application, because I wanted the data to be loaded asynchron. But normally the Add and Remve are done only by the main thread. 
 I will check this once more. 
  
 I’ll keep you informed. 
 Thanks, 
 Guillaume.

Ok, we are waiting for your feedback on this issue. Thank you.

Hello, 
  
 I think that I endly found my Problem. 
 I had an event in my code that was called 2 times. 
 Therefore my handler was executed 2 times. 
  
 Now it seems to work good. I don’t have any more exception.  
  
 What I don’t understand is that my handler makes a BeginTransation, insert, and then a CommitTransaction, and was explicitly called with a Dispatcher.Invoke, to be sure that it was executed in the main thread.  
 Calling this handler 1 time makes no problem, but calling it 2 times throw this exception. However a first commitTransaction was already made when the first execution of the handler has ended, and a new BeginTransaction was made when the execution of te second begin.  
 theoretically, this should work, doesn’t it ? 
  
 Thanks, 
 Guillaume. 
  


Guillaume, 
  
 Could you please send us a simple sample helping us to recreate this issue?  
  
 Thanks, 
  
 Ben