I wanted to create a ShapeFile from an InMemoryFeatureLayer. In this InMemoryFeatureLayer, it stores some data retrieved from different database tables, but these tables have the same data columns, for example they all have an ID column which stores a sequence number. When I create the ShapeFile, if the InMemoryFeatureLayer stores data from only one database table, everything works very well; but when the InMemoryFeatureLayer stores data from more than one database tables, I got following exception the program executes the "AddFeature(feature)" method:
"An item with the same key has already been added"
It seems that some features have the same id, and you can not add them to one feature layer. For example, the features ids from one data table may be “1”, “2”, “3”…, and the ids from other data table also could be “1”, “2”, “3”… So you should write the code like this:
I have no problem to add the data from different tables to the InMemoryFeatureLayer, when I added the data, I specified the key, and the key is guaranteed unique, it is a combination of two fields.
The problem is when I create ShapeFile from the InMemoryFeatureLayer
Yes, this is same as the InMemoryFeatureLayer. When you add a feature to a ShapeFileFeatureLayer, it will add the feature to a dictionary temporarily and the key is the feature’s id by default. So you need to specify the id of the feature to avoid duplicate ids.