Dear Openmappers,
I am new to using shape files. I have some existing shape files of the
administration regions inside of nations (i.e. provinces or the
equivalents of states). I have tried using the ShpInputStream, and
DbfInputStream classes inside OM to read these files, and I am not
having much luck, since I am sure that I am going about things
incorrectly.
When I use the ShpInputStream methods I run out of memory on a 512 Mb
RAM machine with a Shape file of size ~100Kb. Probably some other bug
in my code... Here is a snippet for trying to read a .shp file and
determine the geographic coordinate vectors that make up its constituent
polygon regions. My end goal is to the get the actual (lat,lon) pairs
that make up the regions inside the polygons.
private void readShapeFile(String _filenameShp, String _filenameShx
) {
try {
File shapeFile = new File(_filenameShp);
FileInputStream instreamShp = new
FileInputStream(shapeFile);
shapeFile = null;
File indexFile = new File( _filenameShx );
FileInputStream instreamShx = new FileInputStream( indexFile
);
indexFile = null;
System.gc(); // silly attempts to free up memory here
ShpInputStream shpInstream = new
ShpInputStream(instreamShp);
ShxInputStream shxInstream = new
ShxInputStream(instreamShx);
int[][] indicies = shxInstream.getIndex();
EsriPolygonList esriPolyList = new EsriPolygonList();
// ***** this is where I run out of memory *******
esriPolyList = (EsriPolygonList)
shpInstream.getPolyGeometry(indicies, SHAPE_TYPE_POLYGON);
float[] extents;
for (int i = 0; i < esriPolyList.size(); i++) {
Debug.printf(3, "esriPolyList[ " + i + " ], type = " +
esriPolyList.getType());
extents = esriPolyList.getExtents();
for (int e = 0; e < extents.length; e++) {
Debug.printf(3, "extends[ " + e + " ] = " +
extents[e]);
}
}
When I try to use the DbfInputStream methods, and an existing dbf file,
I get an EndOfFileException. Here is the snippet for that, same goal as
above -- to get the actual (lat,lon) pairs that make up the polygon
regions in the .dbf file.
/**
* Read an input dbf file associated with Shape files. Relies upon
OpenMap DbfInputStream class.
* @param _filename the fully qualified path name of the file to
read in
*/
private void readDBFfile(String _filename) {
try {
File dbfFile = new File(_filename);
FileInputStream instream = new FileInputStream(dbfFile);
dbfinstream = new DbfInputStream(instream);
//LittleEndianInputStream ??
dbfinstream.readData();
// this is actually an ArrayList of ArrayLists
records = dbfinstream.getRecords();
} catch (FileNotFoundException e) {
Debug.printf(1, "MyDBFfileReader.readDBFfile(): file " +
_filename + " is not found" + e);
System.err.println("File not found");
} catch (EOFException e) {
Debug.printf(1, "MyDBFfileReader.readDBFfile(): end of file
problem " + _filename + e.getLocalizedMessage());
System.err.println("End of file problem");
} catch (Exception e) {
Debug.printf(1, "MyDBFfileReader.readDBFfile(): exception
thrown from DbfInputStream " + e);
}
}
I am probaly not going about this in the right way, and perhaps there
are easier ways to achieve what I am doing, I am open for any
suggestions and comments.
And the third problem I am having is that I load some shape files, using
a properties file as:
Shape file for administration areas of Afghanistan
afghan.class=com.bbn.openmap.layer.shape.ShapeLayer
afghan.prettyName=Afghanistan
afghan.shapeFile=E:/proj/tapMerge/data/shape/Afghanistan/AFG_ADM1.SHP
afghan.spatialIndex=E:/proj/tapMerge/data/shape/Afghanistan/AFG_ADM1.SHX
afghan.lineColor=ff404040
afghan.fillColor=ccffcc
#Shape file for administration areas of Algeria
algeria2.class=com.bbn.openmap.layer.shape.ShapeLayer
algeria2.prettyName=Algeria
algeria2.shapeFile=E:/proj/tapMerge/data/shape/Algeria/dza_adm2.shp
algeria2.spatialIndex=E:/proj/tapMerge/data/shape/Algeria/dza_adm2.shx
#Shape file for ecoregions
ecoregions.class=com.bbn.openmap.layer.shape.ShapeLayer
ecoregions.prettyName=eco regions
ecoregions.shapeFile=E:/GIS/ecoRegions/ecoregions.shp
ecoregions.spatialIndex=E:/GIS/ecoRegions/ecoregions.shx
And only part of the actual files are viewable on my OpenMap image, and
when I zoom in or out, some parts of the ShapeLayer disappear (I have
turned the other map layers off etc. to make sure nothing is covered
up.). Since this is my first time ever using shape files I am most
likely not going about things in the most efficient way.
Thank you for your help,
ed
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Ed MacKerrow
Theoretical Division, T-13, Complex Systems
Mail Stop - B213 Los Alamos National Laboratory
Los Alamos, NM 87545
(505) 665-3491 (office)
(505) 603-0352 (cell)
(505) 665 - 3003 (fax)
mackerrow@lanl.gov
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-- [To unsubscribe to this list send an email to "majdart@bbn.com" with the following text in the BODY of the message "unsubscribe openmap-users"]Received on Thu Dec 5 14:00:12 2002
This archive was generated by hypermail 2.1.8 : Thu May 12 2005 - 07:18:33 EDT