ShapefileLayerFactory

Builds a RenderableLayer from an ESRI shapefile. Two entry points:

  • createLayer (URL form) fetches foo.shp plus the foo.dbf and foo.prj sidecars over HTTP, matching WebWorldWind's URL+callback pattern.

  • createLayer (raw-bytes form) parses already-loaded buffers. Use this for bundled assets or any case where the caller is doing its own IO.

The optional shapeConfiguration callback runs once per record (after attribute join) and lets the caller swap in custom ShapeAttributes / PlacemarkAttributes, label the shape, extrude polygons, etc. Returning null drops the record.

Renderables produced (matching WebWorldWind):

  • Point / PointZ / PointM → one Placemark per point

  • MultiPoint / MultiPointZ / MultiPointM → one Placemark per point

  • Polyline / PolylineZ / PolylineM → one Path per record (one per part)

  • Polygon / PolygonZ / PolygonM → one Polygon per record (parts as boundaries)

Functions

Link copied to clipboard
suspend fun createLayer(shpUrl: String, displayName: String? = null, shapeConfiguration: (ShapefileRecord) -> ShapefileShapeConfiguration? = { ShapefileShapeConfiguration() }): RenderableLayer

Load a shapefile from a URL pointing at the .shp file. The factory will derive the .dbf and .prj sidecar URLs by replacing the extension and fetch all three concurrently-ish (sequentially, matching the reference). Sidecars that 404 or fail to download are tolerated and the layer is built without them.

suspend fun createLayer(shpBytes: ByteArray, dbfBytes: ByteArray? = null, prjBytes: ByteArray? = null, cpgBytes: ByteArray? = null, displayName: String? = null, shapeConfiguration: (ShapefileRecord) -> ShapefileShapeConfiguration? = { ShapefileShapeConfiguration() }): RenderableLayer

Build a layer from already-loaded buffers. The DBF, PRJ, and CPG buffers are all optional; if absent, attributes default to empty maps, the shapefile is assumed to be geographic, and DBF text decoding falls back to Latin-1.

Link copied to clipboard
suspend fun ShapefileLayerFactory.createLayerFromZip(zipBytes: ByteArray, displayName: String? = null, shapeConfiguration: (ShapefileRecord) -> ShapefileShapeConfiguration? = { ShapefileShapeConfiguration() }): RenderableLayer

Loads a shapefile distributed as a ZIP archive (the canonical packaging on most data portals). The first .shp, .dbf, .prj, and .cpg entries found are routed through ShapefileLayerFactory.createLayer. Entries deeper in subdirectories are accepted too, but only the first match of each extension is used — ZIP archives occasionally bundle multiple shapefiles together, and picking one deterministically is better than guessing.

Link copied to clipboard
fun emitRecordRenderables(shapefile: Shapefile, shapeConfiguration: (ShapefileRecord) -> ShapefileShapeConfiguration? = { ShapefileShapeConfiguration() }, consumer: (record: ShapefileRecord, renderable: Renderable) -> Unit)

Iterate shapefile records, run shapeConfiguration per record, and pass each resulting Renderable back through consumer alongside the originating record. The base createLayer entry points use this internally; bulk feature sources (e.g. earth.worldwind.formats.shapefile.ShapefileBulkFeatureSource) call it directly to intercept each renderable + its DBF attributes for cache encoding without rebuilding the shape-construction logic.