- java.lang.Object
-
- org.arakhne.afc.io.shape.AbstractCommonShapeFileReader<E>
-
- org.arakhne.afc.io.shape.AbstractShapeFileReader<E>
-
- org.arakhne.afc.io.shape.ShapeFileReader<E>
-
- Type Parameters:
E
- is the type of elements which is red by this reader.
- All Implemented Interfaces:
AutoCloseable
,Iterable<E>
public class ShapeFileReader<E> extends AbstractShapeFileReader<E>
This class is a shape file reader that instance the default elements.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 protected ElementFactory<E>
factory
This object describes how to create instance of shape file elements.-
Fields inherited from class org.arakhne.afc.io.shape.AbstractShapeFileReader
DEFAULT_FUSION_DISTANCE
-
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 ShapeFileReader(File file, DBaseFileReader dbase_importer, ElementFactory<E> factory)
Create a reader of shapes from specified file.ShapeFileReader(File file, DBaseFileReader dbase_importer, ShapeFileIndexReader shxReader, ElementFactory<E> factory)
Create a reader of shapes from specified file.ShapeFileReader(File file, ElementFactory<E> factory)
Create a reader of shapes from specified file.ShapeFileReader(File file, ShapeFileIndexReader shxReader, ElementFactory<E> factory)
Create a reader of shapes from specified file.ShapeFileReader(InputStream inputStream, DBaseFileReader dbase_importer, ElementFactory<E> factory)
Create a reader of shapes from specified input stream.ShapeFileReader(InputStream inputStream, DBaseFileReader dbase_importer, ShapeFileIndexReader shxReader, ElementFactory<E> factory)
Create a reader of shapes from specified input stream.ShapeFileReader(InputStream inputStream, ElementFactory<E> factory)
Create a reader of shapes from specified input stream.ShapeFileReader(InputStream inputStream, ShapeFileIndexReader shxReader, ElementFactory<E> factory)
Create a reader of shapes from specified input stream.ShapeFileReader(URL url, DBaseFileReader dbase_importer, ElementFactory<E> factory)
Create a reader of shapes from specified URL.ShapeFileReader(URL url, DBaseFileReader dbase_importer, ShapeFileIndexReader shxReader, ElementFactory<E> factory)
Create a reader of shapes from specified URL.ShapeFileReader(URL url, ElementFactory<E> factory)
Create a reader of shapes from specified URL.ShapeFileReader(URL url, ShapeFileIndexReader shxReader, ElementFactory<E> factory)
Create a reader of shapes from specified URL.ShapeFileReader(ReadableByteChannel channel, DBaseFileReader dbase_importer, ElementFactory<E> factory)
Create a reader of shapes from specified channel.ShapeFileReader(ReadableByteChannel channel, DBaseFileReader dbase_importer, ShapeFileIndexReader shxReader, ElementFactory<E> factory)
Create a reader of shapes from specified channel.ShapeFileReader(ReadableByteChannel channel, ElementFactory<E> factory)
Create a reader of shapes from specified channel .ShapeFileReader(ReadableByteChannel channel, ShapeFileIndexReader shxReader, ElementFactory<E> factory)
Create a reader of shapes from specified channel.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected AttributeCollection
createAttributeCollection(int elementIndex)
Create an attribute provider which will be used by a new element.protected E
createMultiPatch(AttributeCollection provider, int shapeIndex, int[] parts, ShapeMultiPatchType[] partTypes, ESRIPoint[] points)
Create a multipatch.protected E
createMultiPoint(AttributeCollection provider, int shapeIndex, ESRIPoint[] points, boolean hasZ)
Create a multipoint.protected E
createPoint(AttributeCollection provider, int shape_index, ESRIPoint point)
Create a point instance.protected E
createPolygon(AttributeCollection provider, int shapeIndex, int[] parts, ESRIPoint[] points, boolean hasZ)
Create a polygon.protected E
createPolyline(AttributeCollection provider, int shapeIndex, int[] parts, ESRIPoint[] points, boolean hasZ)
Create a polyline.protected boolean
postAttributeReadingStage(E element)
Called just after the dBase attributes was red.protected void
postHeaderReadingStage()
Called just after the header was read.protected void
postReadingStage(boolean success)
Called after all the entries was read.protected boolean
postRecordReadingStage(E element)
Called just after an entry was read but just before the dBase attributes were read.protected boolean
postShapeReadingStage(E element)
Called just after the shape was red but before the attributes were retreived.protected void
preReadingStage()
Called after the reader was initialized and before the header of the shape file was read.protected void
putAttributeIn(E element, String attributeName, AttributeValue value)
Invoked to put an attribute in the element.-
Methods inherited from class org.arakhne.afc.io.shape.AbstractShapeFileReader
close, isSeekEnabled, readRecord, seek
-
Methods inherited from class org.arakhne.afc.io.shape.AbstractCommonShapeFileReader
disableSeek, ensureAvailableBytes, getBoundsFromHeader, getFileReadingPosition, getFileSize, getShapeElementType, getTaskProgression, isHeaderRead, iterator, iterator, iterator, iterator, 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
-
factory
protected final ElementFactory<E> factory
This object describes how to create instance of shape file elements.
-
-
Constructor Detail
-
ShapeFileReader
public ShapeFileReader(InputStream inputStream, ElementFactory<E> factory)
Create a reader of shapes from specified input stream.- Parameters:
inputStream
- is the stream to read.factory
- is the object that describes how to create instance of elements.
-
ShapeFileReader
public ShapeFileReader(InputStream inputStream, DBaseFileReader dbase_importer, ElementFactory<E> factory)
Create a reader of shapes from specified input stream.- Parameters:
inputStream
- is the stream to read.factory
- is the object that describes how to create instance of elements.dbase_importer
- is the dBase reader to use to read the attribute's values.
-
ShapeFileReader
public ShapeFileReader(InputStream inputStream, ShapeFileIndexReader shxReader, ElementFactory<E> factory)
Create a reader of shapes from specified input stream.- Parameters:
inputStream
- is the stream to read.factory
- is the object that describes how to create instance of elements.shxReader
- is the shape file index reader used to access to the shape file record indexes.
-
ShapeFileReader
public ShapeFileReader(InputStream inputStream, DBaseFileReader dbase_importer, ShapeFileIndexReader shxReader, ElementFactory<E> factory)
Create a reader of shapes from specified input stream.- Parameters:
inputStream
- is the stream to read.factory
- is the object that describes how to create instance of elements.dbase_importer
- is the dBase reader to use to read the attribute's values.shxReader
- is the shape file index reader used to access to the shape file record indexes.
-
ShapeFileReader
public ShapeFileReader(ReadableByteChannel channel, ElementFactory<E> factory)
Create a reader of shapes from specified channel .- Parameters:
channel
- is the channel to read from.factory
- is the object that describes how to create instance of elements.
-
ShapeFileReader
public ShapeFileReader(ReadableByteChannel channel, DBaseFileReader dbase_importer, ElementFactory<E> factory)
Create a reader of shapes from specified channel.- Parameters:
channel
- is the channel to read from.factory
- is the object that describes how to create instance of elements.dbase_importer
- is the dBase reader to use to read the attribute's values.
-
ShapeFileReader
public ShapeFileReader(ReadableByteChannel channel, ShapeFileIndexReader shxReader, ElementFactory<E> factory)
Create a reader of shapes from specified channel.- Parameters:
channel
- is the channel to read from.factory
- is the object that describes how to create instance of elements.shxReader
- is the shape file index reader used to access to the shape file record indexes.
-
ShapeFileReader
public ShapeFileReader(ReadableByteChannel channel, DBaseFileReader dbase_importer, ShapeFileIndexReader shxReader, ElementFactory<E> factory)
Create a reader of shapes from specified channel.- Parameters:
channel
- is the channel to read from.factory
- is the object that describes how to create instance of elements.dbase_importer
- is the dBase reader to use to read the attribute's values.shxReader
- is the shape file index reader used to access to the shape file record indexes.
-
ShapeFileReader
public ShapeFileReader(File file, ElementFactory<E> factory) throws IOException
Create a reader of shapes from specified file.- Parameters:
file
- is the file to open and read.factory
- is the object that describes how to create instance of elements.- Throws:
IOException
- in case of error.
-
ShapeFileReader
public ShapeFileReader(File file, DBaseFileReader dbase_importer, ElementFactory<E> factory) throws IOException
Create a reader of shapes from specified file.- Parameters:
file
- is the file to open and read.factory
- is the object that describes how to create instance of elements.dbase_importer
- is the dBase reader to use to read the attribute's values.- Throws:
IOException
- in case of error.
-
ShapeFileReader
public ShapeFileReader(File file, ShapeFileIndexReader shxReader, ElementFactory<E> factory) throws IOException
Create a reader of shapes from specified file.- Parameters:
file
- is the file to open and read.factory
- is the object that describes how to create instance of elements.shxReader
- is the shape file index reader used to access to the shape file record indexes.- Throws:
IOException
- in case of error.
-
ShapeFileReader
public ShapeFileReader(File file, DBaseFileReader dbase_importer, ShapeFileIndexReader shxReader, ElementFactory<E> factory) throws IOException
Create a reader of shapes from specified file.- Parameters:
file
- is the file to open and read.factory
- is the object that describes how to create instance of elements.dbase_importer
- is the dBase reader to use to read the attribute's values.shxReader
- is the shape file index reader used to access to the shape file record indexes.- Throws:
IOException
- in case of error.
-
ShapeFileReader
public ShapeFileReader(URL url, ElementFactory<E> factory) throws IOException
Create a reader of shapes from specified URL.- Parameters:
url
- is the url of the stream to read.factory
- is the object that describes how to create instance of elements.- Throws:
IOException
- in case of error.
-
ShapeFileReader
public ShapeFileReader(URL url, DBaseFileReader dbase_importer, ElementFactory<E> factory) throws IOException
Create a reader of shapes from specified URL.- Parameters:
url
- is the url of the stream to read.factory
- is the object that describes how to create instance of elements.dbase_importer
- is the dBase reader to use to read the attribute's values.- Throws:
IOException
- in case of error.
-
ShapeFileReader
public ShapeFileReader(URL url, ShapeFileIndexReader shxReader, ElementFactory<E> factory) throws IOException
Create a reader of shapes from specified URL.- Parameters:
url
- is the url of the stream to read.factory
- is the object that describes how to create instance of elements.shxReader
- is the shape file index reader used to access to the shape file record indexes.- Throws:
IOException
- in case of error.
-
ShapeFileReader
public ShapeFileReader(URL url, DBaseFileReader dbase_importer, ShapeFileIndexReader shxReader, ElementFactory<E> factory) throws IOException
Create a reader of shapes from specified URL.- Parameters:
url
- is the url of the stream to read.factory
- is the object that describes how to create instance of elements.dbase_importer
- is the dBase reader to use to read the attribute's values.shxReader
- is the shape file index reader used to access to the shape file record indexes.- Throws:
IOException
- in case of error.
-
-
Method Detail
-
createAttributeCollection
protected AttributeCollection createAttributeCollection(int elementIndex)
Description copied from class:AbstractShapeFileReader
Create an attribute provider which will be used by a new element.- Specified by:
createAttributeCollection
in classAbstractShapeFileReader<E>
- 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:
AbstractShapeFileReader.createMultiPoint(AttributeCollection, int, ESRIPoint[], boolean)
,AbstractShapeFileReader.createPoint(AttributeCollection, int, ESRIPoint)
,AbstractShapeFileReader.createPolygon(AttributeCollection, int, int[], ESRIPoint[], boolean)
,AbstractShapeFileReader.createPolyline(AttributeCollection, int, int[], ESRIPoint[], boolean)
-
createMultiPoint
protected E createMultiPoint(AttributeCollection provider, int shapeIndex, ESRIPoint[] points, boolean hasZ)
Description copied from class:AbstractShapeFileReader
Create a multipoint.- Specified by:
createMultiPoint
in classAbstractShapeFileReader<E>
- 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)
.
-
createPoint
protected E createPoint(AttributeCollection provider, int shape_index, ESRIPoint point)
Description copied from class:AbstractShapeFileReader
Create a point instance.- Specified by:
createPoint
in classAbstractShapeFileReader<E>
- 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)
.
-
createPolygon
protected E createPolygon(AttributeCollection provider, int shapeIndex, int[] parts, ESRIPoint[] points, boolean hasZ)
Description copied from class:AbstractShapeFileReader
Create a polygon.- Specified by:
createPolygon
in classAbstractShapeFileReader<E>
- 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)
.
-
createPolyline
protected E createPolyline(AttributeCollection provider, int shapeIndex, int[] parts, ESRIPoint[] points, boolean hasZ)
Description copied from class:AbstractShapeFileReader
Create a polyline.- Specified by:
createPolyline
in classAbstractShapeFileReader<E>
- 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)
.
-
createMultiPatch
protected E createMultiPatch(AttributeCollection provider, int shapeIndex, int[] parts, ShapeMultiPatchType[] partTypes, ESRIPoint[] points)
Description copied from class:AbstractShapeFileReader
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.
- Specified by:
createMultiPatch
in classAbstractShapeFileReader<E>
- 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)
.
-
postAttributeReadingStage
protected boolean postAttributeReadingStage(E element) throws IOException
Description copied from class:AbstractShapeFileReader
Called just after the dBase attributes was red.- Overrides:
postAttributeReadingStage
in classAbstractShapeFileReader<E>
- Parameters:
element
- 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.
-
postRecordReadingStage
protected boolean postRecordReadingStage(E element) throws IOException
Description copied from class:AbstractCommonShapeFileReader
Called just after an entry was read but just before the dBase attributes were read.- Overrides:
postRecordReadingStage
in classAbstractCommonShapeFileReader<E>
- Parameters:
element
- is the value returned by the reading function.- Returns:
true
if the object is assumed to be valid (ie. replies by the reading function, otherwhisefalse
.- Throws:
IOException
- in case of error.
-
postShapeReadingStage
protected boolean postShapeReadingStage(E element) throws IOException
Description copied from class:AbstractShapeFileReader
Called just after the shape was red but before the attributes were retreived.- Overrides:
postShapeReadingStage
in classAbstractShapeFileReader<E>
- Parameters:
element
- 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.
-
postHeaderReadingStage
protected void postHeaderReadingStage() throws IOException
Description copied from class:AbstractCommonShapeFileReader
Called just after the header was read.- Overrides:
postHeaderReadingStage
in classAbstractShapeFileReader<E>
- Throws:
IOException
- in case of error.
-
postReadingStage
protected void postReadingStage(boolean success) throws IOException
Description copied from class:AbstractCommonShapeFileReader
Called after all the entries was read.- Overrides:
postReadingStage
in classAbstractCommonShapeFileReader<E>
- Parameters:
success
- istrue
is the reading was successfull, otherwhisefalse
.- Throws:
IOException
- in case of error.
-
preReadingStage
protected void preReadingStage() throws IOException
Description copied from class:AbstractCommonShapeFileReader
Called after the reader was initialized and before the header of the shape file was read.- Overrides:
preReadingStage
in classAbstractCommonShapeFileReader<E>
- Throws:
IOException
- in case of error.
-
putAttributeIn
protected void putAttributeIn(E element, String attributeName, AttributeValue value)
Description copied from class:AbstractShapeFileReader
Invoked to put an attribute in the element.- Specified by:
putAttributeIn
in classAbstractShapeFileReader<E>
- 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.
-
-