Class Shapefile
java.lang.Object
org.geotools.shapefile.Shapefile
- All Implemented Interfaces:
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()intGet the number of errors found after a read.static ShapeHandlergetShapeHandler(int type) static ShapeHandlergetShapeHandler(org.locationtech.jts.geom.Geometry geom, int ShapeFileDimension) static intgetShapeType(org.locationtech.jts.geom.Geometry geom, int ShapeFileDimension) Returns the Shape Type corresponding to geometry geom of dimension ShapeFileDimension.static StringgetShapeTypeDescription(int index) Returns a string describing the shape type.org.locationtech.jts.geom.GeometryCollectionread(org.locationtech.jts.geom.GeometryFactory geometryFactory) Initialises a shapefile from disk.org.locationtech.jts.geom.GeometryCollectionreadFromIndex(org.locationtech.jts.geom.GeometryFactory geometryFactory, InputStream is) The purpose of this new reader [mmichaud 2015-04-11] is to read a shapefile using the shx index file.voidsetTaskMonitor(TaskMonitor taskMonitor) voidwrite(org.locationtech.jts.geom.GeometryCollection geometries, int ShapeFileDimension) Saves a shapefile to an output stream.voidwriteIndex(org.locationtech.jts.geom.GeometryCollection geometries, EndianDataOutputStream file, int ShapeFileDimension) Saves a shapefile index (shx) to an output stream.
-
Field Details
-
NULL
public static final int NULL- See Also:
-
POINT
public static final int POINT- See Also:
-
POINTZ
public static final int POINTZ- See Also:
-
POINTM
public static final int POINTM- See Also:
-
ARC
public static final int ARC- See Also:
-
ARCM
public static final int ARCM- See Also:
-
ARCZ
public static final int ARCZ- See Also:
-
POLYGON
public static final int POLYGON- See Also:
-
POLYGONM
public static final int POLYGONM- See Also:
-
POLYGONZ
public static final int POLYGONZ- See Also:
-
MULTIPOINT
public static final int MULTIPOINT- See Also:
-
MULTIPOINTM
public static final int MULTIPOINTM- See Also:
-
MULTIPOINTZ
public static final int MULTIPOINTZ- See Also:
-
MULTIPATCH
public static final int MULTIPATCH- See Also:
-
UNDEFINED
public static final int UNDEFINED- See Also:
-
-
Constructor Details
-
Shapefile
Creates and initialises a shapefile from a url- Parameters:
url- The url of the shapefile
-
Shapefile
-
-
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
-
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 writefile- file to write toShapeFileDimension- shapefile dimension (2=x,y ; 3=x,y,m ; 4=x,y,z,m)- Throws:
Exception
-
getShapeTypeDescription
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
- 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 geomShapeFileDimension- 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 geometriesis- shx input stream- Returns:
- a GeometryCollection containing all the shapes.
- Throws:
Exception
-
setTaskMonitor
- Specified by:
setTaskMonitorin interfaceTaskMonitorSupport
-
getTaskMonitor
- Specified by:
getTaskMonitorin interfaceTaskMonitorSupport
-