ilog.views.maps.format.shapefile
Class IlvShapeFileReader

java.lang.Object
  extended by ilog.views.maps.format.shapefile.IlvShapeFileReader
All Implemented Interfaces:
IlvLookAheadFeatureIterator, IlvMapFeatureIterator

public class IlvShapeFileReader
extends Object
implements IlvLookAheadFeatureIterator

This class can be used to read ESRI Arc/Info Shapefiles.
An ESRI shapefile consists of a main file (.shp extension) containing the geometries, an index file (.shx extension) allowing direct access to objects in the main file, and an attribute table (.dbf in dBASE format).
The following example shows how to load a Shapefile into an IlvManager.

   IlvMapLoader loader = new IlvMapLoader(manager);
   IlvShapeFileReader reader = new IlvShapeFileReader("file.shp", "file.dbf");
   IlvFeatureRenderer renderer = new IlvDefaultFeatureRenderer();
   loader.load(reader, renderer);
 

Since:
ILOG JViews 3.0

Constructor Summary
IlvShapeFileReader(IlvSHPReader shpReader, IlvDBFReader dbfReader)
          Creates an instance of IlvShapeFileReader that uses the specified specialized readers.
IlvShapeFileReader(IlvSHPReader shpReader, IlvDBFReader dbfReader, IlvShapeFileIndex shxReader)
          Creates an instance of IlvShapeFileReader that uses the specified specialized readers.
IlvShapeFileReader(String shapeFileName, String dbfFileName)
          Creates an instance of IlvShapeFileReader for the specified files.
IlvShapeFileReader(String shapeFileName, String dbfFileName, String shxFileName)
          Creates an instance of IlvShapeFileReader for the specified files.
IlvShapeFileReader(URL shapeURL, URL dbfURL)
          Creates an instance of IlvShapeFileReader for the specified URLs.
IlvShapeFileReader(URL shape, URL dbf, URL shx)
          Creates an instance of IlvShapeFileReader for the specified URL.
 
Method Summary
 void dispose()
          Releases the resources allocated to the reader.
 void finalize()
          Called by the Java Garbage Collector to release the resources allocated to the reader.
 IlvCoordinateSystem getCoordinateSystem()
          Returns the spatial reference system that describes the coordinate system of geometric coordinates of the map features.
 IlvDBFReader getDBFReader()
          Returns the reader of the .dbf file.
 IlvFeatureRenderer getDefaultFeatureRenderer()
          Returns the default feature renderer for this reader.
 IlvMapFeature getFeatureAt(int index)
          Returns the feature located at the specified index.
 IlvCoordinate getLowerRightCorner()
          Returns the lower-right corner of the bounding box that delimits the content of the .shp file.
 IlvMapFeature getNextFeature()
          Returns the next map feature read from the Shapefile.
 Object getNextFeatureId()
          Returns the ID of the next feature.
 int getNextFeatureIndex()
          Returns the index of the next feature that is read.
 IlvSHPReader getSHPReader()
          Returns the reader of the .shp file.
 IlvCoordinate getUpperLeftCorner()
          Returns the upper-left corner of the bounding box that delimits the content of the .shp file.
 boolean isGeoreferenced()
          Returns false unless the IlvSHPReader has been subclassed.
 boolean isLoadingAttributes()
          Specifies whether this reader is reading auxiliary attributes.
 void setCoordinateSystem(IlvCoordinateSystem cs)
          Sets the coordinate system for this reader.
 boolean skipNextFeature()
          Skips the next feature available from this feature iterator.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IlvShapeFileReader

public IlvShapeFileReader(String shapeFileName,
                          String dbfFileName)
                   throws IOException
Creates an instance of IlvShapeFileReader for the specified files.

Parameters:
shapeFileName - The name of the Shapefile (with a .shp or .SHP extension).
dbfFileName - The name of the attribute file (with a .dbf or .DBF extension).
Throws:
IOException

IlvShapeFileReader

public IlvShapeFileReader(String shapeFileName,
                          String dbfFileName,
                          String shxFileName)
                   throws IOException
Creates an instance of IlvShapeFileReader for the specified files. This constructor is the only one that allows direct access to all Shapefiles, using the .shx file to access graphic objects.

Parameters:
shapeFileName - The name of the Shapefile (with a .shp or .SHP extension).
dbfFileName - The name of the attribute file (with a .dbf or .DBF extension). If null, no attribute is read.
shxFileName - The name of the index file (with a .shx or .SHX extension).
Throws:
IOException
Since:
JViews 4.0

IlvShapeFileReader

public IlvShapeFileReader(URL shape,
                          URL dbf,
                          URL shx)
                   throws IOException
Creates an instance of IlvShapeFileReader for the specified URL. This constructor allows direct access to all Shapefiles, using the .shx file to access graphic objects.

Parameters:
shape - The name of the Shapefile (with a .shp or .SHP extension).
dbf - The name of the attribute file (with a .dbf or .DBF extension). If null, no attribute is read.
shx - The name of the index file (with a .shx or .SHX extension).
Throws:
IOException
Since:
JViews 7.5

IlvShapeFileReader

