private void checkLinearRing(LinearRing<P> ring, CoordinateReferenceSystem<P> crs) { if (ring == null) throw new IllegalArgumentException("NULL linear ring is not valid."); if (ring.isEmpty()) throw new IllegalArgumentException("Empty linear ring is not valid."); if (!ring.getCoordinateReferenceSystem().equals(crs)) throw new IllegalArgumentException("Linear ring with different CRS than exterior boundary."); }
public CountingPositionSequenceBuilder(CoordinateReferenceSystem<P> crs) { delegate = PositionSequenceBuilders.variableSized(crs.getPositionClass()); dim = crs.getCoordinateDimension(); }
/** * Returns the coordinate dimension, i.e. the number of axes in this coordinate reference system. * * @return the coordinate dimension */ public int getCoordinateDimension() { return getCoordinateSystem().getCoordinateDimension(); }
@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())); }
public static <Q extends Position> Geometry<Q> forceToCrs(Geometry<?> geometry, CoordinateReferenceSystem<Q> crs) { if (crs == null || geometry == null) return (Geometry<Q>) geometry; if (crs.equals(geometry.getCoordinateReferenceSystem())) return (Geometry<Q>) geometry; if (geometry instanceof Simple) { Simple simple = (Simple) geometry; PositionSequence<Q> positions = Positions.copy(geometry.getPositions(), crs.getPositionClass()); return Geometries.mkGeometry(simple.getClass(), positions, crs); } else {
EnvelopeVisitor(CoordinateReferenceSystem<P> crs) { this.crs = crs; coordinates = new double[crs.getCoordinateDimension()]; }
/** * Registers a {@code CoordinateReferenceSystem} in the registry. * * @param crs the {@code CoordinateReferenceSystem} to register */ public static void registerCoordinateReferenceSystem(CoordinateReferenceSystem<?> crs) { crsMap.put(crs.getCrsId(), crs); }
@Override public int hashCode() { int result = crs != null ? crs.hashCode() : 0; result = 31 * result + (lowerLeft != null ? lowerLeft.hashCode() : 0); result = 31 * result + (upperRight != null ? upperRight.hashCode() : 0); return result; }
/** * Gets the coordinate value for the specified axis * * * @param axis the CoordinateSystemAxis for which to get the coordinate * @return the coordinate value for the specified axis * @throws IllegalArgumentException if the specified axis is not present in the {@code CoordinateReferenceSystem} * of this instance * * @Deprecated Use {@code getCoordinate(CoordinateSystemAxis axis)} * */ @Deprecated public double getCoordinate(CoordinateSystemAxis axis, CoordinateReferenceSystem<?> crs) { int idx = crs.getAxisIndex(axis); if (idx == -1) throw new IllegalArgumentException("Not an axis of this coordinate reference system."); return getCoordinate(axis.getNormalOrder()); }
@SuppressWarnings("unchecked") public static <P extends Position> CompoundCoordinateReferenceSystem<?> combine (CoordinateReferenceSystem<P> base, SingleCoordinateReferenceSystem ods) { if (base instanceof CompoundCoordinateReferenceSystem) { List<SingleCoordinateReferenceSystem<?>> components = ((CompoundCoordinateReferenceSystem<P>) base) .getComponents(); List<SingleCoordinateReferenceSystem<?>> nc = new ArrayList<SingleCoordinateReferenceSystem<?>>(components); nc.add(ods); return new CompoundCoordinateReferenceSystem(base.getName() + "+" + ods.getName(), nc.toArray( new SingleCoordinateReferenceSystem[0])); } else if (base instanceof SingleCoordinateReferenceSystem) { SingleCoordinateReferenceSystem<P> single = (SingleCoordinateReferenceSystem<P>) base; return new CompoundCoordinateReferenceSystem(single.getName() + "+" + ods.getName(), single, ods); } throw new UnsupportedOperationException("Unsupported type of coordinate reference system"); }
public static Geographic2DCoordinateReferenceSystem getGeographicCoordinateReferenceSystemForEPSG(int epsgCode) { CoordinateReferenceSystem<? extends Position> crs = crsMap.get(CrsId.valueOf(epsgCode)); if (crs == null) return null; if (crs.getPositionClass().equals(G2D.class)) { return (Geographic2DCoordinateReferenceSystem) crs; } throw new RuntimeException(String.format("EPSG code %d doesn't refer to geographic projection system", epsgCode)); }
private <P extends Position> void readPosition(ByteBuffer byteBuffer, double[] coordinates, CoordinateReferenceSystem<P> crs) { for (int ci = 0; ci < crs.getCoordinateDimension(); ci++) { coordinates[ci] = byteBuffer.getDouble(); } }
void setCoordinateReferenceSystem(CoordinateReferenceSystem<?> crs) { this.crs = crs; this.srid = crs.getCrsId().getCode(); }
private <P extends Position> CoordinateSequence fromCoordinateArray(Coordinate[] coordinates, CoordinateReferenceSystem<P> crs) { PositionSequenceBuilder<P> builder = PositionSequenceBuilders.fixedSized(coordinates.length, crs.getPositionClass()); double[] ordinates = new double[crs.getCoordinateDimension()]; for (Coordinate co : coordinates) { copy(co, ordinates, crs); builder.add(ordinates); } return (CoordinateSequence) builder.toPositionSequence(); }
public static ProjectedCoordinateReferenceSystem getProjectedCoordinateReferenceSystemForEPSG(int epsgCode) { CoordinateReferenceSystem<? extends Position> crs = crsMap.get(CrsId.valueOf(epsgCode)); if (crs.getPositionClass().equals(C2D.class)) { return (ProjectedCoordinateReferenceSystem) crs; } throw new RuntimeException(String.format("EPSG code %d doesn't refer to geographic projection system", epsgCode)); }
private void checkCompatibleCRS(Geometry<?> geometry, Geometry<?> other) { if (!geometry.getCoordinateReferenceSystem().equals(other.getCoordinateReferenceSystem())) { throw new IllegalArgumentException("Geometries have different CRS's"); } }
/** * Create an instance using the specified coordinates and <code>CoordinateReferenceSystem</code>. * * If the {@code CoordinateReferenceSystem} has coordinate dimension > 2, the Z/M coordinate values will be set to 0 * in the envelope * * @param minC1 minimum first coordinate * @param minC2 minimum second coordinate * @param maxC1 maximum first coordinate * @param maxC2 maximum second coordinate * @param crs the <code>CoordinateReferenceSystem</code> for the coordinates * of the envelope. */ public Envelope(double minC1, double minC2, double maxC1, double maxC2, CoordinateReferenceSystem<P> crs) { if (crs == null) { throw new IllegalArgumentException("Null CRS argument not allowed"); } double[] lowerLeft = new double[crs.getCoordinateDimension()]; double[] upperRight = new double[crs.getCoordinateDimension()]; lowerLeft[0] = minC1 <= maxC1 ? minC1 : maxC1; lowerLeft[1] = minC2 <= maxC2 ? minC2 : maxC2; upperRight[0] = minC1 > maxC1 ? minC1 : maxC1; upperRight[1] = minC2 > maxC2 ? minC2 : maxC2; this.crs = crs; this.lowerLeft = Positions.mkPosition(crs, lowerLeft); this.upperRight = Positions.mkPosition(crs, upperRight); }
public String toString() { StringBuilder builder = new StringBuilder(getCoordinateReferenceSystem().getCrsId().toString()); builder.append("LL: ") .append(this.lowerLeft.toString()) .append(" - UR: ") .append(this.upperRight.toString()); return builder.toString(); }
/** * Returns the index of the specified axis in this {@code CoordinateReferenceSystem}, or * -1 if it is not an axis of this system. * * @param axis the axis to look up * @return the index of the specified axis in this {@code CoordinateReferenceSystem} */ public int getAxisIndex(CoordinateSystemAxis axis) { return getCoordinateSystem().getAxisIndex(axis); }
private <P extends Position> PositionSequence<P> readPositions(int numPos, ByteBuffer byteBuffer, CoordinateReferenceSystem<P> crs) { PositionSequenceBuilder<P> psBuilder = PositionSequenceBuilders.fixedSized(numPos, crs.getPositionClass()); double[] coordinates = new double[crs.getCoordinateDimension()]; for (int i = 0; i < numPos; i++) { readPosition(byteBuffer, coordinates, crs); psBuilder.add(coordinates); } return psBuilder.toPositionSequence(); }