Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a featurecollection:

SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(dbFeatureType);
SimpleFeatureCollection collection = FeatureCollections.newCollection();
while (mifReader.hasNext()){      
  in = (SimpleFeatureImpl) mifReader.next();
  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");
      if(name.trim().equalsIgnoreCase(kadname.trim())){
        dbFeature.setAttribute("kadnum", string3);
      }
    }
    if (attrValue instanceof Geometry){
        idn++;
        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);

    }
    collection.add(dbFeature);
    }
}

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() 
{ 
    @Override
            public PropertyName getPropertyName() { return YourPropertyNameImpl("id") ; } 
    @Override
            public SortOrder getSortOrder() { return SortOrder.ASCENDING; }
});

But I don't understand what is YourPropertyNameImpl.

UPDATE

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) iterator.next();
        coll.add(feature);
        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
show 7 more comments

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.