public IlvShapeFileReader(IlvSHPReader shpReader,
                          IlvDBFReader dbfReader)
                   throws IOException
Creates an instance of IlvShapeFileReader that uses the specified specialized readers.

Parameters:
shpReader - The reader for the .shp file.
dbfReader - The reader for the .dbf file.
Throws:
IOException

IlvShapeFileReader

public IlvShapeFileReader(IlvSHPReader shpReader,
                          IlvDBFReader dbfReader,
                          IlvShapeFileIndex shxReader)
                   throws IOException
Creates an instance of IlvShapeFileReader that uses the specified specialized readers.

Parameters:
shpReader - The reader for the .shp file.
dbfReader - The reader for the .dbf file.
shxReader - The reader for the .shx file.
Throws:
IOException
Since:
JViews 4.0

IlvShapeFileReader

public IlvShapeFileReader(URL shapeURL,
                          URL dbfURL)
                   throws IOException
Creates an instance of IlvShapeFileReader for the specified URLs.

Parameters:
shapeURL - The URL of the Shapefile.
dbfURL - The URL of the attribute file.
Throws:
IOException
Method Detail

getNextFeature

public IlvMapFeature getNextFeature()
                             throws IOException
Returns the next map feature read from the Shapefile. The returned map feature is volatile and might therefore be modified when the getNextFeature is called again.

Specified by:
getNextFeature in interface IlvMapFeatureIterator
Returns:
The IlvMapFeature read.
Throws:
IOException - if an error occurs while reading the data.

getFeatureAt

public IlvMapFeature getFeatureAt(int index)
                           throws IOException
Returns the feature located at the specified index. Note that this only works if this IlvShapeFileReader has been constructed with a .shx file.

Parameters:
index - The location of the feature.
Returns:
The IlvMapFeature read or null if an error occurs.
Throws:
IOException - if an error occurs.
UnsupportedOperationException - if this operation is not supported on this IlvShapeFileReader.
IllegalArgumentException - if there is no feature at the specified index.
Since:
JViews 4.0

getNextFeatureIndex

public int getNextFeatureIndex()
Returns the index of the next feature that is read. Note: This will return the index of the next feature, even if the end of file is reached.

Since:
JViews 4.0

getNextFeatureId

public Object getNextFeatureId()
                        throws IOException
Returns the ID of the next feature. For Shapefiles, IDs are created as java.lang.Integer.

Specified by:
getNextFeatureId in interface IlvLookAheadFeatureIterator
Returns:
An ID created using new java.lang.Integer(getNextFeatureIndex()).
Throws:
IOException
Since:
JViews 4.0

setCoordinateSystem

public void setCoordinateSystem(IlvCoordinateSystem cs)
Sets the coordinate system for this reader.

Since:
JViews 5.0

skipNextFeature

public boolean skipNextFeature()
                        throws IOException
Skips the next feature available from this feature iterator.

Specified by:
skipNextFeature in interface IlvLookAheadFeatureIterator
Returns:
true if the skipped feature is not the last feature. In JViews 4.0, the return type of this method was void.
Throws:
IOException
Since:
JViews 5.0

isLoadingAttributes

public boolean isLoadingAttributes()
Specifies whether this reader is reading auxiliary attributes.


isGeoreferenced

public boolean isGeoreferenced()
Returns false unless the IlvSHPReader has been subclassed.

Specified by:
isGeoreferenced in interface IlvMapFeatureIterator

getCoordinateSystem

public IlvCoordinateSystem getCoordinateSystem()
Returns the spatial reference system that describes the coordinate system of geometric coordinates of the map features.

Specified by:
getCoordinateSystem in interface IlvMapFeatureIterator
Returns:
The coordinate system, or null if the coordinate system is unknown.
Since:
JViews 5.0

getUpperLeftCorner

public IlvCoordinate getUpperLeftCorner()
Returns the upper-left corner of the bounding box that delimits the content of the .shp file.

Specified by:
getUpperLeftCorner in interface IlvMapFeatureIterator

getLowerRightCorner

public IlvCoordinate getLowerRightCorner()
Returns the lower-right corner of the bounding box that delimits the content of the .shp file.

Specified by:
getLowerRightCorner in interface IlvMapFeatureIterator

getDefaultFeatureRenderer

public IlvFeatureRenderer getDefaultFeatureRenderer()
Returns the default feature renderer for this reader.

Specified by:
getDefaultFeatureRenderer in interface IlvMapFeatureIterator

dispose

public void dispose()
Releases the resources allocated to the reader.

Specified by:
dispose in interface IlvMapFeatureIterator

getSHPReader

public IlvSHPReader getSHPReader()
Returns the reader of the .shp file. This reader should not be modified or used to read geometries or it might be left in an inconsistent state.


getDBFReader

public IlvDBFReader getDBFReader()
Returns the reader of the .dbf file. This reader should not be modified or used to read attributes or it might be left in an inconsistent state.


finalize

public void finalize()
Called by the Java Garbage Collector to release the resources allocated to the reader. If the dispose method has not been called, it releases the resources used by the reader.

Overrides:
finalize in class Object
See Also:
dispose()


Copyright © 1996-2007 ILOG S.A. All rights reserved.   Documentation homepage.