protected Literal clipToWorld(Literal geometry) { if(geometry != null) { Geometry g = geometry.evaluate(null, Geometry.class); if(g != null) { g.apply(new GeometryComponentFilter() { @Override public void filter(Geometry geom) { geom.apply(new CoordinateFilter() { @Override public void filter(Coordinate coord) { coord.setCoordinate(new Coordinate(clipLon(coord.x),clipLat(coord.y))); } }); } }); geometry = CommonFactoryFinder.getFilterFactory(null).literal(g); } } return geometry; }
private Geometry check(Geometry geometry) { if (maxCoordinatesInGeometry > 0) { int distanceTolerance = 10; while (geometry.getNumPoints() > maxCoordinatesInGeometry) { geometry = DouglasPeuckerSimplifier.simplify(geometry, distanceTolerance); distanceTolerance *= 2; } } if (roundCoordinates) { final double factor = Math.pow(10, roundNumberOfDecimals); geometry.apply(new CoordinateFilter() { @Override public void filter(Coordinate coord) { coord.x = Math.round(coord.x * factor) / factor; coord.y = Math.round(coord.y * factor) / factor; } }); } return geometry; }
protected Geometry transformJTSGeometry(Geometry geom, final CoordinateReferenceSystem sourceCRS, final CoordinateReferenceSystem crs) throws Exception { final MathTransform transform = CRS.findMathTransform(sourceCRS, crs, true); final Mutable<Boolean> anyChanged = new Mutable<Boolean>(false); geom = (Geometry) geom.clone(); geom.apply(new CoordinateFilter() { @Override public void filter(Coordinate c) { DirectPosition dpFrom = new DirectPosition2D(sourceCRS, c.x, c.y); DirectPosition dpTo = new DirectPosition2D(); try { transform.transform(dpFrom, dpTo); c.x = dpTo.getOrdinate(0); c.y = dpTo.getOrdinate(1); anyChanged.set(true); } catch (TransformException e) { LOG.warn("Failed to transform point " + c, e); } } }); if (anyChanged.get()) { geom.geometryChanged(); } return geom; }
/** * Finds a UTM projection and applies it to all coordinates of the given geom. * * @param orig * @return */ public static Geometry projectLonLatGeom(Geometry orig) { // TODO FIXME XXX: what about when the geoms cross zones? final Geometry geom = (Geometry) orig.clone(); geom.apply(new CoordinateFilter() { public void filter(Coordinate coord) { final ProjectedCoordinate converted = GeoUtils.convertLonLatToEuclidean(coord); coord.setCoordinate(converted); } }); geom.geometryChanged(); return geom; }
public static Geometry toMercator(Geometry geometry) { Geometry clone = (Geometry) geometry.clone(); clone.apply(new CoordinateFilter() { @Override public void filter(Coordinate coord) { coord.setCoordinate(new Coordinate(lon2x(coord.x), lat2y(coord.y), coord.z)); } }); clone.geometryChanged(); return clone; }
/** * @return a coordinate filter that applies the transformation to all coordinates it is given. */ public CoordinateFilter getCoordinateFilter() { return new CoordinateFilter() { @Override public void filter(Coordinate coord) { coord.setCoordinate(PolynomialTransformation.this.transform(coord)); } }; }
public IGeometry translate(IGeometry geom, final double tx, final double ty, final double tz) { try { Geometry jtsGeom = JtsGeOxygene.makeJtsGeom(geom); CoordinateFilter translateCoord = new CoordinateFilter() { @Override public void filter(Coordinate coord) { coord.x += tx; coord.y += ty; coord.z += tz; } }; jtsGeom.apply(translateCoord); IGeometry result = JtsGeOxygene.makeGeOxygeneGeom(jtsGeom); return result; } catch (Exception e) { JtsAlgorithms.logger .error(I18N.getString("JtsAlgorithms.TranslateError")); //$NON-NLS-1$ if (JtsAlgorithms.logger.isDebugEnabled()) { JtsAlgorithms.logger .debug(I18N.getString("JtsAlgorithms.Geometry") + ((geom != null) ? geom.toString() : I18N.getString("JtsAlgorithms.NullGeometry"))); //$NON-NLS-1$ //$NON-NLS-2$ JtsAlgorithms.logger.debug(e.getMessage()); } e.printStackTrace(); return null; } }
public ForwardTransformer (AbstractProjection proj) { _proj = proj; _filter = new CoordinateFilter() { private Coordinate temp = new Coordinate(); public void filter (Coordinate coord) { temp = _proj.forwardPoint(coord.x, coord.y, temp); coord.setCoordinate(temp); } }; }
/** * Moves g so that c is at (0,0). * @param g the Geometry to modify * @param c the point to move to the origin */ public void translate(Geometry g, final Coordinate delta) { g.apply(new CoordinateFilter() { public void filter(Coordinate coordinate) { coordinate.x += delta.x; coordinate.y += delta.y; } }); }
public void reproject(Geometry geometry, final CoordinateSystem source, final CoordinateSystem destination) { if (!wouldChangeValues(source, destination)) { return; } geometry.apply(new CoordinateFilter() { public void filter(Coordinate coord) { reproject(coord, source, destination); } }); geometry.setSRID(destination.getEPSGCode()); geometry.geometryChanged(); }
@Override public void apply(final CoordinateFilter filter) { filter.filter(getCoordinate()); filter.filter(GeometryUtils.toCoordinate(target.getLocation())); }
@Override public void apply(CoordinateFilter filter) { // Do nothing. This circle is not expected to be a complete geometry. }