Predefined Readers > The Shapefile Reader > Classes for Reading the Shapefile Format
 
Classes for Reading the Shapefile Format
The following classes are used to read the Shapefile format:
*IlvShapeFileReader
This class is a subclass of IlvMapFeatureIterator and allows you to read .shp, .dbf, and .shx files. Since Shapefiles provide no information on the projection system used, this reader is not georeferenced. See the sections Feature Iterators and Loading Nongeoreferenced Files.
*IlvShapeSHPReader
This class is a subclass of IlvMapFeatureIterator. This reader only reads .shp files.
*IlvShapeDBFReader
This class only reads .dbf files.
*IlvShapeFileIndex
This class reads .shx files. You can find more information in the section The IlvShapeFileIndex Class.
*IlvShapeSpatialIndex
This class reads spatial index files (.idx files). You can find more information in the section The IlvShapeSpatialIndex Class.
IlvShapeFileReader
This reader reads the .shp file storing geometries and the .dbf file storing attributes simultaneously, and merges the information into a single IlvMapFeature object. The reader can also read an optional .shx file to provide random access to geometries.
It can be instantiated in one of the following ways:
*By specifying the name of the .dbf, .shp, and the optional .shx files.
*By specifying an IlvShapeDBFReader, an IlvShapeSHPReader, and an optional IlvShapeFileIndex object directly.
This is useful, for example, when using a derived IlvShapeSHPReader object.
In both cases, when the reader is created with the ability to read the .shx file, it provides random access to geometries through the getFeatureAt method.
This reader uses three specialized readers: IlvShapeSHPReader, IlvShapeDBFReader, and IlvShapeFileIndex. Its getNextFeature method merges the information generated by these specialized readers into a single map feature.
For an example, see the Shapefile sample at the following location:
<installdir>/samples/maps/shapefile
IlvShapeSHPReader
This reader only reads .shp files, but if it is created with both .shp and .shx files, this reader allows random acces to geometries.
The geometries stored in Shapefiles are not necessarily 2D objects. Each point that makes up a shape object can be associated with measurements, or with measurements and an elevation.
Measurements are stored in an attribute of type IlvAttributeArray.
The following are the shape types that are associated with measurements:
*POINTZ
*POLYLINEZ
*POLYGONZ
*MULTIPOINTZ
*POINTM
*POLYLINEM
*POLYGONM
*MULTIPOINTM
Elevations are stored in an attribute of type IlvAttributeArray.
The following are the shape types that are associated with measurements and elevations:
*POINTZ
*POLYLINEZ
*POLYGONZ
*MULTIPOINTZ
Since Rogue Wave Views Maps does not have a predefined geometry to represent shape objects of type MULTIPATCH, which are essentially used for 3D rendering, these are ignored. It is possible, however, to modify this behavior by subtyping the class IlvShapeSHPReader. Since shape objects are read in protected methods, modifying the reader to include new geometries requires minimal effort.
IlvShapeDBFReader
This reader is used exclusively for reading a file of the .dbf format. It can be used to iterate over a file as follows:
IlvShapeDBFReader* reader = new IlvShapeDBFReader("myFile.dbf");
IlvFeatureAttributeProperty* attributes = reader->getNextRecord();
while (attributes) {
// process attributes
...
attributes = reader->getNextRecord(...);
}
As the .dbf file associates attributes with the objects in the .shp in a sequential way, you can access map feature attributes directly by specifying their record number:
reader->readRecord(index, error);

Version 5.5.1
Copyright © 2012, Rogue Wave Software, Inc. All Rights Reserved.