Class EsriShapefile


  • public class EsriShapefile
    extends Object
    EsriShapefile.java

    Encapsulates details of ESRI Shapefile format, documented at http://www.esri.com/library/whitepapers/pdfs/shapefile.pdf

    • Constructor Detail

      • EsriShapefile

        public EsriShapefile​(String filename)
                      throws IOException
        Read an ESRI shapefile and extract all features into an in-memory structure.
        Parameters:
        filename - name of ESRI shapefile (typically has ".shp" extension)
        Throws:
        IOException
      • EsriShapefile

        public EsriShapefile​(URL url)
                      throws IOException
        Read an ESRI shapefile from a URL and extract all features into an in-memory structure.
        Parameters:
        url - URL of ESRI shapefile
        Throws:
        IOException
      • EsriShapefile

        public EsriShapefile​(String filename,
                             double coarseness)
                      throws IOException
        Read an ESRI shapefile and extract all features into an in-memory structure, with control of time versus resolution.
        Parameters:
        filename - name of ESRI shapefile (typically has ".shp" extension)
        coarseness - to tradeoff plot quality versus speed.
        Throws:
        IOException
      • EsriShapefile

        public EsriShapefile​(URL url,
                             double coarseness)
                      throws IOException
        Read an ESRI shapefile from a URL and extract all features into an in-memory structure, with control of time versus resolution.
        Parameters:
        url - URL of ESRI shapefile
        coarseness - to tradeoff plot quality versus speed.
        Throws:
        IOException
      • EsriShapefile

        public EsriShapefile​(URL url,
                             Rectangle2D bBox,
                             double coarseness)
                      throws IOException
        Read an ESRI shapefile and extract the subset of features that have bounding boxes that intersect a specified bounding box
        Parameters:
        url - URL of ESRI shapefile
        bBox - bounding box specifying which features to select, namely those whose bounding boxes intersect this one. If null, bounding box of whole shapefile is used
        coarseness - to tradeoff plot quality versus speed.
        Throws:
        IOException
      • EsriShapefile

        public EsriShapefile​(String filename,
                             Rectangle2D bBox,
                             double coarseness)
                      throws IOException
        Read an ESRI shapefile and extract all features into an in-memory structure, with control of time versus resolution.
        Parameters:
        filename - name of ESRI shapefile
        bBox - bounding box specifying which features to select, namely those whose bounding boxes intersect this one. If null, bounding box of whole shapefile is used
        coarseness - to tradeoff plot quality versus speed.
        Throws:
        IOException
      • EsriShapefile

        public EsriShapefile​(URL url,
                             Rectangle2D bBox)
                      throws IOException
        Read an ESRI shapefile and extract the subset of features that have bounding boxes that intersect a specified bounding box
        Parameters:
        url - URL of ESRI shapefile
        bBox - bounding box specifying which features to select, namely those whose bounding boxes intersect this one. If null, bounding box of whole shapefile is used
        Throws:
        IOException
      • EsriShapefile

        public EsriShapefile​(String filename,
                             Rectangle2D bBox)
                      throws IOException
        Read an ESRI shapefile and extract the subset of features that have bounding boxes that intersect a specified bounding box.
        Parameters:
        filename - name of ESRI shapefile
        bBox - bounding box specifying which features to select, namely those whose bounding boxes intersect this one. If null, bounding box of whole shapefile is used
        Throws:
        IOException
      • EsriShapefile

        public EsriShapefile​(InputStream iStream,
                             Rectangle2D bBox,
                             double coarseness)
                      throws IOException
        Read an ESRI shapefile and extract the subset of features that have bounding boxes that intersect a specified bounding box, with control of time versus resolution.
        Parameters:
        iStream - input from which to read
        bBox - bounding box specifying which features to select, namely those whose bounding boxes intersect this one. If null, bounding box of whole shapefile is used
        Throws:
        IOException
    • Method Detail

      • percentRead

        public double percentRead()
        Return percent of file read, so far.
        Returns:
        percent of file read, so far.
      • getNumFeatures

        public int getNumFeatures()
        Returns:
        number of features in shapefile
      • getVersion

        public int getVersion()
        Returns shapefile format version (currently 1000)
        Returns:
        version, as stored in shapefile.
      • getBoundingBox

        public Rectangle2D getBoundingBox()
        Get bounding box, according to file (not computed from features)
        Returns:
        bounding box for shapefilew, as stored in header.
      • getFeatures

        public List getFeatures()
        Get a List of all the GisFeatures in the shapefile. This is very fast after the constructor has been called, since it is created during construction.
        Returns:
        a List of features
      • getFeatures

        public List<EsriShapefile.EsriFeature> getFeatures​(Rectangle2D bBox)
        Get a List of all the features in the shapefile that intersect the specified bounding box. This requires testing every feature in the List created at construction, so it's faster to just give a bounding box o the constructor if you will only do this once.
        Parameters:
        bBox - specifying the bounding box with which all the returned features bounding boxes have a non-empty intersection.
        Returns:
        a new list of features in the shapefile whose bounding boxes intersect the specified bounding box.