Hi Ive sent this question before but it was unreadable
I saw your VPF snippet about reading VPF geometries on codehaus.
I just found out of Geotools And I can't say that I'm a java programmer only
a GIS engineer, but I copied
your snippet code for learning (hope it is ok). Never the less I had to
modify it because I can't import
org.geotools.data.DefaultFeatureResults;,
just can't find it.
My database is VMap level 0 euroasia
This is the code for now:
import java.io.File;
import org.geotools.data.DataStore;
import org.geotools.feature.FeatureCollection;
import org.geotools.feature.FeatureIterator;
import org.geotools.data.FeatureSource;
import org.geotools.feature.Feature;
import com.vividsolutions.jts.geom.Geometry;
public class VPFTest
{
public static void main( String[] args )
throws Exception
{
if ( args.length != 1 )
{
System.err.println( "Usage: java " + VPFTest.class.getName() + " <VPF
directory containing lht file>" );
System.exit( 1 );
}
DataStore ds = new org.geotools.data.vpf.VPFLibrary( new File( args[0] )
);
String[] types = ds.getTypeNames();
for ( int i = 0; i < types.length; i++ )
runThrough( ds, types[i] );
}
static void runThrough( DataStore ds, String feature )
throws Exception
{
FeatureIterator fi = null;
FeatureCollection fc =null;
FeatureSource fs = null;
try
{
fs = ds.getFeatureSource( feature );
fc = fs.getFeatures();
fi = fc.features();
while (fi.hasNext()) // here I'm getting the exception the second time
I enter runThrough()
{
Feature f = fi.next();
Geometry g = f.getDefaultGeometry();
if ( g == null )
System.out.println( "Default Geometry is null for: " + f );
else
System.out.println( "Default Geometry for: " + f );
}
}
finally
{
if(fi != null) fi.close();
}
}
}
And this is the output:
Default Geometry is null for: Feature[ id=923 , id=923 , f_code=BA010 ,
edg_id=923 , libref.lft_id=null , start_node=null , end_node=null ,
right_edge=null , left_edge=null , coordinates=null ]
Default Geometry is null for: Feature[ id=924 , id=924 , f_code=BA010 ,
edg_id=924 , libref.lft_id=null , start_node=null , end_node=null ,
right_edge=null , left_edge=null , coordinates=null ]
Default Geometry is null for: Feature[ id=925 , id=925 , f_code=BA010 ,
edg_id=925 , libref.lft_id=null , start_node=null , end_node=null ,
right_edge=null , left_edge=null , coordinates=null ]
ALL coordinates are null.
Then when program moves to the next featur type and enter runThrough fc, fs,
fi seems ok but fi.hasNext()
reports this:
java.io.IOException: The handle is invalid
at java.io.RandomAccessFile.length(Native Method)
at org.geotools.data.vpf.file.VPFFile.hasNext(VPFFile.java:492)
at
org.geotools.data.vpf.VPFFeatureReader.readNext(VPFFeatureReader.java:142)
at
org.geotools.data.vpf.VPFFeatureReader.hasNext(VPFFeatureReader.java:114)
at
org.geotools.data.ReTypeFeatureReader.hasNext(ReTypeFeatureReader.java:164)
at
org.geotools.data.store.FeatureReaderIterator.hasNext(FeatureReaderIterator.java:44)
at
org.geotools.feature.collection.DelegateFeatureIterator.hasNext(DelegateFeatureIterator.java:50)
at VPFTest.runThrough(VPFTest.java:99)
at VPFTest.main(VPFTest.java:83)
I would really like to be able to read the geometries for all features in a
VPF database, is it possible with geotools?
Paul Malm
--
View this message in context: http://www.nabble.com/VPF-tp20109965p20109965.html
Sent from the geotools-gt2-users mailing list archive at Nabble.com.
|