Keeping the FID order when creating a shapefile

Description

The improvement consists in creating shapefiles according to the FID order as defined in the FeatureCollection the user wants to save.
Therefore in the regular order for ListFeatureCollection or following a map tree index for MemoryFeatureCollection.

Here is Jody's answer on the geotools mailing list:
Internally (until you hit commit) the features are held in memory in a TransactionStateDiff; and then they are written out when commit() is called. What is the bet that that data structure uses a HashMap internally; I think if we change it to use a ListMap then the functionality you wanted would be preserved?

Here is the variable:

/**

  • Map of differences by typeName.
    *
    * <p>
    * Differences are stored as a Map of Feature by fid, and are reset during
    * a commit() or rollback().
    * </p>
    */
    Map typeNameDiff = new HashMap();

Looking at the code a bit more I am updating that to be:

As for Diff?

public class Diff{
private final Map modifiedFeatures;
private final Map addedFeatures;
And yes they are set to a form of HashMap:

public Diff( )
{
modifiedFeatures=new ConcurrentHashMap();
addedFeatures=new ConcurrentHashMap();
modified2=Collections.unmodifiableMap(modifiedFeatures);
added=Collections.unmodifiableMap(addedFeatures);
spatialIndex=new Quadtree();
mutex=this;
}

Environment

None

Activity

Show:
codehaus
April 10, 2015, 2:51 PM

CodeHaus Comment From: jgarnett - Time: Thu, 26 May 2011 17:21:42 -0500
---------------------
Committed as of -r37326

codehaus
April 10, 2015, 2:51 PM

CodeHaus Comment From: egrosso - Time: Thu, 26 May 2011 10:52:59 -0500
---------------------
The patch works for me locally too. Thanks a lot Jody.

codehaus
April 10, 2015, 2:51 PM

CodeHaus Comment From: jgarnett - Time: Thu, 26 May 2011 09:03:55 -0500
---------------------
So patch works for me locally; can I ask for a review.

codehaus
April 10, 2015, 2:51 PM

CodeHaus Comment From: jgarnett - Time: Thu, 26 May 2011 09:03:00 -0500
---------------------
Patch available; used a CopyOnWriteList to keep track of order.

codehaus
April 10, 2015, 2:51 PM

CodeHaus Comment From: jgarnett - Time: Thu, 26 May 2011 08:00:44 -0500
---------------------
So the quick fix is to make sure that the TransactionStateDiff applies the changes in the order they were supplied; the map keeping the changes is a form of HashMap - troubling a ConncurrentHashMap.

So with a bit of help from Andrea we tracked the changed down to Jesse; but the comment was vague. So rather than replace ConncurrentHashMap I am thinking of supplementing it with a List<String> which we can use when writing the contents out.

This is however a "deep" change so testing and code review will be needed.

Fixed

Assignee

Unassigned

Reporter

codehaus

Triage

None

Components

Fix versions

Affects versions

Priority

Low