Class GeoJsonCountryLoader
- All Implemented Interfaces:
ICountryLoader
FeatureCollection.
Designed primarily for Natural Earth 10m cultural vectors, but tolerates minor schema variations. Features with missing required properties or unsupported geometry types are silently skipped rather than causing a parse failure.
Expected GeoJSON schema
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"ADMIN": "United States of America",
"ISO_A3": "USA"
},
"geometry": {
"type": "Polygon" | "MultiPolygon",
"coordinates": [...] // degrees, longitude first
}
}, ...
]
}
Coordinate handling
Input coordinates are in degrees (longitude, latitude order as required
by GeoJSON RFC 7946). They are converted to radians and the longitude is
wrapped to (-π, π] before being stored in the returned
GeoJsonCountryLoader.CountryFeature.
Thread safety
This class has no mutable state. The internal ObjectMapper is
thread-safe for reading and may be shared freely. The returned lists are
unmodifiable.
This class is not instantiable.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classImmutable representation of a single country feature consisting of an administrative name, an ISO-3166-1 alpha-3 code, and one or more polygon rings expressed as lists of geographic points in radians. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionLoads country features from the given filesystem path.loadFromResource(String resourcePath) Loads country features from a classpath resource.loadFromResourceStatic(String resourcePath) Static convenience overload: loads country features from a classpath resource.loadStatic(Path geoJsonPath) Static convenience overload: loads country features from a GeoJSON file.
-
Constructor Details
-
GeoJsonCountryLoader
public GeoJsonCountryLoader()No-arg constructor required for use as anICountryLoaderinstance.
-
-
Method Details
-
load
Loads country features from the given filesystem path.The path may point to the primary file of a multi-file format (e.g. the
— delegates to.shpfile of a shapefile set) or to a self-contained file (e.g. a.geojsonfile). Implementations are responsible for locating any companion files (e.g..dbf,.shx) relative to the supplied path.loadStatic(Path).- Specified by:
loadin interfaceICountryLoader- Parameters:
path- path to the data file; must not benull- Returns:
- unmodifiable list of country features; never
null - Throws:
IOException- if the file cannot be read or parsed
-
loadFromResource
public List<GeoJsonCountryLoader.CountryFeature> loadFromResource(String resourcePath) throws IOException Loads country features from a classpath resource.The resource path must be absolute (begin with
— delegates to/) so thatClass.getResourceAsStream(String)resolves it correctly. For multi-file formats this method may not be supportable (e.g. a shapefile set cannot be fully represented as a single classpath resource); in that case implementations should throwUnsupportedOperationExceptionwith a clear message.loadFromResourceStatic(String).- Specified by:
loadFromResourcein interfaceICountryLoader- Parameters:
resourcePath- absolute classpath resource path; must not benull- Returns:
- unmodifiable list of country features; never
null - Throws:
IOException- if the resource cannot be read or parsed
-
loadStatic
public static List<GeoJsonCountryLoader.CountryFeature> loadStatic(Path geoJsonPath) throws IOException Static convenience overload: loads country features from a GeoJSON file.- Parameters:
geoJsonPath- path to a GeoJSONFeatureCollectionfile- Returns:
- unmodifiable list of
GeoJsonCountryLoader.CountryFeatureinstances - Throws:
IOException- if an I/O or JSON parse error occurs
-
loadFromResourceStatic
public static List<GeoJsonCountryLoader.CountryFeature> loadFromResourceStatic(String resourcePath) throws IOException Static convenience overload: loads country features from a classpath resource. The resource path must begin with/.- Parameters:
resourcePath- absolute classpath resource path- Returns:
- unmodifiable list of
GeoJsonCountryLoader.CountryFeatureinstances - Throws:
IOException- if the resource cannot be found, read, or parsed
-