[udig-devel] Troubles using FeatureWriter

Jesse Eichar jeichar at refractions.net
Tue Aug 8 07:34:42 PDT 2006


Try deleting the .fix file and see if that helps.  It is possible  
that the fix file has become corrupt and needs to be re-indexed.  If  
that works please report a bug with this email as the comments.

Cheers,
Jesse

On 8-Aug-06, at 12:28 AM, Damjan Šavko wrote:

> Hello, I've been having a lot of troubles trying to write to a  
> shapefile. I've done it before but it always worked and now I don't  
> know what I'm doing wrong.
> This is my piece of code:
>
> try {
>
>             FilterFactory filterFactory =  
> FilterFactoryFinder.createFilterFactory ();
>             CompareFilter filter = filterFactory.createCompareFilter 
> (FilterType.COMPARE_EQUALS);
>             filter.addLeftValue 
> (filterFactory.createAttributeExpression(...........));
>             filter.addRightValue 
> (filterFactory.createLiteralExpression (feature.getAttribute 
> (.....................)));
>
>             Transaction transaction = new DefaultTransaction();
>             FeatureWriter fw = fs.getDataStore().getFeatureWriter 
> (fs.getSchema().getTypeName(),filter, transaction);
>
>             try {
>
>                 while(fw.hasNext()) {
>
>                     Feature changedFeature = fw.next();
>                     changedFeature.setAttribute  
> (..........., ..............);
>
>                     fw.write ();
>                 }
>
>                 fw.close();
>                 transaction.commit();
>
>
>             }
>             catch (Exception e) {
>                 transaction.rollback();
>             }
>             finally {
>                 fw.close();
>                 transaction.close();
>             }
>
>         } catch (IOException ioe) {
>             e.printStackTrace();
>         }
>
>
>  The error I get is:
>
> java.io.IOException: Shp has extra record
>     at org.geotools.data.shapefile.indexed.IndexedShapefileDataStore 
> $Reader.hasNext(IndexedShapefileDataStore.java:1204)
>     at org.geotools.data.FIDFeatureReader.hasNext  
> (FIDFeatureReader.java:139)
>     at org.geotools.data.FilteringFeatureReader.hasNext 
> (FilteringFeatureReader.java:118)
>     at org.geotools.data.DiffFeatureReader.hasNext 
> (DiffFeatureReader.java:115)
>     at org.geotools.data.DiffFeatureWriter.hasNext  
> (DiffFeatureWriter.java:206)
>     at org.geotools.data.InProcessLockingManager$1.hasNext 
> (InProcessLockingManager.java:338)
>     at org.geotools.data.FilteringFeatureWriter.hasNext 
> (FilteringFeatureWriter.java:134)
>     at si.triport.udig.modal.Split.test(Split.java: 
> 997)..............................
>
> The problem seems to be laying in the method hasNext().  At the end  
> of the loop when it should return false it just breaks down.
> I tried to change the iterator by using a feature iterator:
>
> FeatureCollection fc = fs.getFeatures(filter);
> FeatureIterator fi = fc.features();
>
>             try {
>
>                 while(fi.hasNext ()) {
>
>                     Feature f = fi.next();
>                     Feature changedFeature = fw.next();
>                    ........................................
>                     fw.write();
>                 }
>
>                 fi.close();
>                 fw.close();
>                 transaction.commit();     ....
>
> But the error remained the same except that it was fired from  
> transaction.commit() and not hasNext()
>
>
> java.io.IOException : Shp has extra record
>     at org.geotools.data.shapefile.indexed.IndexedShapefileDataStore 
> $Reader.hasNext(IndexedShapefileDataStore.java:1204)
>     at org.geotools.data.shapefile.indexed.IndexedShapefileDataStore 
> $Writer.close (IndexedShapefileDataStore.java:1509)
>     at org.geotools.data.TransactionStateDiff.applyDiff 
> (TransactionStateDiff.java:251)
>     at org.geotools.data.TransactionStateDiff.commit 
> (TransactionStateDiff.java:137)
>     at org.geotools.data.DefaultTransaction.commit 
> (DefaultTransaction.java:176)
>     at si.triport.udig.modal.Split.test(Split.java: 
> 1011)..........................
>
> Can anybody tell me what I'm doing wrong?
>
> Damjan Šavko
>
>
> _______________________________________________
> User-friendly Desktop Internet GIS (uDig)
> http://udig.refractions.net
> http://lists.refractions.net/mailman/listinfo/udig-devel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.refractions.net/pipermail/udig-devel/attachments/20060808/f9d0d4fd/attachment.html


More information about the udig-devel mailing list