Package org.goplanit.matsim.converter
Class MatsimWriter<T>
- java.lang.Object
-
- org.goplanit.converter.BaseWriterImpl<T>
-
- org.goplanit.matsim.converter.MatsimWriter<T>
-
- All Implemented Interfaces:
ConverterEntity
,ConverterWriter<T>
- Direct Known Subclasses:
MatsimNetworkWriter
,MatsimZoningWriter
public abstract class MatsimWriter<T> extends BaseWriterImpl<T>
Base class from which all matsim writers derive- Author:
- markr
-
-
Field Summary
Fields Modifier and Type Field Description static String
DEFAULT_FILE_NAME_EXTENSION
default extension for xml files generatedprotected org.opengis.referencing.operation.MathTransform
destinationCrsTransformer
when the destination CRS differs from the network CRS all geometries require transforming, for which this transformer will be initialisedprotected int
indentLevel
track indentation level-
Fields inherited from class org.goplanit.converter.BaseWriterImpl
idMapper
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
MatsimWriter(IdMapperType idMapperType)
Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
decreaseIndentation()
Decrease indentation levelprotected org.locationtech.jts.geom.Coordinate
extractDestinationCrsCompatibleCoordinate(org.locationtech.jts.geom.Point location)
Using the destination crs and its transformer extract the coordinate from the position in the desired crsprotected void
increaseIndentation()
Increase indentation levelprotected org.opengis.referencing.crs.CoordinateReferenceSystem
prepareCoordinateReferenceSystem(MacroscopicNetwork network, String destinationCountry, org.opengis.referencing.crs.CoordinateReferenceSystem destinationCrs)
Prepare the Crs transformer (if any) based on the user configuration settings.protected boolean
validateNetwork(TransportLayerNetwork<?,?> referenceNetwork)
Validate the network instance available, throw or log when issues are foundprotected void
writeEndElementNewLine(XMLStreamWriter xmlWriter, boolean decreaseIndentation)
write an end element and add newline afterwardsprotected void
writeIndentation(XMLStreamWriter xmlWriter)
Add indentation to stream at current indentation levelprotected void
writeStartElementNewLine(XMLStreamWriter xmlWriter, String xmlElementName, boolean increaseIndentation)
write a start element and add newline afterwards-
Methods inherited from class org.goplanit.converter.BaseWriterImpl
getIdMapperType, identifyDestinationCoordinateReferenceSystem, setIdMapperType
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.goplanit.converter.ConverterEntity
getTypeDescription, reset
-
Methods inherited from interface org.goplanit.converter.ConverterWriter
getSettings, write
-
-
-
-
Field Detail
-
indentLevel
protected int indentLevel
track indentation level
-
destinationCrsTransformer
protected org.opengis.referencing.operation.MathTransform destinationCrsTransformer
when the destination CRS differs from the network CRS all geometries require transforming, for which this transformer will be initialised
-
DEFAULT_FILE_NAME_EXTENSION
public static final String DEFAULT_FILE_NAME_EXTENSION
default extension for xml files generated- See Also:
- Constant Field Values
-
-
Constructor Detail
-
MatsimWriter
protected MatsimWriter(IdMapperType idMapperType)
Constructor- Parameters:
idMapperType
- to use
-
-
Method Detail
-
validateNetwork
protected boolean validateNetwork(TransportLayerNetwork<?,?> referenceNetwork) throws PlanItException
Validate the network instance available, throw or log when issues are found- Parameters:
referenceNetwork
- to use for persisting- Returns:
- true when valid, false otherwise
- Throws:
PlanItException
- thrown if invalid
-
prepareCoordinateReferenceSystem
protected org.opengis.referencing.crs.CoordinateReferenceSystem prepareCoordinateReferenceSystem(MacroscopicNetwork network, String destinationCountry, org.opengis.referencing.crs.CoordinateReferenceSystem destinationCrs) throws PlanItException
Prepare the Crs transformer (if any) based on the user configuration settings. If no destinationCrs is provided than we use the country to try and infer the most appropriate desintation crs. In case the identified destination crs differs from the network one, we also creata destination transformer which is registered on the instance of the class- Parameters:
network
- the network extract current Crs if no user specific settings can be founddestinationCountry
- of the networkdestinationCrs
- that we would like to use, maybe null- Returns:
- identified destinationCrs to use
- Throws:
PlanItException
- thrown if error
-
extractDestinationCrsCompatibleCoordinate
protected org.locationtech.jts.geom.Coordinate extractDestinationCrsCompatibleCoordinate(org.locationtech.jts.geom.Point location) throws org.opengis.geometry.MismatchedDimensionException, org.opengis.referencing.operation.TransformException
Using the destination crs and its transformer extract the coordinate from the position in the desired crs- Parameters:
location
- to extract destination crs compatible coordinate for- Returns:
- coordinate created
- Throws:
org.opengis.referencing.operation.TransformException
- thrown if errororg.opengis.geometry.MismatchedDimensionException
- thrown if error
-
writeIndentation
protected void writeIndentation(XMLStreamWriter xmlWriter) throws XMLStreamException
Add indentation to stream at current indentation level- Parameters:
xmlWriter
- to use- Throws:
XMLStreamException
- thrown if error
-
increaseIndentation
protected void increaseIndentation() throws XMLStreamException
Increase indentation level- Throws:
XMLStreamException
- thrown when error
-
decreaseIndentation
protected void decreaseIndentation() throws XMLStreamException
Decrease indentation level- Throws:
XMLStreamException
- thrown when error
-
writeStartElementNewLine
protected void writeStartElementNewLine(XMLStreamWriter xmlWriter, String xmlElementName, boolean increaseIndentation) throws XMLStreamException
write a start element and add newline afterwards- Parameters:
xmlWriter
- to usexmlElementName
- element to start tag, e.g.<xmlElementName>
increaseIndentation
- when true, increase indentation after this element has been written- Throws:
XMLStreamException
- thrown if error
-
writeEndElementNewLine
protected void writeEndElementNewLine(XMLStreamWriter xmlWriter, boolean decreaseIndentation) throws XMLStreamException
write an end element and add newline afterwards- Parameters:
xmlWriter
- to usedecreaseIndentation
- when true decrease indentation level before this element has been written- Throws:
XMLStreamException
- thrown if error
-
-