Package org.hortonmachine.gears.utils
Class CrsUtilities
- java.lang.Object
-
- org.hortonmachine.gears.utils.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.CoordinateReferenceSystemWGS84static intWGS84_SRIDstatic org.geotools.geometry.jts.ReferencedEnvelopeWORLD
-
Constructor Summary
Constructors Constructor Description CrsUtilities()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringgetCodeFromCrs(org.opengis.referencing.crs.CoordinateReferenceSystem crs)Get the code from aCoordinateReferenceSystem.static org.opengis.referencing.crs.CoordinateReferenceSystemgetCrsFromEpsg(String epsgPlusCode)static org.opengis.referencing.crs.CoordinateReferenceSystemgetCrsFromEpsg(String epsgPlusCode, Boolean doLatitudeFirst)Get theCoordinateReferenceSystemfrom an epsg definition.static org.opengis.referencing.crs.CoordinateReferenceSystemgetCrsFromSrid(int srid)Get theCoordinateReferenceSystemfrom a epsg srid number.static org.opengis.referencing.crs.CoordinateReferenceSystemgetCrsFromSrid(int srid, Boolean doLatitudeFirst)static doublegetMetersAsWGS84(double meters, org.locationtech.jts.geom.Coordinate c)Converts meters to degrees, based on a given coordinate in 90 degrees direction.static intgetSrid(org.opengis.referencing.crs.CoordinateReferenceSystem crs)static booleanisCrsValid(org.opengis.referencing.crs.CoordinateReferenceSystem crs)Checks if a crs is valid, i.e.static org.opengis.referencing.crs.CoordinateReferenceSystemreadProjectionFile(String filePath, String extension)Reads aCoordinateReferenceSystemfrom a prj file.static voidreproject(org.opengis.referencing.crs.CoordinateReferenceSystem from, org.opengis.referencing.crs.CoordinateReferenceSystem to, Object[] geometries)Reproject a set of geometriesstatic voidreproject(org.opengis.referencing.crs.CoordinateReferenceSystem from, org.opengis.referencing.crs.CoordinateReferenceSystem to, org.locationtech.jts.geom.Coordinate[] coordinates)Reproject a set of coordinates.static voidwriteProjectionFile(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
-
WGS84_SRID
public static final int WGS84_SRID
- See Also:
- Constant Field Values
-
WORLD
public static final org.geotools.geometry.jts.ReferencedEnvelope WORLD
-
-
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. Ifnull, the crs is written to filePath directly.crs- theCoordinateReferenceSystemto write.- Throws:
IOException
-
readProjectionFile
public static org.opengis.referencing.crs.CoordinateReferenceSystem readProjectionFile(String filePath, String extension) throws Exception
Reads aCoordinateReferenceSystemfrom 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. Ifnullit 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 ExceptionReproject a set of geometries- Parameters:
from- the starting crsto- the destination crsgeometries- 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 ExceptionReproject a set of coordinates.- Parameters:
from- the starting crsto- the destination crscoordinates- 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 aCoordinateReferenceSystem.- 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 theCoordinateReferenceSystemfrom 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 theCoordinateReferenceSystemfrom an epsg definition.- Parameters:
epsgPlusCode- the code as EPSG:4326doLatitudeFirst- seeCRS.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.
-
-