package nl.tudelft.simulation.dsol.animation.gis.osm; import java.awt.Color; import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; import java.net.URL; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Set; import org.djutils.exceptions.Throw; import de.siegmar.fastcsv.reader.NamedCsvReader; import de.siegmar.fastcsv.reader.NamedCsvRow; import nl.tudelft.simulation.dsol.animation.gis.FeatureInterface; import nl.tudelft.simulation.dsol.animation.gis.GisMapInterface; import nl.tudelft.simulation.dsol.animation.gis.LayerInterface; import nl.tudelft.simulation.dsol.animation.gis.map.Feature; import nl.tudelft.simulation.dsol.animation.gis.map.GisMap; import nl.tudelft.simulation.dsol.animation.gis.map.Layer; import nl.tudelft.simulation.dsol.animation.gis.parser.ColorParser; import nl.tudelft.simulation.dsol.animation.gis.transform.CoordinateTransform; /** * This class parses a CSV file that defines which elements of an OpenSTreetMap file need to be drawn and what format to use. *
* Copyright (c) 2020-2022 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See * for project information DSOL Manual. The DSOL * project is distributed under a three-clause BSD-style license, which can be found at * DSOL License. *
** The dsol-animation-gis project is based on the gisbeans project that has been part of DSOL since 2002, originally by Peter * Jacobs and Paul Jacobs. *
* @author Alexander Verbraeck */ public final class OsmFileCsvParser { /** Utility class, no constructor. */ private OsmFileCsvParser() { // Utility class } /** * Parses a CSV file with information about the map and layers. * @param csvUrl URL; the url of the CSV file. * @param osmUrl URL; the OpenStreetMap file in pbf, osm.gz or osm.bz2 format * @param mapName String; the human readable name of the map * @return MapInterface the parsed map file. * @throws IOException on failure */ public static GisMapInterface parseMapFile(final URL csvUrl, final URL osmUrl, final String mapName) throws IOException { return parseMapFile(csvUrl, osmUrl, mapName, new CoordinateTransform.NoTransform()); } /** * Parses a CSV file with information about the map and layers. * @param csvUrl URL; the url of the CSV file. * @param osmUrl URL; the OpenStreetMap file in pbf, osm.gz or osm.bz2 format * @param mapName String; the human readable name of the map * @param coordinateTransform CoordinateTransform; the transformation of (x, y) coordinates to (x', y') coordinates. * @return MapInterface the parsed map file. * @throws IOException on failure */ public static GisMapInterface parseMapFile(final URL csvUrl, final URL osmUrl, final String mapName, final CoordinateTransform coordinateTransform) throws IOException { return parseMapFile(csvUrl, osmUrl, mapName, coordinateTransform, ',', '"'); } /** * Parses a CSV file with information about the map and layers. FieldSeparateor can be, for instance \t for a tab character, * and the quote character can be the double quote, the single quote, or something else. * @param csvUrl URL; the url of the CSV file. * @param osmUrl URL; the OpenStreetMap file in pbf, osm.gz or osm.bz2 format * @param mapName String; the human readable name of the map * @param coordinateTransform CoordinateTransform; the transformation of (x, y) coordinates to (x', y') coordinates. * @param fieldSeparator char; field separator, e.g., comma for csv files and tab for tsv files * @param quoteCharacter char; e.g., single or double quote * @return MapInterface the parsed map file. * @throws IOException on failure reading the CSV file, the shape files, or making the layers * @throws IllegalArgumentException when one of the outline or fill colors can not be parsed * @throws NumberFormatException when one of colors contains an illegal number */ public static GisMapInterface parseMapFile(final URL csvUrl, final URL osmUrl, final String mapName, final CoordinateTransform coordinateTransform, final char fieldSeparator, final char quoteCharacter) throws IOException { GisMapInterface map = new GisMap(); map.setName(mapName); List