On Wednesday 20 February 2008, Jody Garnett wrote: > Mauricio Pazos wrote: > > Hi list, I need a feature collection sorted by different attributes or > > properties alfanumeric (no geometry attributes). > > > > This was my first test (it uses a shape file as feature source) > > Sorting hsa been added to GeoTools in 2.3, the shapefile module > maintainer has only now moved from GeoTools 2.2 to trunk so there is a > really good > possibility that sorting is not implemented yet. However Jesse (in > monday's IRC) meeting was talking about some attribute index based code > that he was given (exactly what is needed for sorting). > > So why not head over to geotools-devel and let Jesse know you have a > real use case and can help with testing :-) Ok, I am coping this to geotools-devel and Jesse.
About the real use case, it is in uDig context (spatial operations plugin). I need sort different type of *feature source* before process it. Geotools provide the layer required to hide the persistence problem (interfaces and implementations), but now I need sort technique by alfanumeric attributes. I know shape file is an special case, but is is very popular. > > > DefaultQuery query = new DefaultQuery(schema.getTypeName(), filter, > > attrNames); > > sortProperties[0] = ..; > > query.setSortBy(sortProperties); > > > > FeatureCollection featureCollection = featureSource.getFeatures(query); > > This is the technique that is supposed to work; you may be the first > person to try it with shapefiles. :D fantastic! > > > It returns an empty collection. I debug it and I found the following : > > > > AbstractFeatureSource implements FeatureSource{ > > ... > > public FeatureColletion getFeatures(Query query){ > > ... > > FeatureCollection collection = new DefaultFeatureResults(this, > > query); if( collection.getDefaultGeometry() == null ){ <<<< this is > > true!!! return collection; // no geometry no reprojection needed } > > Yeah that does not make sense to me ... is there code after this test > that you was expected to run? > > > The collection.getDefaultGeometry == null condition is true because the > > DataFeatureCollection 's contract doesn't allow handle the default > > geometry. > > > > DataFeatureCollection > > > > public Geometry getDefaultGeometry() { > > return null; <<<< > > } > > public void setDefaultGeometry( Geometry geometry ) throws > > IllegalAttributeException { > > throw new IllegalAttributeException( "DefaultGeometry not > > supported" ); <<<<<< is not allowed > > } > > > > I tried other possibilities using SubFeatureList but I haven gotten > > success. > > I wrote some of the inital sorting for memory data store (using an in > memory list of feature Ids and random accesss to return features in a > required order). Good news!, I am thinking in similar solution, I could load feature's ids uning memory data store and then iterate .... > > > Then, What is the better approach to get an ordered feature collection? > > If you can use an SQL based datastore you will find they implement > sorting and have been tested. Yes, it is uDig then the catalogue could retrieve sql based or others > > > Is there any solution in geotool library? or Should I develop an ad hoc > > solution? > > Test and then share your ad hoc solutions :-) :) ok > > Jody -- Mauricio Pazos www.axios.es tel-:+34 94 441 63 84 ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Geotools-devel mailing list Geotools-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/geotools-devel