/** * Convert a value in this unit to the given unit if possible. * * @param value * to be converted * @param targetUnit * to convert to * @return the converted value or the same value if this unit equals given unit. * @throws IllegalArgumentException * if no conversion can be applied. */ public final double convert( final double value, final IUnit targetUnit ) { if ( this.equals( targetUnit ) ) { return value; } if ( canConvert( targetUnit ) ) { return ( value * scale ) / targetUnit.getScale(); } throw new IllegalArgumentException( "Can't convert from \"" + this + "\" to \"" + targetUnit + "\"." ); }
/** * Convert a value in this unit to the base unit, e.g. degree->radians * * @param value * to be converted * @return the converted value or the same value if this unit is a base unit. */ public final double toBaseUnits( final double value ) { if ( isBaseType() ) { return value; } return value * scale; }
result = createUnitFromString( uomAttribute ); if ( result == null ) { LOG.debug( "Trying to resolve the uri: " + uomAttribute + " from a gml:value/@uom node" ); CRSCodeType[] codes = unitID.getCodes(); for ( int i = 0; i < codes.length && result == null; ++i ) { result = createUnitFromString( codes[i].getOriginal() );
/** * @param params * the values to get the units or to_meter from. * @return a unit create from the +unit parameter or Unit.METRE if not found. * @throws CRSConfigurationException * if the given unit parameter could not be mapped to a valid deegree-crs unit. */ private Unit createUnit( Map<String, String> params ) throws CRSConfigurationException { Unit result = Unit.METRE; String tmpValue = params.remove( "units" ); if ( tmpValue != null && !"".equals( tmpValue.trim() ) ) { result = Unit.createUnitFromString( tmpValue ); if ( result == null ) { throw new CRSConfigurationException( Messages.getMessage( "CRS_CONFIG_PROJ4_UNKNOWN_UNIT", params.get( EPSG_PRE + "identifier" ), tmpValue ) ); } } else { tmpValue = params.remove( "to_meter" ); if ( tmpValue != null && !"".equals( tmpValue.trim() ) ) { result = new Unit( "Unknown", "unknown", Double.parseDouble( tmpValue ), Unit.METRE ); } } return result; }
/** * @return true if this is a base type */ public final boolean isBaseType() { return this.equals( this.baseType ); }
private void calcParams() { if ( getSourceCRS().getType() == CRSType.COMPOUND ) { this.hasHeight = true; defaultHeightValue = ( (ICompoundCRS) getSourceCRS() ).getDefaultHeight(); } else if ( getTargetCRS().getType() == CRSType.COMPOUND ) { this.hasHeight = true; defaultHeightValue = ( (ICompoundCRS) getTargetCRS() ).getDefaultHeight(); } else { this.hasHeight = false; defaultHeightValue = 0; } IEllipsoid ellipsoid = getSourceCRS().getGeodeticDatum().getEllipsoid(); semiMajorAxis = Unit.METRE.convert( ellipsoid.getSemiMajorAxis(), ellipsoid.getUnits() ); semiMinorAxis = Unit.METRE.convert( ellipsoid.getSemiMinorAxis(), ellipsoid.getUnits() ); squaredSemiMajorAxis = semiMajorAxis * semiMajorAxis; squaredSemiMinorAxis = semiMinorAxis * semiMinorAxis; squaredEccentricity = ellipsoid.getSquaredEccentricity(); // e2 = ( a2 - b2 ) / a2; ep2 = ( squaredSemiMajorAxis - squaredSemiMinorAxis ) / squaredSemiMinorAxis; }
throw new UnknownUnitException( "Unit name is missing" ); return Unit.createUnitFromString( name );
if ( ea != 0 ) { if ( ef != 0 || eb != 0 ) { IUnit u = Unit.createUnitFromString( "epsg:" + uom ); if ( u == null ) { LOG.warn( "Could not determine unit of measure of epsg:" + uom );
result = Unit.createUnitFromString( unitId ); if ( result == null ) { throw new CRSConfigurationException( Messages.getMessage( "CRS_CONFIG_PARSE_ERROR", "Units",