Shapefile

class Shapefile(shpBytes: ByteArray, val projection: PrjFile? = null, val attributes: DBaseFile? = null)

Parser for an ESRI shapefile (.shp). Reads the entire input eagerly into a List<ShapefileRecord> at construction time; iteration is then in-memory and allocation-free. Mirrors the behavior of WebWorldWind's Shapefile class.

Optional sidecar files can be supplied:

  • projection — .prj content; only the geographic-vs-projected distinction is used, matching the reference. Projected shapefiles are not supported (see PrjFile).

  • attributes — .dbf content; rows are matched to records by their 1-based index.

Spec: ESRI Shapefile Technical Description (July 1998), pages 4–5 (file header / record headers), pages 5–13 (per-shape-type record contents).

Constructors

Link copied to clipboard
constructor(shpBytes: ByteArray, projection: PrjFile? = null, attributes: DBaseFile? = null)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
Link copied to clipboard

File bounding rectangle as [minY, maxY, minX, maxX] (latitude, longitude for geographic shapefiles).

Link copied to clipboard

File length in bytes (the on-disk header value is in 16-bit words; doubled here).

Link copied to clipboard
Link copied to clipboard

Eager list of records. Materialized on first access via recordsSequence and cached. Preferred for small/medium shapefiles; use recordsSequence directly for huge files where the full list would dwarf heap.

Link copied to clipboard

Lazy iteration over the records in this shapefile. Each call walks the bytes from the start; iterators are independent so callers can take, filter, etc. without affecting other consumers. NULL records are silently skipped. DBF attributes (if attributes was supplied at construction) are joined by record-number index.

Link copied to clipboard
Link copied to clipboard