Class GeoJsonCityLoader

java.lang.Object
edu.cnu.mdi.mapping.loader.GeoJsonCityLoader
All Implemented Interfaces:
ICityLoader

public final class GeoJsonCityLoader extends Object implements ICityLoader
Utility for loading city (populated place) point features from a GeoJSON 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.

  • Constructor Details

    • GeoJsonCityLoader

      public GeoJsonCityLoader()
      No-arg constructor required for use as an ICityLoader instance.
  • Method Details

    • load

      public List<GeoJsonCityLoader.CityFeature> load(Path path) throws IOException
      Loads city features from the given filesystem path.

      The path may point to the primary file of a multi-file format (e.g. the .shp file of a shapefile set) or to a self-contained file (e.g. a .geojson file). Implementations are responsible for locating companion files (e.g. .dbf, .shx) relative to the supplied path.

      — delegates to loadStatic(Path).
      Specified by:
      load in interface ICityLoader
      Parameters:
      path - path to the data file; must not be null
      Returns:
      unmodifiable list of city features; never null
      Throws:
      IOException - if the file cannot be read or parsed
    • loadFromResource

      public List<GeoJsonCityLoader.CityFeature> loadFromResource(String resourcePath) throws IOException
      Loads city features from a classpath resource.

      The resource path must be absolute (begin with /). For multi-file formats this may not be supportable; implementations should throw UnsupportedOperationException with a clear message in that case.

      — delegates to loadFromResourceStatic(String).
      Specified by:
      loadFromResource in interface ICityLoader
      Parameters:
      resourcePath - absolute classpath resource path; must not be null
      Returns:
      unmodifiable list of city features; never null
      Throws:
      IOException - if the resource cannot be read or parsed
    • loadStatic

      public static List<GeoJsonCityLoader.CityFeature> loadStatic(Path geoJsonPath) throws IOException
      Static convenience overload: loads city features from a GeoJSON file.
      Parameters:
      geoJsonPath - path to a GeoJSON FeatureCollection file
      Returns:
      unmodifiable list of GeoJsonCityLoader.CityFeature instances
      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.CityFeature instances
      Throws:
      IOException - if the resource cannot be found, read, or parsed