I tried :
------------------------
GMLConfiguration configuration = new GMLConfiguration();
configuration.setupBindings().put(new QName("http://www.opengis.net/gml",
"AbstractFeatureCollectionType"), KeepOrderFeatureCollectionTypeBinding.class);
Parser parser = new Parser(configuration);
------------------------
Where "KeepOrderFeatureCollectionTypeBinding" is :
------------------------
public class KeepOrderFeatureCollectionTypeBinding extends
AbstractFeatureCollectionTypeBinding {
@Override
public Object parse(ElementInstance instance, Node node, Object value)
throws Exception {
SimpleFeatureCollection featureCollection =
(SimpleFeatureCollection)
node.getChildValue(FeatureCollection.class);
if (featureCollection == null) {
*featureCollection = createFeatureCollection();*
}
//<element maxOccurs="unbounded" minOccurs="0"
ref="gml:featureMember"/>
@SuppressWarnings("unchecked")
List<SimpleFeature> childValues =
node.getChildValues(SimpleFeature.class);
// example DefaultFeatureCollections or ListFeatureCollection
Collection<SimpleFeature> collection =
DataUtilities.collectionCast( featureCollection );
collection.addAll(childValues);
//<element minOccurs="0" ref="gml:featureMembers"/>
SimpleFeature[] featureMembers = (SimpleFeature[])
node.getChildValue(SimpleFeature[].class);
if (featureMembers != null) {
for (int i = 0; i < featureMembers.length; i++) {
collection.add(featureMembers[i]);
}
}
return featureCollection;
}
protected SimpleFeatureCollection *createFeatureCollection()* {
return new DefaultFeatureCollection(); // To change!
}
}
------------------------
My goal is to be able to change the SimpleFeatureCollection implementation used.
But it doesn't seem to work. For this QName, it is still /AbstractFeatureCollectionTypeBinding/ that
is used, not my /KeepOrderFeatureCollectionTypeBinding /class.
Any idea?
Julien
On 9/25/2014 7:58 AM, electrotype wrote:
Thanks for the reply Jody.
But how can I tell the parse() method to use one implementation instead of
another?
I see the Parser's constructor can take a Configuration object, which seems to use PicoContainer
and have a registerBindings() method... Is that the way to configure which implementation of the
FeatureCollection I want it to use?
Can you provide a small code example?
Julien
On 9/24/2014 4:01 PM, Jody Garnett wrote:
There are several FeatureCollection implementations for different purposes. The
DefaultFeatureCollection implementation is built around a TreeMap and sorts the contents by
FeatureId.
See the docs for alternatives:
-
http://docs.geotools.org/latest/userguide/library/main/collection.html#performance-options
Jody Garnett
On Wed, Sep 24, 2014 at 12:24 PM, electrotype <electrot...@gmail.com
<mailto:electrot...@gmail.com>> wrote:
I use org.geotools.xml.Parser#parse(...) to parse a GML based XML file.
This XML contains a
<gml:FeatureCollection> which contains multiple <gml:featureMember>.
The problem is that the resulting DefaultFeatureCollection doesn't seem to
keep the order in
which
the featureMembers are declared.
For example,
----------------------
Iterator<SimpleFeature> iterator = defaultFeatureCollection.iterator();
----------------------
... returns an Iterator with the elements in another order. I think
DefaultFeatureCollection
uses a
TreeMap to keep the elements, but sort them by internal ID, not by the
order they appear in
the XML.
Our application would require the order of the featureMembers to be kept...
Is there a way to
achieve this?
The only way I currently think of is to manually modify the generated
DefaultFeatureCollection after
GeoTools has parsed the XML file.
The highest version of GeoTools I can use is 11.2 since our application
uses Java 6.
Thanks in advance!
Julien
------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
GeoTools-GT2-Users mailing list
GeoTools-GT2-Users@lists.sourceforge.net
<mailto:GeoTools-GT2-Users@lists.sourceforge.net>
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
GeoTools-GT2-Users mailing list
GeoTools-GT2-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users