Class Shapefile

java.lang.Object
org.geotools.shapefile.Shapefile
All Implemented Interfaces:
TaskMonitorSupport

public class Shapefile extends Object implements TaskMonitorSupport
This class represents an ESRI Shape file.

You construct it with a file name, and later you can read the file's properties, i.e. Sizes, Types, and the data itself.

Copyright 1998 by James Macgill.

Version 1.0beta1.1 (added construct with inputstream) 1.0beta1.2 (made Shape type constants public 18/Aug/98) This class supports the Shape file as set out in :-
"ESRI(r) Shapefile - A Technical Description"
'An ESRI White Paper . May 1997'

This code is coverd by the LGPL. Mail the Author

  • Field Details

  • Constructor Details

    • Shapefile

      public Shapefile(URL url)
      Creates and initialises a shapefile from a url
      Parameters:
      url - The url of the shapefile
    • Shapefile

      public Shapefile(InputStream is)
  • Method Details

    • close

      public void close()
    • read

      public org.locationtech.jts.geom.GeometryCollection read(org.locationtech.jts.geom.GeometryFactory geometryFactory) throws Exception
      Initialises a shapefile from disk. Use Shapefile(String) if you don't want to use LEDataInputStream directly (recommended)
      Parameters:
      geometryFactory - the geometry factory to use to read the shapes
      Throws:
      Exception
    • getErrorNumber

      public int getErrorNumber()
      Get the number of errors found after a read.
    • write

      public void write(org.locationtech.jts.geom.GeometryCollection geometries, int ShapeFileDimension) throws Exception
      Saves a shapefile to an output stream.
      Parameters:
      geometries - geometry collection to write
      ShapeFileDimension - shapefile dimension (2=x,y ; 3=x,y,m ; 4=x,y,z,m)
      Throws:
      Exception
    • writeIndex

      public void writeIndex(org.locationtech.jts.geom.GeometryCollection geometries, EndianDataOutputStream file, int ShapeFileDimension) throws Exception
      Saves a shapefile index (shx) to an output stream.
      Parameters:
      geometries - geometry collection to write
      file - file to write to
      ShapeFileDimension - shapefile dimension (2=x,y ; 3=x,y,m ; 4=x,y,z,m)
      Throws:
      Exception
    • getShapeTypeDescription

      public static String getShapeTypeDescription(int index)
      Returns a string describing the shape type.
      Parameters:
      index - An int coresponding to the shape type to be described
      Returns:
      A string describing the shape type
    • getShapeHandler

      public static ShapeHandler getShapeHandler(org.locationtech.jts.geom.Geometry geom, int ShapeFileDimension) throws Exception
      Throws:
      Exception
    • getShapeHandler

      public static ShapeHandler getShapeHandler(int type) throws Exception
      Throws:
      Exception
    • getShapeType

      public static int getShapeType(org.locationtech.jts.geom.Geometry geom, int ShapeFileDimension) throws ShapefileException
      Returns the Shape Type corresponding to geometry geom of dimension ShapeFileDimension.
      Parameters:
      geom - the geom
      ShapeFileDimension - the dimension of the geom (2=x,y ; 3=x,y,m ; 4=x,y,z,m)
      Returns:
      A int representing the Shape Type
      Throws:
      ShapefileException
    • readFromIndex

      public org.locationtech.jts.geom.GeometryCollection readFromIndex(org.locationtech.jts.geom.GeometryFactory geometryFactory, InputStream is) throws Exception
      The purpose of this new reader [mmichaud 2015-04-11] is to read a shapefile using the shx index file. While the legacy reader #read(GeometryFactory geometryFactory) read the shapefile sequentially and don't need the shx index file, this new parser read the shx file and access the shp file with a RandomAccessReader. Because the shapefile may come from a compressed input stream, the method first write the shapefile in a temporary file.
      Parameters:
      geometryFactory - geometry factory to use to build geometries
      is - shx input stream
      Returns:
      a GeometryCollection containing all the shapes.
      Throws:
      Exception
    • setTaskMonitor

      public void setTaskMonitor(TaskMonitor taskMonitor)
      Specified by:
      setTaskMonitor in interface TaskMonitorSupport
    • getTaskMonitor

      public TaskMonitor getTaskMonitor()
      Specified by:
      getTaskMonitor in interface TaskMonitorSupport