VPF reader
----------

                 Key: GEOT-2094
                 URL: http://jira.codehaus.org/browse/GEOT-2094
             Project: GeoTools
          Issue Type: Test
          Components: data vpf
    Affects Versions: 2.4.5
         Environment: WinXP
            Reporter: Paul Malm


Hi, I'm sorry if this is not the right forum for user questions.
I saw a 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 the 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 get exceptions the second round
        {
                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


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Geotools-devel mailing list
Geotools-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to