Class CustomProjection
- java.lang.Object
-
- org.openstreetmap.josm.data.projection.AbstractProjection
-
- org.openstreetmap.josm.data.projection.CustomProjection
-
- All Implemented Interfaces:
Projecting
,Projection
public class CustomProjection extends AbstractProjection
Custom projection. Inspired by PROJ.4 and Proj4J.- Since:
- 5072
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CustomProjection.Param
Proj4-like projection parameters.(package private) static class
CustomProjection.Polarity
-
Field Summary
Fields Modifier and Type Field Description private String
axis
Starting in PROJ 4.8.0, the+axis
argument can be used to control the axis orientation of the coordinate system.protected Bounds
bounds
protected String
code
private static List<String>
LON_LAT_VALUES
private static double
METER_PER_UNIT_DEGREE
private double
metersPerUnitWMTS
protected String
name
private EnumMap<CustomProjection.Polarity,EastNorth>
polesEN
protected String
pref
pref String that defines the projection null means fall back mode (Mercator)private static Map<String,Double>
PRIME_MERIDANS
private static Map<String,Double>
UNITS_TO_METERS
-
Constructor Summary
Constructors Constructor Description CustomProjection()
Constructs a new emptyCustomProjection
.CustomProjection(String pref)
Constructs a newCustomProjection
with given parameters.CustomProjection(String name, String code, String pref)
Constructs a newCustomProjection
with given name, code and parameters.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ProjectionBounds
getEastNorthBoundsBox(ProjectionBounds box, Projection boxProjection)
Get a box in east/north space of this projection, that fully contains an east/north box of another projection.Integer
getEpsgCode()
Returns The EPSG Code of this CRS.Bounds
getLatLonBoundsBox(ProjectionBounds r)
Find lat/lon-box containing all the area of a given rectangle in east/north space.double
getMetersPerUnit()
Factor to convert units of east/north coordinates to meters.private static EastNorth
getPointAlong(int i, int n, ProjectionBounds r)
private EastNorth
getPole(CustomProjection.Polarity whichPole)
private static Map<String,Double>
getPrimeMeridians()
private static Map<String,Double>
getUnitsToMeters()
Bounds
getWorldBoundsLatLon()
Get the bounds of the world.boolean
isGeographic()
Return true, if a geographic coordinate reference system is represented.static double
parseAngle(String angleStr, String parameterName)
Convert an angle string to a double valuestatic Bounds
parseBounds(String boundsStr)
Converts a string to a bounds objectDatum
parseDatum(Map<String,String> parameters, Ellipsoid ellps)
Gets the datumstatic double
parseDouble(String doubleStr, String parameterName)
static double
parseDouble(Map<String,String> parameters, String parameterName)
Ellipsoid
parseEllipsoid(Map<String,String> parameters)
Gets the ellipsoidstatic Map<String,String>
parseParameterList(String pref, boolean ignoreUnknownParameter)
Parse a parameter list to key=value pairs.Proj
parseProjection(Map<String,String> parameters, Ellipsoid ellps)
Gets a projection using the given ellipsoidDatum
parseToWGS84(String paramList, Ellipsoid ellps)
Parsetowgs84
parameter.static Map<String,String>
resolveInits(Map<String,String> parameters, boolean ignoreUnknownParameter)
Recursive resolution of +init includes.boolean
switchXY()
Does this projection natural order of coordinates is North East, instead of East NorthString
toCode()
Default implementation of toCode().String
toString()
Describe the projection in one or two words.void
update(String pref)
Updates thisCustomProjection
with given parameters.-
Methods inherited from class org.openstreetmap.josm.data.projection.AbstractProjection
convertDegreeMinuteSecond, convertMinuteSecond, eastNorth2latlon, eastNorth2latlonClamped, getBaseProjection, getCentralMeridian, getDatum, getDefaultZoomInPPD, getEllipsoid, getFalseEasting, getFalseNorthing, getProj, getProjectingsForArea, getScaleFactor, getToMeter, getWorldBoundsBoxEastNorth, latlon2eastNorth, visitOutline
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.openstreetmap.josm.data.projection.Projecting
getCacheKey, latlon2eastNorth
-
-
-
-
Field Detail
-
METER_PER_UNIT_DEGREE
private static final double METER_PER_UNIT_DEGREE
- See Also:
- Constant Field Values
-
UNITS_TO_METERS
private static final Map<String,Double> UNITS_TO_METERS
-
PRIME_MERIDANS
private static final Map<String,Double> PRIME_MERIDANS
-
pref
protected String pref
pref String that defines the projection null means fall back mode (Mercator)
-
metersPerUnitWMTS
private double metersPerUnitWMTS
-
axis
private String axis
Starting in PROJ 4.8.0, the+axis
argument can be used to control the axis orientation of the coordinate system. The default orientation is "easting, northing, up" but directions can be flipped, or axes flipped using combinations of the axes in the+axis
switch. The values are:e
(Easting),w
(Westing),n
(Northing),s
(Southing),u
(Up),d
(Down); Examples:+axis=enu
(the default easting, northing, elevation),+axis=neu
(northing, easting, up; useful for "lat/long" geographic coordinates, or south orientated transverse mercator),+axis=wnu
(westing, northing, up - some planetary coordinate systems have "west positive" coordinate systems)See proj4.org
-
LON_LAT_VALUES
private static final List<String> LON_LAT_VALUES
-
polesEN
private EnumMap<CustomProjection.Polarity,EastNorth> polesEN
-
-
Constructor Detail
-
CustomProjection
public CustomProjection()
Constructs a new emptyCustomProjection
.
-
CustomProjection
public CustomProjection(String pref)
Constructs a newCustomProjection
with given parameters.- Parameters:
pref
- String containing projection parameters (ex: "+proj=tmerc +lon_0=-3 +k_0=0.9996 +x_0=500000 +ellps=WGS84 +datum=WGS84 +bounds=-8,-5,2,85")
-
CustomProjection
public CustomProjection(String name, String code, String pref)
Constructs a newCustomProjection
with given name, code and parameters.- Parameters:
name
- describe projection in one or two wordscode
- unique code for this projection - may be nullpref
- the string that defines the custom projection
-
-
Method Detail
-
update
public final void update(String pref) throws ProjectionConfigurationException
Updates thisCustomProjection
with given parameters.- Parameters:
pref
- String containing projection parameters (ex: "+proj=lonlat +ellps=WGS84 +datum=WGS84 +bounds=-180,-90,180,90")- Throws:
ProjectionConfigurationException
- ifpref
cannot be parsed properly
-
parseParameterList
public static Map<String,String> parseParameterList(String pref, boolean ignoreUnknownParameter) throws ProjectionConfigurationException
Parse a parameter list to key=value pairs.- Parameters:
pref
- the parameter listignoreUnknownParameter
- true, if unknown parameter should not raise exception- Returns:
- parameters map
- Throws:
ProjectionConfigurationException
- in case of invalid parameter
-
resolveInits
public static Map<String,String> resolveInits(Map<String,String> parameters, boolean ignoreUnknownParameter) throws ProjectionConfigurationException
Recursive resolution of +init includes.- Parameters:
parameters
- parameters mapignoreUnknownParameter
- true, if unknown parameter should not raise exception- Returns:
- parameters map with +init includes resolved
- Throws:
ProjectionConfigurationException
- in case of invalid parameter
-
parseEllipsoid
public Ellipsoid parseEllipsoid(Map<String,String> parameters) throws ProjectionConfigurationException
Gets the ellipsoid- Parameters:
parameters
- The parameters to get the value from- Returns:
- The Ellipsoid as specified with the parameters
- Throws:
ProjectionConfigurationException
- in case of invalid parameters
-
parseDatum
public Datum parseDatum(Map<String,String> parameters, Ellipsoid ellps) throws ProjectionConfigurationException
Gets the datum- Parameters:
parameters
- The parameters to get the value fromellps
- The ellisoid that was previously computed- Returns:
- The Datum as specified with the parameters
- Throws:
ProjectionConfigurationException
- in case of invalid parameters
-
parseToWGS84
public Datum parseToWGS84(String paramList, Ellipsoid ellps) throws ProjectionConfigurationException
Parsetowgs84
parameter.- Parameters:
paramList
- List of parameter arguments (expected: 3 or 7)ellps
- ellipsoid- Returns:
- parsed datum (
ThreeParameterDatum
orSevenParameterDatum
) - Throws:
ProjectionConfigurationException
- if the arguments cannot be parsed
-
parseProjection
public Proj parseProjection(Map<String,String> parameters, Ellipsoid ellps) throws ProjectionConfigurationException
Gets a projection using the given ellipsoid- Parameters:
parameters
- Additional parametersellps
- TheEllipsoid
- Returns:
- The projection
- Throws:
ProjectionConfigurationException
- in case of invalid parameters
-
parseBounds
public static Bounds parseBounds(String boundsStr) throws ProjectionConfigurationException
Converts a string to a bounds object- Parameters:
boundsStr
- The string as comma separated list of angles.- Returns:
- The bounds.
- Throws:
ProjectionConfigurationException
- in case of invalid parameter- See Also:
parseAngle(String, String)
-
parseDouble
public static double parseDouble(Map<String,String> parameters, String parameterName) throws ProjectionConfigurationException
- Throws:
ProjectionConfigurationException
-
parseDouble
public static double parseDouble(String doubleStr, String parameterName) throws ProjectionConfigurationException
- Throws:
ProjectionConfigurationException
-
parseAngle
public static double parseAngle(String angleStr, String parameterName) throws ProjectionConfigurationException
Convert an angle string to a double value- Parameters:
angleStr
- The string. e.g. -1.1 or 50d10'3"parameterName
- Only for error message.- Returns:
- The angle value, in degrees.
- Throws:
ProjectionConfigurationException
- in case of invalid parameter
-
getEpsgCode
public Integer getEpsgCode()
Description copied from class:AbstractProjection
Returns The EPSG Code of this CRS.- Specified by:
getEpsgCode
in classAbstractProjection
- Returns:
- The EPSG Code of this CRS, null if it doesn't have one.
-
toCode
public String toCode()
Description copied from class:AbstractProjection
Default implementation of toCode(). Should be overridden, if there is no EPSG code for this CRS.- Specified by:
toCode
in interfaceProjection
- Overrides:
toCode
in classAbstractProjection
- Returns:
- the projection identifier
-
getWorldBoundsLatLon
public Bounds getWorldBoundsLatLon()
Description copied from interface:Projection
Get the bounds of the world.- Returns:
- the supported lat/lon rectangle for this projection
-
toString
public String toString()
Description copied from interface:Projection
Describe the projection in one or two words.- Specified by:
toString
in interfaceProjection
- Overrides:
toString
in classObject
- Returns:
- the name / description
-
getMetersPerUnit
public double getMetersPerUnit()
Factor to convert units of east/north coordinates to meters. When east/north coordinates are in degrees (geographic CRS), the scale at the equator is taken, i.e. 360 degrees corresponds to the length of the equator in meters.- Returns:
- factor to convert units to meter
-
switchXY
public boolean switchXY()
Description copied from interface:Projection
Does this projection natural order of coordinates is North East, instead of East North- Returns:
- true if natural order of coordinates is North East, false if East North
-
getUnitsToMeters
private static Map<String,Double> getUnitsToMeters()
-
getPrimeMeridians
private static Map<String,Double> getPrimeMeridians()
-
getPointAlong
private static EastNorth getPointAlong(int i, int n, ProjectionBounds r)
-
getPole
private EastNorth getPole(CustomProjection.Polarity whichPole)
-
getLatLonBoundsBox
public Bounds getLatLonBoundsBox(ProjectionBounds r)
Description copied from interface:Projection
Find lat/lon-box containing all the area of a given rectangle in east/north space. This is an approximate method. Points outside of the world should be ignored.- Parameters:
r
- the rectangle in projected space- Returns:
- minimum lat/lon box, that when projected, covers
pb
-
getEastNorthBoundsBox
public ProjectionBounds getEastNorthBoundsBox(ProjectionBounds box, Projection boxProjection)
Description copied from interface:Projection
Get a box in east/north space of this projection, that fully contains an east/north box of another projection. Reprojecting a rectangular box from one projection to another may distort/rotate the shape of the box, so in general one needs to walk along the boundary in small steps to get a reliable result. This is an approximate method.- Parameters:
box
- the east/north box given in projectionboxProjection
boxProjection
- the projection ofbox
- Returns:
- an east/north box in this projection, containing the given box
-
isGeographic
public boolean isGeographic()
Return true, if a geographic coordinate reference system is represented. I.e. if it returns latitude/longitude values rather than Cartesian east/north coordinates on a flat surface.- Returns:
- true, if it is geographic
- Since:
- 12792
-
-