uDig 1.2.1 is using the latest GeoTools; which from your testing appears more 
capable!
-- 
Jody Garnett

On Wednesday, 16 March 2011 at 8:45 AM, Alessandro Ferrucci wrote: 
> Hello,
> I have a question:
> 
> I'm using geotools 2.6.5 to read a shapefile, code is below:
> 
> Map map = new HashMap();
>  map.put("url", shpfilef.toURI().toURL());
>  DataStore store = DataStoreFinder.getDataStore(map);
>  String[] typeNames = store.getTypeNames();
>  String typeName = typeNames[0];
>  FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = 
> store.getFeatureSource(typeName);
>  FeatureCollection<SimpleFeatureType, SimpleFeature> collection = 
> featureSource.getFeatures();
>  FeatureIterator<SimpleFeature> iterator = collection.features();
>  int numfeatures = 0;
>  while (iterator.hasNext()) {
>  numfeatures++;
>  SimpleFeature feature = iterator.next();
>  int a= Integer.parseInt((String) feature.getAttribute(1));
>  int b= Integer.parseInt((String) feature.getAttribute(2));
>  int c= Integer.parseInt((String) feature.getAttribute(3));
>  Geometry geom = (Geometry) feature.getDefaultGeometry();
>  }
>  System.out.println("num features: " + numfeatures);
> 
> On certain shapefiles I get the following error 
> 
> Mar 15, 2011 6:37:43 PM 
> org.geotools.data.shapefile.indexed.IndexedShapefileDataStore queryQuadTree
> SEVERE: null
> java.nio.BufferUnderflowException
>  at java.nio.Buffer.nextGetIndex(Buffer.java:480)
>  at java.nio.DirectByteBuffer.getDouble(DirectByteBuffer.java:902)
>  at 
> org.geotools.data.shapefile.shp.PolygonHandler.readCoordinates(PolygonHandler.java:234)
>  at 
> org.geotools.data.shapefile.shp.PolygonHandler.read(PolygonHandler.java:147)
>  at 
> org.geotools.data.shapefile.shp.ShapefileReader$Record.shape(ShapefileReader.java:109)
>  at 
> org.geotools.data.shapefile.ShapefileAttributeReader.next(ShapefileAttributeReader.java:154)
>  at 
> org.geotools.data.shapefile.indexed.IndexedShapefileAttributeReader.next(IndexedShapefileAttributeReader.java:122)
>  at org.geotools.data.FIDFeatureReader.next(FIDFeatureReader.java:98)
>  at org.geotools.data.FIDFeatureReader.next(FIDFeatureReader.java:55)
>  at 
> org.geotools.data.store.FeatureReaderIterator.next(FeatureReaderIterator.java:71)
>  at 
> org.geotools.data.store.FeatureReaderIterator.next(FeatureReaderIterator.java:41)
>  at 
> org.geotools.feature.collection.DelegateFeatureIterator.next(DelegateFeatureIterator.java:58)
>  at Main.main(Main.java:42)
> 
> I understand this to be possibly the cause of a slightly corrupted shapefile? 
>  However if I then add the shapefile that caused the above error, to uDig 
> (version 1.2.1) uDig displays it without any problems.
> 
> another weird thing, is that if I tell uDig to export this layer to a new 
> shapefile (essentially creating a copy of the shapefile).
> 
> then the code I have above does not bomb out on that copy of the shapefile 
> anymore (and the number of features it reads is the same as that of uDig, so 
> I  know I'm getting all the features).
> 
> so it seems like uDig is FIXING the shapefile... but how could uDig read the 
> shapefile and my code above NOT read the shapefile, since they are both 
> essentially using the exact same code base?  Are there more  checks I need to 
> put in place that uDig performs?
>  Thanks,
> -- 
> Signed,
> Alessandro Ferrucci
> ------------------------------------------------------------------------------
> Colocation vs. Managed Hosting
> A question and answer guide to determining the best fit
> for your organization - today and in the future.
> http://p.sf.net/sfu/internap-sfd2d
> _______________________________________________
> Geotools-gt2-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
> 
------------------------------------------------------------------------------
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to