Class ShapefileFeatureLoader
ShapeFeature instances
without any assumptions about the attribute schema or geometry type.
This loader is the generic counterpart to the schema-specific
ShapefileCountryLoader and ShapefileCityLoader. It is
appropriate for any shapefile layer whose content is not known at compile
time — rivers, lakes, urban areas, administrative boundaries at any level,
protected areas, coastlines, and so on.
Supported geometry types
ShapefileGeometryReader.TYPE_POINT— single pointsShapefileGeometryReader.TYPE_MULTIPOINT— multiple points per featureShapefileGeometryReader.TYPE_POLYLINE— connected line segments (rivers, roads, coastlines)ShapefileGeometryReader.TYPE_POLYGON— filled areas (lakes, land cover, urban footprints)
Null-shape records are silently skipped.
Attribute loading
All .dbf fields are included in each feature's property map.
Values are trimmed strings; callers use
ShapeFeature.getProperty(String) to retrieve them by field name.
No field names are required or assumed.
Coordinate handling
Input coordinates must be WGS84 or NAD83/GRS80 geographic degrees
(longitude, latitude order). NAD83 is treated as WGS84 without datum
transformation, which is appropriate for map display. If a companion .prj
exists, it is validated and incompatible or unrecognized coordinate systems
are rejected. If it is absent, WGS84 is assumed. Coordinates are converted
to radians and longitude is wrapped to (-π, π] before being stored.
File layout contract
The .dbf companion file is derived from the .shp path
by replacing the extension. Both files must reside in the same directory
with the same base name. The .shx index file is not required;
records are read sequentially from the .shp file directly.
Usage
ShapefileFeatureLoader loader = new ShapefileFeatureLoader();
// Load rivers
List<ShapeFeature> rivers = loader.load(Path.of("ne_10m_rivers_lake_centerlines.shp"));
ShapeFeatureStyle riverStyle = new ShapeFeatureStyle()
.strokeColor(new Color(0x6B9FD4))
.strokeWidth(0.8f);
mapView.addLayer(new ShapeFeatureRenderer(rivers, riverStyle));
// Load lakes
List<ShapeFeature> lakes = loader.load(Path.of("ne_10m_lakes.shp"));
ShapeFeatureStyle lakeStyle = new ShapeFeatureStyle()
.fillColor(new Color(0x6B9FD4))
.strokeColor(new Color(0x4A7FB5))
.strokeWidth(0.5f)
.labelField("name");
mapView.addLayer(new ShapeFeatureRenderer(lakes, lakeStyle));
This class is stateless and thread-safe; a single instance may be reused
across multiple load(java.nio.file.Path) calls.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionLoads all features from the shapefile at the given path.
-
Constructor Details
-
ShapefileFeatureLoader
public ShapefileFeatureLoader()Creates a new loader. No configuration is required; all behaviour is determined by the shapefile itself and theShapeFeatureStyleapplied at render time.
-
-
Method Details
-
load
Loads all features from the shapefile at the given path.Opens the
.shpgeometry file and the companion.dbfattribute file (derived by replacing the extension). Both files are read sequentially and the results are combined into oneShapeFeatureper shapefile record.- Parameters:
shpPath- path to the.shpfile; the companion.dbfmust exist in the same directory with the same base name; must not benull- Returns:
- unmodifiable list of
ShapeFeatureinstances in file order; nevernull - Throws:
IOException- if either file cannot be opened or a parse error occurs
-