Class GeoJsonCityLoader
- All Implemented Interfaces:
ICityLoader
FeatureCollection.
Designed primarily for
Natural Earth 10m populated places data (e.g.
ne_10m_populated_places.geojson), but tolerates schema variations
such as mixed-case property names. Features with unsupported geometry types
or missing coordinate data are silently skipped.
Expected GeoJSON schema
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [longitude_degrees, latitude_degrees]
},
"properties": {
"NAME": "London",
"ADM0NAME": "United Kingdom",
"POP_MAX": 8908081,
"SCALERANK": 0
}
}, ...
]
}
Property name tolerance
The loader tries several case variants for each property (e.g.
NAME, name, Name) and accepts the first non-empty
match. Properties that are entirely absent result in a null string
or the sentinel value -1 for numeric fields.
Coordinate handling
Input coordinates are in degrees (GeoJSON RFC 7946 convention). They are
converted to radians and the longitude is wrapped to (-π, π] before storage.
All GeoJsonCityLoader.CityFeature coordinate accessors return radians.
Thread safety
This class has no mutable state. The shared ObjectMapper is
thread-safe for reading. Both load(Path) and
loadFromResource(String) return unmodifiable lists.
This class is not instantiable.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classImmutable representation of a single populated-place (city) feature. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionLoads city features from the given filesystem path.loadFromResource(String resourcePath) Loads city features from a classpath resource.static List<GeoJsonCityLoader.CityFeature> loadFromResourceStatic(String resourcePath) Static convenience overload: loads city features from a classpath resource.static List<GeoJsonCityLoader.CityFeature> loadStatic(Path geoJsonPath) Static convenience overload: loads city features from a GeoJSON file.
-
Constructor Details
-
GeoJsonCityLoader
public GeoJsonCityLoader()No-arg constructor required for use as anICityLoaderinstance.
-
-
Method Details
-
load
Loads city 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 companion files (e.g..dbf,.shx) relative to the supplied path.loadStatic(Path).- Specified by:
loadin interfaceICityLoader- Parameters:
path- path to the data file; must not benull- Returns:
- unmodifiable list of city features; never
null - Throws:
IOException- if the file cannot be read or parsed
-
loadFromResource
Loads city features from a classpath resource.The resource path must be absolute (begin with
— delegates to/). For multi-file formats this may not be supportable; implementations should throwUnsupportedOperationExceptionwith a clear message in that case.loadFromResourceStatic(String).- Specified by:
loadFromResourcein interfaceICityLoader- Parameters:
resourcePath- absolute classpath resource path; must not benull- Returns:
- unmodifiable list of city features; never
null - Throws:
IOException- if the resource cannot be read or parsed
-
loadStatic
Static convenience overload: loads city features from a GeoJSON file.- Parameters:
geoJsonPath- path to a GeoJSONFeatureCollectionfile- Returns:
- unmodifiable list of
GeoJsonCityLoader.CityFeatureinstances - Throws:
IOException- if an I/O or JSON parse error occurs
-
loadFromResourceStatic
public static List<GeoJsonCityLoader.CityFeature> loadFromResourceStatic(String resourcePath) throws IOException Static convenience overload: loads city features from a classpath resource. The resource path must begin with/.- Parameters:
resourcePath- absolute classpath resource path- Returns:
- unmodifiable list of
GeoJsonCityLoader.CityFeatureinstances - Throws:
IOException- if the resource cannot be found, read, or parsed
-