I've had pretty good success with DbaseFileReader, but the javadoc is
out of date. Here's an example that should work (warning, I haven't
tried to compile this). The example assumes the first field has a
character data type and the second has a numeric data type:
FileInputStream fis = new FileInputStream( "yourfile.dbf" );
DbaseFileReader dbfReader = new DbaseFileReader(fis.getChannel(),
false, Charset.forName("ISO-8859-1"));
while ( dbfReader.hasNext() )
{
final Object[] fields = dbfReader.readEntry();
String field1 = (String) fields[0];
Integer field2 = (Integer) fields[1];
System.out.println("DBF field 1 value is: " + field1);
System.out.println("DBF field 2 value is: " + field2);
}
dbfReader.close();
fis.close();
-Larry
On Wed, Apr 14, 2010 at 9:25 AM, GeoSAN <[email protected]> wrote:
>
> Hello,
>
> As you are soon to realize, I am a complete n00b at Geotools still.
>
>
> I am working on a project to create 3D Models of a building structure using
> OpenGL. The building structural data is stored in shape files and I am using
> Geotools to read it and display using OpenGL(actually I am supposed to read
> the data and store it in a MySQL Spatial database, but thats another story).
>
> I managed all the seemingly difficult part like reading the various
> geometries using datastore->featuresource->collection->and-so-on and
> implemented the visualization also. But the data in the .shp file is
> completely 2Dimensional like a Top View or Floor Plan.
>
> The 3Dness is got by using a zFact and BaseHeight column in the .dbf file.
> Earlier I was reading the .dbf data using FeatureCollectionTableModel and
> the World was well. But recently I got new data whose .dbf file my old code
> seems unable to read (get a zero on the model.rowcount).
>
> Now my requirement is simple:
> Read data from the .dbf file
>
> A few thing I have figured after some painstaking hours:
> 1. The DataStore can manage all the info from all the component files of the
> shape format (.shp, .dbf, .prj etc)
> 2. The DbaseFileReader could help me. But it seems like overkill at the
> moment (especially in light of point no. 1). Also I couldn't figure how to
> use it. The example code in the API doc seems bugged.
> 3. The FeatureType object could be used to determine the type and number of
> the attributes of the .dbf file columns (right?). But I can't figure how to
> get the data X(
>
>
> I am guessing the answer is so simple that no one has bothered to talk about
> it on the WWW (atleast as much as is reachable by Google) or it cannot be
> done. I am rooting of the former and hoping some of you could help me.
>
> Just to make it clear, what I don't want to do is:
> 1. Display labels and stuff using SDL
> 2. Make a shapefile
>
> and all I want is:
> 1. Get the data stored in columns of the .dbf file
> 2. Supernatural Strength (but that goes in another forum)
>
> Thank you in advance!
> --
> View this message in context:
> http://n2.nabble.com/Read-data-from-dbf-file-tp4902284p4902284.html
> Sent from the geotools-gt2-users mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> Download Intel® Parallel Studio Eval
> Try the new software tools for yourself. Speed compiling, find bugs
> proactively, and fine-tune applications for parallel performance.
> See why Intel Parallel Studio got high marks during beta.
> http://p.sf.net/sfu/intel-sw-dev
> _______________________________________________
> Geotools-gt2-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users