Class AbstractShapeFileReader<E>
- java.lang.Object
-
- org.arakhne.afc.io.shape.AbstractCommonShapeFileReader<E>
-
- org.arakhne.afc.io.shape.AbstractShapeFileReader<E>
-
- Type Parameters:
E
- is the type of element in the shape file.
- All Implemented Interfaces:
AutoCloseable
,Iterable<E>
- Direct Known Subclasses:
GISShapeFileReader
,ShapeFileReader
public abstract class AbstractShapeFileReader<E> extends AbstractCommonShapeFileReader<E>
This class is a shape file reader.To have a lower memory foot-print, call
AbstractCommonShapeFileReader.disableSeek()
. Indeed, the seek feature forces this reader to maintain a buffer of all the file content.The
ShapeFileIndexReader
, passed as parameter of the constructors, is mandatory to seek.The specification of the ESRI Shape file format is described in the July 98 specification document.
- Since:
- 14.0
- Version:
- 17.0 2020-01-04 14:41:52
- Author:
- Stéphane GALLAND, Olivier LAMOTTE
- Maven Group Id:
- org.arakhne.afc.advanced
- Maven Artifact Id:
- shapefile
-
-
Field Summary
Fields Modifier and Type Field Description static double
DEFAULT_FUSION_DISTANCE
Default distance under which a reader considers two points as too nearest (in meters).-
Fields inherited from class org.arakhne.afc.io.shape.AbstractCommonShapeFileReader
BLOCK_SIZE, expectedShapeType, fileSize, maxm, maxx, maxy, maxz, minm, minx, miny, minz
-
-
Constructor Summary
Constructors Constructor Description AbstractShapeFileReader(File file, DBaseFileReader dbase_importer, ShapeFileIndexReader shxReader)
Constructor.AbstractShapeFileReader(InputStream inputStream, DBaseFileReader dbase_importer, ShapeFileIndexReader shxReader)
Constructor.AbstractShapeFileReader(URL inputStream, DBaseFileReader dbase_importer, ShapeFileIndexReader shxReader)
Constructor.AbstractShapeFileReader(ReadableByteChannel inputStream, DBaseFileReader dbase_importer, ShapeFileIndexReader shxReader)
Constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
close()
Close the stream.protected abstract AttributeCollection
createAttributeCollection(int elementIndex)
Create an attribute provider which will be used by a new element.protected abstract E
createMultiPatch(AttributeCollection provider, int shapeIndex, int[] parts, ShapeMultiPatchType[] partTypes, ESRIPoint[] points)
Create a multipatch.protected abstract E
createMultiPoint(AttributeCollection provider, int shapeIndex, ESRIPoint[] points, boolean hasZ)
Create a multipoint.protected abstract E
createPoint(AttributeCollection provider, int shape_index, ESRIPoint point)
Create a point instance.protected abstract E
createPolygon(AttributeCollection provider, int shapeIndex, int[] parts, ESRIPoint[] points, boolean hasZ)
Create a polygon.protected abstract E
createPolyline(AttributeCollection provider, int shapeIndex, int[] parts, ESRIPoint[] points, boolean hasZ)
Create a polyline.boolean
isSeekEnabled()
Replies if the seek feature is enabled.protected boolean
postAttributeReadingStage(E element_representation)
Called just after the dBase attributes was red.protected void
postHeaderReadingStage()
Called just after the header was read.protected boolean
postShapeReadingStage(E element_representation)
Called just after the shape was red but before the attributes were retreived.protected abstract void
putAttributeIn(E element, String attributeName, AttributeValue value)
Invoked to put an attribute in the element.protected E
readRecord(int recordIndex)
Read a record according to its type.void
seek(int recordIndex)
Move the reading head at the specified record index.-
Methods inherited from class org.arakhne.afc.io.shape.AbstractCommonShapeFileReader
disableSeek, ensureAvailableBytes, getBoundsFromHeader, getFileReadingPosition, getFileSize, getShapeElementType, getTaskProgression, isHeaderRead, iterator, iterator, iterator, iterator, postReadingStage, postRecordReadingStage, preReadingStage, read, readBEDouble, readBEInt, readHeader, readLEDouble, readLEInt, setReadingPosition, setTaskProgression, skipBytes
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Field Detail
-
DEFAULT_FUSION_DISTANCE
public static final double DEFAULT_FUSION_DISTANCE
Default distance under which a reader considers two points as too nearest (in meters).- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AbstractShapeFileReader
public AbstractShapeFileReader(ReadableByteChannel inputStream, DBaseFileReader dbase_importer, ShapeFileIndexReader shxReader)
Constructor.- Parameters:
inputStream
- is the stream to readdbase_importer
- is the dBase reader to use to read the attribute's values.shxReader
- is the shape file index to reader.
-
AbstractShapeFileReader
public AbstractShapeFileReader(InputStream inputStream, DBaseFileReader dbase_importer, ShapeFileIndexReader shxReader)
Constructor.- Parameters:
inputStream
- is the stream to readdbase_importer
- is the dBase reader to use to read the attribute's values.shxReader
- is the shape file index to reader.
-
AbstractShapeFileReader
public AbstractShapeFileReader(File file, DBaseFileReader dbase_importer, ShapeFileIndexReader shxReader) throws IOException
Constructor.- Parameters:
file
- is the file to readdbase_importer
- is the dBase reader to use to read the attribute's values.shxReader
- is the shape file index to reader.- Throws:
IOException
- in case of error.
-
AbstractShapeFileReader
public AbstractShapeFileReader(URL inputStream, DBaseFileReader dbase_importer, ShapeFileIndexReader shxReader) throws IOException
Constructor.- Parameters:
inputStream
- is the stream to readdbase_importer
- is the dBase reader to use to read the attribute's values.shxReader
- is the shape file index to reader.- Throws:
IOException
- in case of error.
-
-
Method Detail
-
postHeaderReadingStage
protected void postHeaderReadingStage() throws IOException
Description copied from class:AbstractCommonShapeFileReader
Called just after the header was read.- Overrides:
postHeaderReadingStage
in classAbstractCommonShapeFileReader<E>
- Throws:
IOException
- in case of error.
-
close
public void close() throws IOException
Description copied from class:AbstractCommonShapeFileReader
Close the stream.- Specified by:
close
in interfaceAutoCloseable
- Overrides:
close
in classAbstractCommonShapeFileReader<E>
- Throws:
IOException
- in case of error.
-
readRecord
protected E readRecord(int recordIndex) throws EOFException, IOException
Description copied from class:AbstractCommonShapeFileReader
Read a record according to its type.- Specified by:
readRecord
in classAbstractCommonShapeFileReader<E>
- Parameters:
recordIndex
- is the index of the read record.- Returns:
- the element extracted from the record
- Throws:
EOFException
- if EOF is reach to early.IOException
- in case of error.
-
postAttributeReadingStage
protected boolean postAttributeReadingStage(E element_representation) throws IOException
Called just after the dBase attributes was red.- Parameters:
element_representation
- is the value returned by the reading function.- Returns:
true
if the object is assumed to be valid (ie. it will be replies by the reading function), otherwisefalse
.- Throws:
IOException
- in case of error.
-
postShapeReadingStage
protected boolean postShapeReadingStage(E element_representation) throws IOException
Called just after the shape was red but before the attributes were retreived.- Parameters:
element_representation
- is the value returned by the reading function.- Returns:
true
if the object is assumed to be valid (ie. it will be replies by the reading function), otherwhisefalse
.- Throws:
IOException
- in case of error.
-
createPoint
protected abstract E createPoint(AttributeCollection provider, int shape_index, ESRIPoint point)
Create a point instance.- Parameters:
provider
- is the attribute provider which must be used by the new element.shape_index
- is the index of the element in the shape file.point
- is the location of the point.- Returns:
- an object representing the creating point, depending of your implementation.
This value will be passed to
AbstractCommonShapeFileReader.postRecordReadingStage(Object)
.
-
createPolyline
protected abstract E createPolyline(AttributeCollection provider, int shapeIndex, int[] parts, ESRIPoint[] points, boolean hasZ)
Create a polyline.- Parameters:
provider
- is the attribute provider which must be used by the new element.shapeIndex
- is the index of the element in the shape file.parts
- is the list of the parts, ie the index of the first point in the parts.points
- is the list of the points.hasZ
- indicates if the z-coordinates were set.- Returns:
- an object representing the creating element, depending of your implementation.
This value will be passed to
AbstractCommonShapeFileReader.postRecordReadingStage(Object)
.
-
createPolygon
protected abstract E createPolygon(AttributeCollection provider, int shapeIndex, int[] parts, ESRIPoint[] points, boolean hasZ)
Create a polygon.- Parameters:
provider
- is the attribute provider which must be used by the new element.shapeIndex
- is the index of the element in the shape file.parts
- is the list of the parts, ie the index of the first point in the parts.points
- is the list of the points.hasZ
- indicates if the z-coordinates were set.- Returns:
- an object representing the creating element, depending of your implementation.
This value will be passed to
AbstractCommonShapeFileReader.postRecordReadingStage(Object)
.
-
createMultiPoint
protected abstract E createMultiPoint(AttributeCollection provider, int shapeIndex, ESRIPoint[] points, boolean hasZ)
Create a multipoint.- Parameters:
provider
- is the attribute provider which must be used by the new element.shapeIndex
- is the index of the element in the shape file.points
- is the list of the points.hasZ
- indicates if the z-coordinates were set.- Returns:
- an object representing the creating element, depending of your implementation.
This value will be passed to
AbstractCommonShapeFileReader.postRecordReadingStage(Object)
.
-
createMultiPatch
protected abstract E createMultiPatch(AttributeCollection provider, int shapeIndex, int[] parts, ShapeMultiPatchType[] partTypes, ESRIPoint[] points)
Create a multipatch.A MultiPatch consists of a number of surface patches. Each surface patch describes a surface. The surface patches of a MultiPatch are referred to as its parts, and the type of part controls how the order of vertices of an MultiPatch part is interpreted.
A single Triangle Strip, or Triangle Fan, represents a single surface patch.
A sequence of parts that are rings can describe a polygonal surface patch with holes. The sequence typically consists of an Outer Ring, representing the outer boundary of the patch, followed by a number of Inner Rings representing holes. When the individual types of rings in a collection of rings representing a polygonal patch with holes are unknown, the sequence must start with First Ring, followed by a number of Rings. A sequence of Rings not preceded by an First Ring is treated as a sequence of Outer Rings without holes.
- Parameters:
provider
- is the attribute provider which must be used by the new element.shapeIndex
- is the index of the element in the shape file.parts
- is the list of the parts, ie the index of the first point in the parts.partTypes
- is the list of the types of the parts.points
- is the list of the points.- Returns:
- an object representing the creating multipatch, depending of your implementation.
This value will be passed to
AbstractCommonShapeFileReader.postRecordReadingStage(Object)
.
-
putAttributeIn
protected abstract void putAttributeIn(E element, String attributeName, AttributeValue value)
Invoked to put an attribute in the element.- Parameters:
element
- is the element in which the attribute should be put.attributeName
- is the name of the attribute.value
- is the value of the attribute.
-
createAttributeCollection
protected abstract AttributeCollection createAttributeCollection(int elementIndex)
Create an attribute provider which will be used by a new element.- Parameters:
elementIndex
- is the index of the element for which an attribute provider must be created.- Returns:
- the new attribute provider which will be passed to one of the creation functions.
- See Also:
createMultiPoint(AttributeCollection, int, ESRIPoint[], boolean)
,createPoint(AttributeCollection, int, ESRIPoint)
,createPolygon(AttributeCollection, int, int[], ESRIPoint[], boolean)
,createPolyline(AttributeCollection, int, int[], ESRIPoint[], boolean)
-
seek
public void seek(int recordIndex) throws IOException
Description copied from class:AbstractCommonShapeFileReader
Move the reading head at the specified record index.If the index is negative, the next record to read is assumed to be the first record. If the index is greater or equals to the count of records, the exception
EOFException
will be thrown.- Specified by:
seek
in classAbstractCommonShapeFileReader<E>
- Parameters:
recordIndex
- is the index of record to reply at the next read.- Throws:
IOException
- in case of error.
-
isSeekEnabled
public boolean isSeekEnabled()
Description copied from class:AbstractCommonShapeFileReader
Replies if the seek feature is enabled.- Overrides:
isSeekEnabled
in classAbstractCommonShapeFileReader<E>
- Returns:
true
if the seek feature is enabled, otherwisefalse
-
-