Class JTSHelper


  • public class JTSHelper
    extends Object
    Utility class for the Java Topology Suite.
    Since:
    1.0.0
    • Field Detail

      • COORDINATE_SWITCHING_FILTER

        public static final org.locationtech.jts.geom.CoordinateFilter COORDINATE_SWITCHING_FILTER
    • Constructor Detail

      • JTSHelper

        protected JTSHelper()
    • Method Detail

      • createGeometryFromWKT

        public static org.locationtech.jts.geom.Geometry createGeometryFromWKT​(String wkt,
                                                                               int srid)
                                                                        throws org.locationtech.jts.io.ParseException
        Creates a JTS Geometry from an WKT representation. Switches the coordinate order if needed.
        Parameters:
        wkt - WKT representation of the geometry
        srid - the SRID of the newly created geometry
        Returns:
        JTS Geometry object
        Throws:
        org.locationtech.jts.io.ParseException - If an error occurs
      • getWKTReaderForSRID

        public static org.locationtech.jts.io.WKTReader getWKTReaderForSRID​(int srid)
      • getCoordinatesString

        public static String getCoordinatesString​(org.locationtech.jts.geom.Geometry geom)
        Get the coordinates of a Geometry as String.
        Parameters:
        geom - Geometry to get coordinates
        Returns:
        Coordinates as String
      • getCoordinatesString

        public static String getCoordinatesString​(org.locationtech.jts.geom.Coordinate[] sourceCoords)
      • getCoordinateString

        protected static StringBuilder getCoordinateString​(StringBuilder builder,
                                                           org.locationtech.jts.geom.Coordinate coordinate)
      • createWKTPolygonFromEnvelope

        public static String createWKTPolygonFromEnvelope​(String lowerCorner,
                                                          String upperCorner)
        Creates a WKT Polygon representation from lower and upper corner values.
        Parameters:
        lowerCorner - Lower corner coordinates
        upperCorner - Upper corner coordinates
        Returns:
        WKT Polygon
      • createEnvelopeFromLowerUpperCorner

        public static org.locationtech.jts.geom.Envelope createEnvelopeFromLowerUpperCorner​(String lowerCorner,
                                                                                            String upperCorner)
      • createPolygonFromEnvelope

        public static org.locationtech.jts.geom.Geometry createPolygonFromEnvelope​(double[] envelope,
                                                                                   int srid)
      • createPolygonFromEnvelope

        public static org.locationtech.jts.geom.Geometry createPolygonFromEnvelope​(double minx,
                                                                                   double miny,
                                                                                   double maxx,
                                                                                   double maxy,
                                                                                   int srid)
      • switchCoordinateAxisOrder

        public static <G extends org.locationtech.jts.geom.Geometry> G switchCoordinateAxisOrder​(G geometry)
        Switches the coordinates of a JTS Geometry.
        Type Parameters:
        G - the geometry type
        Parameters:
        geometry - Geometry to switch coordinates.
        Returns:
        Geometry with switched coordinates
      • getGeometryFactory

        public static org.locationtech.jts.geom.GeometryFactory getGeometryFactory​(org.locationtech.jts.geom.Geometry geometry)
      • getGeometryFactoryForSRID

        public static org.locationtech.jts.geom.GeometryFactory getGeometryFactoryForSRID​(int srid)
      • getSwitchCoordinateGeometryFactoryForSRID

        public static org.n52.shetland.util.JTSHelper.SwitchCoordinateGeometryFactory getSwitchCoordinateGeometryFactoryForSRID​(int srid)
      • createWKTPointFromCoordinateString

        public static String createWKTPointFromCoordinateString​(String coordinates)
        Creates a WKT Point string form coordinate string.
        Parameters:
        coordinates - Coordinate string
        Returns:
        WKT Point string
      • isNotEmpty

        public static boolean isNotEmpty​(org.locationtech.jts.geom.Geometry geometry)
      • getExteriorRingCoordinatesFromPolygon

        public static org.locationtech.jts.geom.Coordinate[] getExteriorRingCoordinatesFromPolygon​(org.locationtech.jts.geom.Polygon polygon)
        Fix for Binary-Incompatible-Change in JTS 1.17.0 Polygon getExteriorRing() which returns LinearRing instead of a LineString. This changes occurs errors in the SOS with Hinernate/Geolatte until the 3rd party libraries have not updated to JTS 1.17.0.
        Parameters:
        polygon - polygon to get exterior ring from
        Returns:
        the coordinates