Class AbstractShapeFileWriter<E>
- java.lang.Object
-
- org.arakhne.afc.io.shape.AbstractCommonShapeFileWriter<E>
-
- org.arakhne.afc.io.shape.AbstractShapeFileWriter<E>
-
- Type Parameters:
E
- is the type of element to write inside the ESRI shape file.
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
GISShapeFileWriter
,ShapeFileWriter
public abstract class AbstractShapeFileWriter<E> extends AbstractCommonShapeFileWriter<E>
This class permits to write an ESRI Shape file.When a
dBase writer
was given, the attributes associated to each element will be put in a dBase file. The columns in the dBase file depends on the attributes which are defined in the elements at the first call toAbstractCommonShapeFileWriter.write(Collection)
orAbstractCommonShapeFileWriter.write(Object)
. Subsequent calls toAbstractCommonShapeFileWriter.write(Collection)
orAbstractCommonShapeFileWriter.write(Object)
do not change the dBase columns. Consequently the subsequent calls call cause several attributes to not be written in the dBase file even if they exists in the element's attribute containers.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 inherited from class org.arakhne.afc.io.shape.AbstractCommonShapeFileWriter
BLOCK_SIZE
-
-
Constructor Summary
Constructors Constructor Description AbstractShapeFileWriter(File shapeName, ShapeElementType elementType, DBaseFileWriter dbfWriter, ShapeFileIndexWriter shxWriter)
Constructor.AbstractShapeFileWriter(OutputStream stream, ShapeElementType elementType, DBaseFileWriter dbfWriter, ShapeFileIndexWriter shxWriter)
Constructor.AbstractShapeFileWriter(URL shapeName, ShapeElementType elementType, DBaseFileWriter dbfWriter, ShapeFileIndexWriter shxWriter)
Constructor.AbstractShapeFileWriter(WritableByteChannel channel, ShapeElementType elementType, DBaseFileWriter dbfWriter, ShapeFileIndexWriter shxWriter)
Constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
close()
Flush temp buffers, write down final information in file header (file size...), and close the streams.protected abstract AttributeProvider
getAttributeProvider(E element)
Replies the attribute container of the given element.protected abstract AttributeProvider[]
getAttributeProviders(Collection<? extends E> elements)
Replies all the attribute containers of the given elements.protected abstract int
getGroupCountFor(E element)
Replies the count of groups of points.protected abstract ShapeMultiPatchType
getGroupTypeFor(E element, int groupIndex)
Replies the type of the given part for a multipatch element.protected abstract ESRIPoint
getPointAt(E element, int groupIndex, int pointIndex, boolean expectM, boolean expectZ)
Replies the point inside the given part at the given index.protected abstract int
getPointCountFor(E element, int groupIndex)
Replies the count of points inside the given part.protected void
onHeaderWritten(ESRIBounds box, ShapeElementType type, Collection<? extends E> elements)
Invoked after the header was written.protected void
writeElement(int recordIndex, E element, ShapeElementType type)
Write an element inside the output stream.-
Methods inherited from class org.arakhne.afc.io.shape.AbstractCommonShapeFileWriter
ensureAvailableBytes, flush, getElementType, getFileBounds, getTaskProgression, isHeaderWritten, setTaskProgression, write, write, writeBEDouble, writeBEInt, writeLEDouble, writeLEInt
-
-
-
-
Constructor Detail
-
AbstractShapeFileWriter
public AbstractShapeFileWriter(File shapeName, ShapeElementType elementType, DBaseFileWriter dbfWriter, ShapeFileIndexWriter shxWriter) throws IOException
Constructor.- Parameters:
shapeName
- is the file to writeelementType
- is the type of the elements to write.dbfWriter
- is the writer used to export the attributesshxWriter
- is the writer used to create the index- Throws:
IOException
- in case of error.
-
AbstractShapeFileWriter
public AbstractShapeFileWriter(URL shapeName, ShapeElementType elementType, DBaseFileWriter dbfWriter, ShapeFileIndexWriter shxWriter) throws IOException
Constructor.- Parameters:
shapeName
- is the file to writeelementType
- is the type of the elements to write.dbfWriter
- is the writer used to export the attributesshxWriter
- is the writer used to create the index- Throws:
IOException
- in case of error.
-
AbstractShapeFileWriter
public AbstractShapeFileWriter(OutputStream stream, ShapeElementType elementType, DBaseFileWriter dbfWriter, ShapeFileIndexWriter shxWriter) throws IOException
Constructor.- Parameters:
stream
- is the file to writeelementType
- is the type of the elements to write.dbfWriter
- is the writer used to export the attributesshxWriter
- is the writer used to create the index- Throws:
IOException
- in case of error.
-
AbstractShapeFileWriter
public AbstractShapeFileWriter(WritableByteChannel channel, ShapeElementType elementType, DBaseFileWriter dbfWriter, ShapeFileIndexWriter shxWriter) throws IOException
Constructor.- Parameters:
channel
- is the file to writeelementType
- is the type of the elements to write.dbfWriter
- is the writer used to export the attributesshxWriter
- is the writer used to create the index- Throws:
IOException
- in case of error.
-
-
Method Detail
-
getPointCountFor
protected abstract int getPointCountFor(E element, int groupIndex) throws IOException
Replies the count of points inside the given part. This function is also invoked for a multipoint. In this case, the group index is always equal to zero.- Parameters:
element
- is the element from which the point count must be extractedgroupIndex
- is the index of the group from which the point count must be replied.- Returns:
- the count of points in the part at the given index.
- Throws:
IOException
- in case of error.
-
getGroupTypeFor
protected abstract ShapeMultiPatchType getGroupTypeFor(E element, int groupIndex) throws IOException
Replies the type of the given part for a multipatch element.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:
element
- is the element from which the point count must be extractedgroupIndex
- is the index of the group from which the point count must be replied.- Returns:
- the type of the part.
- Throws:
IOException
- in case of error.
-
getAttributeProviders
protected abstract AttributeProvider[] getAttributeProviders(Collection<? extends E> elements) throws IOException
Replies all the attribute containers of the given elements. The attributes will be put in a DBase file header as columns. The size of the replied array should be the same as the size of the collection of elements. Otherwise you must be sure that you are not loosing attributes. Moreover the position of the AttributeProvider in the array must corresponds to the position of the element record in the DBF and shape file.- Parameters:
elements
- are the element from which the attribute containers must be extracted- Returns:
- the attribute containers.
- Throws:
IOException
- in case of error.
-
getAttributeProvider
protected abstract AttributeProvider getAttributeProvider(E element) throws IOException
Replies the attribute container of the given element. The attributes will be put in a DBase file.- Parameters:
element
- is the element from which the attribute container must be extracted- Returns:
- the attribute container
- Throws:
IOException
- in case of error.
-
getGroupCountFor
protected abstract int getGroupCountFor(E element) throws IOException
Replies the count of groups of points.- Parameters:
element
- is the element from which the group count must be extracted- Returns:
- the count of groups of points.
- Throws:
IOException
- in case of error.
-
getPointAt
protected abstract ESRIPoint getPointAt(E element, int groupIndex, int pointIndex, boolean expectM, boolean expectZ) throws IOException
Replies the point inside the given part at the given index.This function is also invoked for a simple point. In this case, the group and point indexes are both equal to zero. This function is also invoked for a multipoint. In this case, the group index is always equal to zero.
- Parameters:
element
- is the element from which the point must be extractedgroupIndex
- is the index of the group from which the point must be extracted.pointIndex
- is the index of the point in the group.expectM
- indicates if the M value is expected.expectZ
- indicates if the Z value is expected.- Returns:
- the point.
- Throws:
IOException
- in case of error.
-
onHeaderWritten
protected void onHeaderWritten(ESRIBounds box, ShapeElementType type, Collection<? extends E> elements) throws IOException
Description copied from class:AbstractCommonShapeFileWriter
Invoked after the header was written.- Overrides:
onHeaderWritten
in classAbstractCommonShapeFileWriter<E>
- Parameters:
box
- is the bouding box of the filetype
- is the type of the elements in the file.elements
- are the elements which are caused the header to be written.- Throws:
IOException
- in case of error.
-
close
public void close() throws IOException
Flush temp buffers, write down final information in file header (file size...), and close the streams.- Specified by:
close
in interfaceAutoCloseable
- Overrides:
close
in classAbstractCommonShapeFileWriter<E>
- Throws:
IOException
- in case of error.
-
writeElement
protected void writeElement(int recordIndex, E element, ShapeElementType type) throws IOException
Description copied from class:AbstractCommonShapeFileWriter
Write an element inside the output stream.- Specified by:
writeElement
in classAbstractCommonShapeFileWriter<E>
- Parameters:
recordIndex
- is the index of the element in the file.element
- is the element to write.type
- is the expected type for the element.- Throws:
IOException
- in case of error.
-
-