Class CrsUtilities


  • public class CrsUtilities
    extends Object
    Utilities for CRS.
    Since:
    0.7.0
    Author:
    Andrea Antonello (www.hydrologis.com)
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static org.opengis.referencing.crs.CoordinateReferenceSystem WGS84  
      static int WGS84_SRID  
      static org.geotools.geometry.jts.ReferencedEnvelope WORLD  
    • Constructor Summary

      Constructors 
      Constructor Description
      CrsUtilities()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static String getCodeFromCrs​(org.opengis.referencing.crs.CoordinateReferenceSystem crs)
      Get the code from a CoordinateReferenceSystem.
      static org.opengis.referencing.crs.CoordinateReferenceSystem getCrsFromEpsg​(String epsgPlusCode)  
      static org.opengis.referencing.crs.CoordinateReferenceSystem getCrsFromEpsg​(String epsgPlusCode, Boolean doLatitudeFirst)
      Get the CoordinateReferenceSystem from an epsg definition.
      static org.opengis.referencing.crs.CoordinateReferenceSystem getCrsFromSrid​(int srid)
      Get the CoordinateReferenceSystem from a epsg srid number.
      static org.opengis.referencing.crs.CoordinateReferenceSystem getCrsFromSrid​(int srid, Boolean doLatitudeFirst)  
      static double getMetersAsWGS84​(double meters, org.locationtech.jts.geom.Coordinate c)
      Converts meters to degrees, based on a given coordinate in 90 degrees direction.
      static int getSrid​(org.opengis.referencing.crs.CoordinateReferenceSystem crs)  
      static boolean isCrsValid​(org.opengis.referencing.crs.CoordinateReferenceSystem crs)
      Checks if a crs is valid, i.e.
      static org.opengis.referencing.crs.CoordinateReferenceSystem readProjectionFile​(String filePath, String extension)
      Reads a CoordinateReferenceSystem from a prj file.
      static void reproject​(org.opengis.referencing.crs.CoordinateReferenceSystem from, org.opengis.referencing.crs.CoordinateReferenceSystem to, Object[] geometries)
      Reproject a set of geometries
      static void reproject​(org.opengis.referencing.crs.CoordinateReferenceSystem from, org.opengis.referencing.crs.CoordinateReferenceSystem to, org.locationtech.jts.geom.Coordinate[] coordinates)
      Reproject a set of coordinates.
      static void writeProjectionFile​(String filePath, String extention, org.opengis.referencing.crs.CoordinateReferenceSystem crs)
      Fill the prj file with the actual map projection.
    • Field Detail

      • WGS84

        public static final org.opengis.referencing.crs.CoordinateReferenceSystem WGS84
      • WORLD

        public static final org.geotools.geometry.jts.ReferencedEnvelope WORLD
    • Constructor Detail

      • CrsUtilities

        public CrsUtilities()
    • Method Detail

      • isCrsValid

        public static boolean isCrsValid​(org.opengis.referencing.crs.CoordinateReferenceSystem crs)
        Checks if a crs is valid, i.e. if it is not a wildcard default one.
        Parameters:
        crs - the crs to check.
      • writeProjectionFile

        public static void writeProjectionFile​(String filePath,
                                               String extention,
                                               org.opengis.referencing.crs.CoordinateReferenceSystem crs)
                                        throws IOException
        Fill the prj file with the actual map projection.
        Parameters:
        filePath - the path to the regarding data or prj file.
        extention - the extention of the data file. If null, the crs is written to filePath directly.
        crs - the CoordinateReferenceSystem to write.
        Throws:
        IOException
      • readProjectionFile

        public static org.opengis.referencing.crs.CoordinateReferenceSystem readProjectionFile​(String filePath,
                                                                                               String extension)
                                                                                        throws Exception
        Reads a CoordinateReferenceSystem from a prj file.
        Parameters:
        filePath - the path to the prj file or the connected datafile it sidecar file for.
        extension - the extension of the data file. If null it is assumed to be prj.
        Returns:
        the read CoordinateReferenceSystem.
        Throws:
        Exception
      • reproject

        public static void reproject​(org.opengis.referencing.crs.CoordinateReferenceSystem from,
                                     org.opengis.referencing.crs.CoordinateReferenceSystem to,
                                     Object[] geometries)
                              throws Exception
        Reproject a set of geometries
        Parameters:
        from - the starting crs
        to - the destination crs
        geometries - the array of geometries, wrapped into an Object array
        Throws:
        Exception
      • reproject

        public static void reproject​(org.opengis.referencing.crs.CoordinateReferenceSystem from,
                                     org.opengis.referencing.crs.CoordinateReferenceSystem to,
                                     org.locationtech.jts.geom.Coordinate[] coordinates)
                              throws Exception
        Reproject a set of coordinates.
        Parameters:
        from - the starting crs
        to - the destination crs
        coordinates - the array of coordinates, wrapped into an Object array
        Throws:
        Exception
      • getCodeFromCrs

        public static String getCodeFromCrs​(org.opengis.referencing.crs.CoordinateReferenceSystem crs)
                                     throws Exception
        Get the code from a CoordinateReferenceSystem.
        Parameters:
        crs - the crs to get the code from.
        Returns:
        the code, that can be used with CRS.decode(String) to recreate the crs.
        Throws:
        Exception
      • getSrid

        public static int getSrid​(org.opengis.referencing.crs.CoordinateReferenceSystem crs)
                           throws org.opengis.referencing.FactoryException
        Throws:
        org.opengis.referencing.FactoryException
      • getCrsFromSrid

        public static org.opengis.referencing.crs.CoordinateReferenceSystem getCrsFromSrid​(int srid)
        Get the CoordinateReferenceSystem from a epsg srid number.
        Parameters:
        srid - the srid number.
        Returns:
        the crs or null.
      • getCrsFromSrid

        public static org.opengis.referencing.crs.CoordinateReferenceSystem getCrsFromSrid​(int srid,
                                                                                           Boolean doLatitudeFirst)
      • getCrsFromEpsg

        public static org.opengis.referencing.crs.CoordinateReferenceSystem getCrsFromEpsg​(String epsgPlusCode,
                                                                                           Boolean doLatitudeFirst)
        Get the CoordinateReferenceSystem from an epsg definition.
        Parameters:
        epsgPlusCode - the code as EPSG:4326
        doLatitudeFirst - see CRS.decode(String, boolean)
        Returns:
        the crs.
      • getCrsFromEpsg

        public static org.opengis.referencing.crs.CoordinateReferenceSystem getCrsFromEpsg​(String epsgPlusCode)
      • getMetersAsWGS84

        public static double getMetersAsWGS84​(double meters,
                                              org.locationtech.jts.geom.Coordinate c)
        Converts meters to degrees, based on a given coordinate in 90 degrees direction.
        Parameters:
        meters - the meters to convert.
        c - the position to consider.
        Returns:
        the converted degrees.