/** * Returns a {@code CoordinateReferenceSystem} derived from the specified @{code {@link CoordinateReferenceSystem}} * but extended with the specified axis * * @param baseCrs the base Coordinate Reference System * @param verticalUnit the Unit for the Vertical axis (or null if not required) * @param measureUnit the Unit for measures (or null if not required) * @return a {@code CoordinateReferenceSystem} with at least the specified dimension, and using the specified * crs as base */ public static CoordinateReferenceSystem<?> mkCoordinateReferenceSystem( CoordinateReferenceSystem<?> baseCrs, LinearUnit verticalUnit, LinearUnit measureUnit) { CoordinateReferenceSystem<?> result = baseCrs; if (verticalUnit != null && !hasVerticalAxis(baseCrs)) { result = addVerticalSystem(result, verticalUnit); } if (measureUnit != null && !hasMeasureAxis(baseCrs)) { result = addLinearSystem(result, measureUnit); } return result; }
public static <P extends Position, R extends P> CompoundCoordinateReferenceSystem<R> addVerticalSystem (CoordinateReferenceSystem<P> base, Class<R> resultCSPtype, LinearUnit unit) { return combine(base, mkVertical(unit), resultCSPtype); }
public static <P extends Position> boolean hasMeasureAxis(CoordinateReferenceSystem<P> crs) { return hasAxisOrder(crs, 3); }
private void validateCrs(CoordinateReferenceSystem<?> crs, boolean hasM, boolean hasZ) { if ( (hasM && ! hasMeasureAxis(crs)) || (hasZ && ! hasVerticalAxis(crs))) { throw new WkbDecodeException("WKB inconsistent with specified Coordinate Reference System"); } }
CoordinateReferenceSystem<?> getCRS(int srid, boolean hasZValues, boolean hasMValues ) { CoordinateReferenceSystem<?> crs = CrsRegistry.getCoordinateReferenceSystemForEPSG(srid, DEFAULT_CRS); if (hasZValues) { crs = CoordinateReferenceSystems.addVerticalSystem(crs, Unit.METER); } if (hasMValues) { crs = CoordinateReferenceSystems.addLinearSystem(crs, Unit.METER); } return (CoordinateReferenceSystem<?>) crs; }
/** * @inheritDoc */ @Override public <P extends C2D, M extends C2D & Measured> Geometry<M> measureOnLength( final Geometry<P> geometry, final Class<M> positionTypeMarker, final boolean keepBeginMeasure) { if (geometry == null) throw new IllegalArgumentException("Geometry parameter must not be NULL"); if (positionTypeMarker == null) throw new IllegalArgumentException("PositionTypeMarker parameter must not be NULL"); if (geometry.getGeometryType() != GeometryType.LINESTRING && geometry.getGeometryType() != GeometryType.MULTILINESTRING) { throw new IllegalArgumentException("Geometry parameter must be of type LineString or MultiLineString"); } final CoordinateReferenceSystem<P> sourceCRS = geometry.getCoordinateReferenceSystem(); final CoordinateReferenceSystem<M> measuredVariant = !hasMeasureAxis(sourceCRS) ? (CoordinateReferenceSystem<M>) addLinearSystem(sourceCRS, Unit.METER) : (CoordinateReferenceSystem<M>)sourceCRS; if (!measuredVariant.getPositionClass().equals(positionTypeMarker)) { throw new IllegalArgumentException(String.format( "Inconsistent types: measured CRS has position type %s, but positionTypeMarker is %s.", measuredVariant.getPositionClass().getName(), positionTypeMarker.getName())); } return new OnLengthMeasureOp<M>(geometry, measuredVariant, keepBeginMeasure).execute(); }
public static GeographicCoordinateReferenceSystem mkGeographic(AngularUnit unit) { return mkGeographic(CrsId.UNDEFINED, unit); }
/** * Creates a generic projected coordinate reference system using the specified units of length for coordinates. * <p/> * A generic system is one without a precisely defined Coordinate Reference System * * @param unit the unit to use for the planar coordinates. * @return a {@code CoordinateReferenceSystem} with the specified length units */ public static ProjectedCoordinateReferenceSystem mkProjected(LinearUnit unit) { return mkProjected(CrsId.UNDEFINED, unit); }
public static CoordinateReferenceSystem<?> mkCoordinateReferenceSystem( int epsgCode, LinearUnit verticalUnit, LinearUnit measureUnit) { return mkCoordinateReferenceSystem( CrsRegistry.getCoordinateReferenceSystemForEPSG(epsgCode, PROJECTED_2D_METER), verticalUnit, measureUnit ); }
/** * @param base * @param ods * @param resultCSPtype the Position class for the result of the combined coordinate reference system * @param <P> * @param <R> * @return */ @SuppressWarnings("unchecked") public static <P extends Position, R extends P> CompoundCoordinateReferenceSystem<R> combine (CoordinateReferenceSystem<P> base, SingleCoordinateReferenceSystem ods, Class<R> resultCSPtype) { return (CompoundCoordinateReferenceSystem<R>) combine(base, ods); }
private <T extends C2D & Measured> LineString<T> measure(LineString<T> geometry) { CoordinateReferenceSystem<T> crs = geometry.getCoordinateReferenceSystem(); PositionSequence originalPoints = geometry.getPositions(); PositionSequenceBuilder<T> builder = PositionSequenceBuilders.fixedSized(originalPoints.size(), geometry.getPositionClass()); int mIdx = hasVerticalAxis(crs) ? 3 :2; double[] coordinates = new double[geometry.getCoordinateDimension()]; double[] prevCoordinates = new double[geometry.getCoordinateDimension()]; for (int i = 0; i < originalPoints.size(); i++) { originalPoints.getCoordinates(i, coordinates); if (i > 0) { length += Math.hypot(coordinates[0] - prevCoordinates[0], coordinates[1] - prevCoordinates[1]); } coordinates[mIdx] = length; builder.add(coordinates); prevCoordinates[0] = coordinates[0]; prevCoordinates[1] = coordinates[1]; } return new LineString<T>(builder.toPositionSequence(), crs); }
<P extends Position> void copyCoordinate(int index, double[] coords, CoordinateReferenceSystem<P> crs) { coords[0] = points[2 * index]; coords[1] = points[2 * index + 1]; int idx = 2; if ( hasZValues() ) { assert ( hasVerticalAxis(crs) ); coords[idx++] = zValues[index]; } if ( hasMValues() ) { assert ( CoordinateReferenceSystems.hasMeasureAxis(crs) ); coords[idx] = mValues[index]; } }
private CoordinateReferenceSystem<?> determineCRS(SDOGeometry nativeGeom) { final int srid = nativeGeom.getSRID(); CoordinateReferenceSystem<?> crs = CrsRegistry.ifAbsentReturnProjected2D(srid); if (getVerticalDimension(nativeGeom) > 0) { crs = CoordinateReferenceSystems.addVerticalSystem(crs, LinearUnit.METER); } if (getLinearReferenceDimension(nativeGeom) > 0) { crs = CoordinateReferenceSystems.addLinearSystem(crs, LinearUnit.METER); } return crs; }
/** * Returns the registered coordinate reference system, or when unavailable in the registry, create a new Geographic 2D system and register * this on-the-fly. * * @param epsgCode the code to look up * @return a CoordinateReferenceSystem with the specified epsg code */ public static CoordinateReferenceSystem<?> ifAbsentReturnGeographic2D(int epsgCode) { return computeIfAbsent(CrsId.valueOf(epsgCode), key -> CoordinateReferenceSystems.mkGeographic(key, AngularUnit.RADIAN)); }
/** * Returns the registered coordinate reference system, or when unavailable in the registry, create a new Projected 2D system and register * this on-the-fly. * * @param epsgCode the code to look up * @return a CoordinateReferenceSystem with the specified epsg code */ public static CoordinateReferenceSystem<?> ifAbsentReturnProjected2D(int epsgCode) { return computeIfAbsent(CrsId.valueOf(epsgCode), key -> CoordinateReferenceSystems.mkProjected(key, LinearUnit.METER)); }
@SuppressWarnings("unchecked") public static <P extends Position> CoordinateReferenceSystem<P> mkCoordinateReferenceSystem( CoordinateReferenceSystem<?> baseCrs, LinearUnit verticalUnit, LinearUnit measureUnit, Class<P> positionType) { CoordinateReferenceSystem<?> crs = mkCoordinateReferenceSystem(baseCrs, verticalUnit, measureUnit); if (crs.getPositionClass().equals(positionType)) { return (CoordinateReferenceSystem<P>)crs; } throw new IllegalArgumentException(format("Invalid positionClass: %s not equals %s", crs.getPositionClass().getName(), positionType.getName())); }
private <P extends Position> void copy(Coordinate co, double[] ordinates, CoordinateReferenceSystem<P> crs) { ordinates[0] = co.getX(); ordinates[1] = co.getY(); boolean hasVerticalAxis = hasVerticalAxis(crs); if (hasVerticalAxis) { ordinates[2] = co.getZ(); } if (hasMeasureAxis(crs)) { int idxM = hasVerticalAxis ? 3 : 2; ordinates[idxM] = co.getM(); } }
private CoordinateReferenceSystem<?> ensureZM(CoordinateReferenceSystem<?> crs, boolean needZ, boolean needM) { CoordinateReferenceSystem<?> compound = crs; if (needZ && ! hasVerticalAxis(compound)) { compound = addVerticalSystem(compound, Unit.METER); } if (needM && ! hasMeasureAxis(compound)) { compound = addLinearSystem(compound, Unit.METER); } if (forceToCRS && !compound.equals(crs)) { throw new WktDecodeException("WKT inconsistent with specified Coordinate Reference System"); } return compound; }