Class GeoJSONGeometryWriter

java.lang.Object
com.massifmaps.geometry.GeoJSONGeometryWriter

public class GeoJSONGeometryWriter extends Object
A GeoJSON writer. Generates human-readable GeoJSON representation of the geometry, feature or feature collection.
Supports both 2D and 3D coordinate serialization.
  • Constructor Details

    • GeoJSONGeometryWriter

      public GeoJSONGeometryWriter()
      Constructs a new GeoJSONGeometryWriter object with default settings.
  • Method Details

    • getSourceProjection

      public Projection getSourceProjection()
      Returns the current source projection. If source projection is set, all geometry
      coordinates will be converted from given coordinate system to WGS84.
      Returns:
      The current source projection or null.
    • setSourceProjection

      public void setSourceProjection(Projection proj)
      Sets the current source projection. If source projection is set, all geometry
      coordinates will be converted from given coordinate system to WGS84.
      Parameters:
      proj - The new source projection or null.
    • getZ

      public boolean getZ()
      Returns the state of Z coordinate serialization.
      Returns:
      True if Z coordinate is stored in GeoJSON output, false otherwise. The default is false.
    • setZ

      public void setZ(boolean z)
      Sets the state of Z coordinate serialization.
      Parameters:
      z - True when Z coordinate should be serialized, false otherwise.
    • writeGeometry

      public String writeGeometry(Geometry geometry)
      Creates a GeoJSON string corresponding to the specified geometry.
      Parameters:
      geometry - The geometry to write.
      Returns:
      The corresponding GeoJSON string.
      Throws:
      Exception - If string could not be generated.
    • writeFeature

      public String writeFeature(Feature feature)
      Creates a GeoJSON string corresponding to the specified feature.
      Parameters:
      feature - The feature to write.
      Returns:
      The corresponding GeoJSON string.
      Throws:
      Exception - If string could not be generated.
    • writeFeatureCollection

      public String writeFeatureCollection(FeatureCollection featureCollection)
      Creates a GeoJSON string corresponding to the specified feature collection.
      Parameters:
      featureCollection - The feature collection to write.
      Returns:
      The corresponding GeoJSON string.
      Throws:
      Exception - If string could not be generated.