Class ShapeFileReader

  • All Implemented Interfaces:
    Serializable, DataSourceInterface

    public class ShapeFileReader
    extends Object
    implements DataSourceInterface
    This class reads ESRI-shapefiles and returns the shape objects.

    Copyright (c) 2020-2023 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
    See Also:
    Serialized Form
    • Constructor Detail

      • ShapeFileReader

        public ShapeFileReader​(URL shapeUrl,
                               CoordinateTransform coordinateTransform,
                               List<FeatureInterface> featuresToRead)
                        throws IOException
        Construct a reader for an ESRI ShapeFile.
        Parameters:
        shapeUrl - URL; URL may or may not end with their extension.
        coordinateTransform - CoordinateTransform; the transformation of (x, y) coordinates to (x', y') coordinates.
        featuresToRead - the features to read
        Throws:
        IOException - throws an IOException if the shxFile is not accessible
    • Method Detail

      • readShape

        public GisObject readShape​(int index)
                            throws IOException
        Read a particular shape directly from the shape file, without caching (the cache is stored at the Features).
        Parameters:
        index - int; the index of the shape to read from the shape file, without using any caching
        Returns:
        GisObject; the shape belonging to the index
        Throws:
        IOException - when there is a problem reading the ESRI files.
      • readAllShapes

        public List<GisObject> readAllShapes()
                                      throws IOException
        Read all shapes directly from the shape file, without caching (the cache is stored at the Features).
        Returns:
        List<GisObject>; the shapes that are directly read from the shape file
        Throws:
        IOException - when there is a problem reading the ESRI files.
      • readShapes

        public List<GisObject> readShapes​(Bounds2d extent)
                                   throws IOException
        Read all shapes for a certain extent directly from the shape file, without caching (the cache is stored at the Features).
        Parameters:
        extent - Bounds2d; the extent for which to read the shapes
        Returns:
        List<GisObject>; the shapes for the given extent that are directly read from the shape file
        Throws:
        IOException - when there is a problem reading the ESRI files.
      • getShapes

        public List<GisObject> getShapes​(String attribute,
                                         String columnName)
                                  throws IOException
        Return the shapes based on a particular value of the attributes.
        Parameters:
        attribute - String; the value of the attribute
        columnName - String; the columnName
        Returns:
        List the resulting ArrayList of nl.tudelft.simulation.dsol.animation.gis.GisObject
        Throws:
        IOException - on file IO or database connection failure
      • getAttributeKeyNames

        public String[] getAttributeKeyNames()
        Return the key names of the attribute data. The attribute values are stored in the GisObject together with the shape.
        Returns:
        String[]; the key names of the attribute data