Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a featurecollection:

SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(dbFeatureType);
SimpleFeatureCollection collection = FeatureCollections.newCollection();
while (mifReader.hasNext()){      
  in = (SimpleFeatureImpl);
  SimpleFeature dbFeature = featureBuilder.buildFeature(null);
  for(AttributeDescriptor ad : adList){
    String name = ad.getLocalName();
    Object attrValue;
    attrValue = in.getAttribute(name);
    if(attrValue instanceof String){
      String string3 = new String((attrValue.toString()).getBytes("ISO-8859-1"), "cp1251");
        dbFeature.setAttribute("kadnum", string3);
    if (attrValue instanceof Geometry){
        com.vividsolutions.jts.geom.Geometry geom = (Geometry) in.getAttribute(name);
        dbFeature.setAttribute("id", idn);
        System.out.println("after insrt="+idn);
        dbFeature.setAttribute("deleted", deleted);
        dbFeature.setAttribute("the_geom", geom);
        dbFeature.setAttribute("status_id", status_id);


Its all okay. But when I put this collection in Data Base i get a reversed items. So i want to sort or reverse items in this collection. But how to do this?
I try to use this:

        collection.sort( new SortBy() 
            public PropertyName getPropertyName() { return YourPropertyNameImpl("id") ; } 
            public SortOrder getSortOrder() { return SortOrder.ASCENDING; }

But I don't understand what is YourPropertyNameImpl.


Okey. I try to put features from my collection to another collection:

    Iterator iterator = null;
    int count;
    iterator = collection.iterator();
    while( iterator.hasNext()){
        SimpleFeature feature = (SimpleFeature);
        System.out.println("Coll= "+coll.features().next().getProperties("id"));

But get same result(. In this case i need to read collection from last element to first. Its possible?

share|improve this question
replace SortOrder.ASCENDING; with SortOrder.DESCENDING ? – iant Oct 24 '12 at 9:16
What its mean? Sorry im new in GDAL. – Kliver Max Oct 24 '12 at 9:19
I think that this is GeoTools not GDAL, but where you see the line with ASCENDING in it replace that word with DESCENDING and the collection will be sorted in the other order. – iant Oct 24 '12 at 9:22
Okey. Can you tell me about YourPropertyNameImpl("id") what its mean? I try to use SimpleFeatureImpl but cant get a PropertyName. – Kliver Max Oct 24 '12 at 9:26
can you add a link to where you found this code so I can see the context? – iant Oct 24 '12 at 9:38

Just to help anyone else who ends up here as I did recently! There is a bug in GeoTools that prevents DESCENDING working as a sort order. See this PR for the fix which will be applied shortly.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.