Thanks Amy, good catch!
> I am just learning how to use GeoTools, and have been working with an 
> example file someone sent me. The file had some runtime issues, so I've 
> been rewriting it and in the process, found some documentation errors:
>
> FeatureResults.reader() suggests using FeatureCollections.features() 
> which doesn't exists. It should be FeatureCollection.features(), which 
> returns a FeatureIterator, not a FeatureReader as referred to in the 
> original example. With all this in mind, I rewrote the original example 
> to be:
>
>      public FeatureCollection myCollection() throws IOException {
>          FeatureCollection collection = FeatureCollections.newCollection();
>          FeatureIterator iterator = collection.features();
>          while (iterator.hasNext()) {
>              collection.add( iterator.next() );
>          }
>          return collection; 
>      }
>
> I believe this is correct, and will update files where necessary if you 
> concur.
>   
A couple of points to note, you need to close the iterator after use - 
here is my preferred implementation

FeatureCollection collection = FeatureCollections.newCollection();
FeatureIterator iterator = collection.iterator(); // I like to go normal 
java where possible
try {
     while( iterator.hasNext() ){
          collection.add( (Feature) iterator.next() );
     }
}
finally {
     collection.close( iterator );
}
> Best regards,
>   
Cheers!
Jody


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to