Class ShapeFeature

java.lang.Object
edu.cnu.mdi.mapping.shapefile.ShapeFeature

public final class ShapeFeature extends Object
Immutable representation of a single feature loaded from an arbitrary ESRI Shapefile — a geometry (polygon rings, polyline parts, or points) paired with an open-ended property bag drawn from the companion .dbf table.

Unlike GeoJsonCountryLoader.CountryFeature and GeoJsonCityLoader.CityFeature, which model fixed schemas (name, ISO code, population, etc.), ShapeFeature makes no assumptions about the attribute fields present in the file. Every .dbf column is stored as a trimmed string in getProperties() and callers retrieve values by field name.

Geometry conventions

Property access

Field names are stored exactly as they appear in the .dbf header (typically upper-case for Natural Earth data). Values are trimmed of whitespace. Missing fields return null from Map.get(Object).

Usage example


 ShapefileFeatureLoader loader = new ShapefileFeatureLoader();
 List<ShapeFeature> lakes = loader.load(Path.of("ne_10m_lakes.shp"));
 for (ShapeFeature lake : lakes) {
     String name = lake.getProperty("name");
     double area = lake.getPropertyDouble("scalerank", -1.0);
 }
 
  • Constructor Details

    • ShapeFeature

      public ShapeFeature(int shapeType, List<List<Point2D.Double>> rings, List<Point2D.Double> points, Map<String,String> properties)
      Constructs a new shapefile feature. All list and map parameters are stored directly (callers should pass unmodifiable views).
      Parameters:
      shapeType - shape type constant (see ShapefileGeometryReader TYPE_* constants)
      rings - ring/part lists for polygon/polyline features; must not be null; use Collections.emptyList() for point features
      points - point list for point/multipoint features; must not be null; use Collections.emptyList() for ring-based features
      properties - attribute map from the .dbf table; must not be null
  • Method Details

    • getShapeType

      public int getShapeType()
      Returns the shape type of this feature, corresponding to one of the TYPE_* constants in ShapefileGeometryReader.
      Returns:
      shape type (e.g. ShapefileGeometryReader.TYPE_POLYGON)
    • isPolygon

      public boolean isPolygon()
      Returns true if this feature is a polygon.
      Returns:
      true for ShapefileGeometryReader.TYPE_POLYGON
    • isPolyline

      public boolean isPolyline()
      Returns true if this feature is a polyline (also called a line string or arc in other formats).
      Returns:
      true for ShapefileGeometryReader.TYPE_POLYLINE
    • isPoint

      public boolean isPoint()
      Returns true if this feature is a point or multi-point.
      Returns:
      true for ShapefileGeometryReader.TYPE_POINT or ShapefileGeometryReader.TYPE_MULTIPOINT
    • getRings

      public List<List<Point2D.Double>> getRings()
      Returns the unmodifiable list of rings or parts for polygon and polyline features.

      For polygon features each element is one ring (outer shell or interior hole). For polyline features each element is one connected sequence of vertices (a "part" or arc). Empty for point features.

      All coordinates are in radians with longitude in (-π, π].

      Returns:
      unmodifiable list of rings/parts; never null
    • getPoints

      public List<Point2D.Double> getPoints()
      Returns the unmodifiable list of points for point and multi-point features. Empty for polygon and polyline features.

      All coordinates are in radians with longitude in (-π, π].

      Returns:
      unmodifiable list of points; never null
    • getProperties

      public Map<String,String> getProperties()
      Returns the unmodifiable property map containing all .dbf attribute fields for this feature.

      Keys are field names exactly as stored in the .dbf header (typically upper-case for Natural Earth files). Values are trimmed strings and may be empty but not null.

      Returns:
      unmodifiable attribute map; never null
    • getProperty

      public String getProperty(String fieldName)
      Returns the value of the named property as a string, or null if the field is not present in this feature's attribute table.
      Parameters:
      fieldName - the .dbf field name (case-sensitive)
      Returns:
      trimmed string value, or null if absent
    • getProperty

      public String getProperty(String fieldName, String defaultValue)
      Returns the value of the named property as a string, or defaultValue if the field is absent or empty.
      Parameters:
      fieldName - the .dbf field name (case-sensitive)
      defaultValue - value returned when the field is absent or empty
      Returns:
      trimmed string value, or defaultValue
    • getPropertyDouble

      public double getPropertyDouble(String fieldName, double defaultValue)
      Returns the value of the named property parsed as a double, or defaultValue if the field is absent, empty, or not numeric.
      Parameters:
      fieldName - the .dbf field name (case-sensitive)
      defaultValue - value returned on parse failure
      Returns:
      parsed double value, or defaultValue
    • getPropertyInt

      public int getPropertyInt(String fieldName, int defaultValue)
      Returns the value of the named property parsed as an int, or defaultValue if the field is absent, empty, or not numeric.
      Parameters:
      fieldName - the .dbf field name (case-sensitive)
      defaultValue - value returned on parse failure
      Returns:
      parsed int value, or defaultValue
    • toString

      public String toString()
      Overrides:
      toString in class Object