Class AxisSwapper

java.lang.Object
nz.org.riskscape.engine.output.AxisSwapper

public class AxisSwapper extends Object

Utility for swapping Geometry coordinate order, typically so that it's in the right order for writing where an output format demands a particular axis order.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final org.locationtech.jts.geom.CoordinateFilter
     
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    AxisSwapper(org.geotools.api.referencing.crs.CoordinateReferenceSystem newCrs)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    getForceEpsgDefined(org.geotools.api.referencing.crs.CoordinateReferenceSystem crs)
    Returns an AxisSwapper that flips coordinates to the order defined in the CRS's canonical EPSG definition, or empty if the CRS is the canonical version for.
    getForceXY(org.geotools.api.referencing.crs.CoordinateReferenceSystem crs, URI storedAt, nz.org.riskscape.problem.ProblemSink problemSink)
    Returns an AxisSwapper that will flip coordinates to x-y ordering, or empty if the crs is already in x-y order.
    org.geotools.api.referencing.crs.CoordinateReferenceSystem
    A coordinate reference system with the desired ordering, or the original crs if none could be created
    org.locationtech.jts.geom.Geometry
    swapAxis(org.locationtech.jts.geom.Geometry geom)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • PROBLEMS

      public static final AxisSwapper.LocalProblems PROBLEMS
    • AXIS_SWAPPING_FILTER

      public static final org.locationtech.jts.geom.CoordinateFilter AXIS_SWAPPING_FILTER
  • Constructor Details

    • AxisSwapper

      public AxisSwapper(org.geotools.api.referencing.crs.CoordinateReferenceSystem newCrs)
  • Method Details

    • getForceXY

      public static Optional<AxisSwapper> getForceXY(org.geotools.api.referencing.crs.CoordinateReferenceSystem crs, URI storedAt, nz.org.riskscape.problem.ProblemSink problemSink)

      Returns an AxisSwapper that will flip coordinates to x-y ordering, or empty if the crs is already in x-y order. If a flipped crs could not be created, a swapper is still returned, but newCrs is set to be the original y-x crs. If required, we could change this to be optional, but at the moment we would prefer an incorrect prj to no prj, so it is set to simplify writer logic.

      Parameters:
      crs - the crs that geometries are in.
      storedAt - used for context if there's a problem with the CRS
      problemSink - a place to dump a problem if no flipped CRS could be created
    • getForceEpsgDefined

      public static Optional<AxisSwapper> getForceEpsgDefined(org.geotools.api.referencing.crs.CoordinateReferenceSystem crs)

      Returns an AxisSwapper that flips coordinates to the order defined in the CRS's canonical EPSG definition, or empty if the CRS is the canonical version for. We say canonical definition, as a CRS can loosely match another CRS by ESPG code but have different axis order (such as if it's been loaded from a shapefile). This method will normalize the axis order so that it matches the canonically defined order. Or empty if no EPSG code could be matched or if the crs already matches the EPSG defined order.

    • swapAxis

      public org.locationtech.jts.geom.Geometry swapAxis(org.locationtech.jts.geom.Geometry geom)
      Returns:
      a new geometry based on the input geometry, but with X and Y coordinates swapped
    • getNewCrs

      public org.geotools.api.referencing.crs.CoordinateReferenceSystem getNewCrs()

      A coordinate reference system with the desired ordering, or the original crs if none could be created