Class ShapeFeature
.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
- All coordinates are in radians (longitude, latitude order)
with longitude wrapped to (-π, π], matching the convention used by
all
IMapProjectionimplementations. getRings()is non-empty for polygon and polyline features (ShapefileGeometryReader.TYPE_POLYGON,ShapefileGeometryReader.TYPE_POLYLINE). Each element is one ring or part.getPoints()is non-empty for point features (ShapefileGeometryReader.TYPE_POINT,ShapefileGeometryReader.TYPE_MULTIPOINT).- Both lists are unmodifiable.
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 Summary
ConstructorsConstructorDescriptionShapeFeature(int shapeType, List<List<Point2D.Double>> rings, List<Point2D.Double> points, Map<String, String> properties) Constructs a new shapefile feature. -
Method Summary
Modifier and TypeMethodDescriptionReturns the unmodifiable list of points for point and multi-point features.Returns the unmodifiable property map containing all.dbfattribute fields for this feature.getProperty(String fieldName) Returns the value of the named property as a string, ornullif the field is not present in this feature's attribute table.getProperty(String fieldName, String defaultValue) Returns the value of the named property as a string, ordefaultValueif the field is absent or empty.doublegetPropertyDouble(String fieldName, double defaultValue) Returns the value of the named property parsed as adouble, ordefaultValueif the field is absent, empty, or not numeric.intgetPropertyInt(String fieldName, int defaultValue) Returns the value of the named property parsed as anint, ordefaultValueif the field is absent, empty, or not numeric.getRings()Returns the unmodifiable list of rings or parts for polygon and polyline features.intReturns the shape type of this feature, corresponding to one of theTYPE_*constants inShapefileGeometryReader.booleanisPoint()Returnstrueif this feature is a point or multi-point.booleanReturnstrueif this feature is a polygon.booleanReturnstrueif this feature is a polyline (also called a line string or arc in other formats).toString()
-
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 (seeShapefileGeometryReaderTYPE_*constants)rings- ring/part lists for polygon/polyline features; must not benull; useCollections.emptyList()for point featurespoints- point list for point/multipoint features; must not benull; useCollections.emptyList()for ring-based featuresproperties- attribute map from the.dbftable; must not benull
-
-
Method Details
-
getShapeType
public int getShapeType()Returns the shape type of this feature, corresponding to one of theTYPE_*constants inShapefileGeometryReader.- Returns:
- shape type (e.g.
ShapefileGeometryReader.TYPE_POLYGON)
-
isPolygon
public boolean isPolygon()Returnstrueif this feature is a polygon.- Returns:
trueforShapefileGeometryReader.TYPE_POLYGON
-
isPolyline
public boolean isPolyline()Returnstrueif this feature is a polyline (also called a line string or arc in other formats).- Returns:
trueforShapefileGeometryReader.TYPE_POLYLINE
-
isPoint
public boolean isPoint()Returnstrueif this feature is a point or multi-point.- Returns:
trueforShapefileGeometryReader.TYPE_POINTorShapefileGeometryReader.TYPE_MULTIPOINT
-
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
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
Returns the unmodifiable property map containing all.dbfattribute fields for this feature.Keys are field names exactly as stored in the
.dbfheader (typically upper-case for Natural Earth files). Values are trimmed strings and may be empty but notnull.- Returns:
- unmodifiable attribute map; never
null
-
getProperty
Returns the value of the named property as a string, ornullif the field is not present in this feature's attribute table.- Parameters:
fieldName- the.dbffield name (case-sensitive)- Returns:
- trimmed string value, or
nullif absent
-
getProperty
Returns the value of the named property as a string, ordefaultValueif the field is absent or empty.- Parameters:
fieldName- the.dbffield name (case-sensitive)defaultValue- value returned when the field is absent or empty- Returns:
- trimmed string value, or
defaultValue
-
getPropertyDouble
Returns the value of the named property parsed as adouble, ordefaultValueif the field is absent, empty, or not numeric.- Parameters:
fieldName- the.dbffield name (case-sensitive)defaultValue- value returned on parse failure- Returns:
- parsed double value, or
defaultValue
-
getPropertyInt
Returns the value of the named property parsed as anint, ordefaultValueif the field is absent, empty, or not numeric.- Parameters:
fieldName- the.dbffield name (case-sensitive)defaultValue- value returned on parse failure- Returns:
- parsed int value, or
defaultValue
-
toString
-