Refine search
CoordinateReferenceSystem destCrs = CRS.decode("EPSG:4326"); Boolean latLon = null; if (crs != null) { CoordinateReferenceSystem sourceCrs = CRS.decode(crs); if (CRS.getAxisOrder(destCrs) == CRS.AxisOrder.NORTH_EAST) latLon = true; else if (CRS.getAxisOrder(destCrs) == CRS.AxisOrder.EAST_NORTH) DirectPosition2D orig = new DirectPosition2D(x, y); DirectPosition2D transformed = new DirectPosition2D(); mathTransform.transform(orig, transformed); lon = transformed.getY(); lat = transformed.getX(); lon = transformed.getX(); lat = transformed.getY();
/** Circumscribed rectangle (smallest) for full disk earth image */ public static Envelope2D circumscribeFullDisk(CoordinateReferenceSystem geosCRS) throws TransformException, FactoryException { if (!isGeostationaryCRS(geosCRS)) { return null; } MathTransform mt = CRS.findMathTransform(geosCRS, CRS.getProjectedCRS(geosCRS).getBaseCRS(), true); MathTransform imt = mt.inverse(); ParameterValueGroup parameters = CRS.getMapProjection(geosCRS).getParameterValues(); double semiMajorAxis = parameters.parameter("semi_major").doubleValue(); double satelliteHeight = parameters.parameter("satellite_height").doubleValue(); double centralMeridian = parameters.parameter("central_meridian").doubleValue(); DirectPosition2D dp2d = new DirectPosition2D(); double halfFoVRadians = Math.acos(semiMajorAxis / (satelliteHeight + semiMajorAxis)); double halfFoVDegrees = Math.toDegrees(halfFoVRadians); dp2d.setLocation(centralMeridian - halfFoVDegrees, 0.); imt.transform(dp2d, dp2d); double xMin = dp2d.getX(); dp2d.setLocation(centralMeridian + halfFoVDegrees, 0.); imt.transform(dp2d, dp2d); double xMax = dp2d.getX(); dp2d.setLocation(centralMeridian, -halfFoVDegrees); imt.transform(dp2d, dp2d); double yMin = dp2d.getY(); dp2d.setLocation(centralMeridian, halfFoVDegrees); imt.transform(dp2d, dp2d); double yMax = dp2d.getY(); return new Envelope2D(geosCRS, xMin, yMin, xMax - xMin, yMax - yMin); }
/** * Gets the mouse position in world coordinates. * * @return world position */ public DirectPosition2D getWorldPos() { return new DirectPosition2D( worldCoords.getCoordinateReferenceSystem(), worldCoords.x, worldCoords.y); }
/** * The contains test whether the coordinate p is within the circle. Triangle contains coordinate * if the distance between center and p is smaller then the radius that is reduced by tolerance. * This is used for triangulation when there are four points on one circle to avoid neverending * loop. * * @param p - the point to be tested * @return True if the circle contais p, False if not. */ protected boolean contains(DirectPosition p) { if (center.distance(new DirectPosition2D(p)) < (this.radius - tolerance)) { return true; } else { return false; } } }
public void testCRS_CH1903_LV03() throws NoSuchAuthorityCodeException, FactoryException, MismatchedDimensionException, TransformException { CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:4326", false); // WGS84 CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:21781", false); // CH1903_LV03 MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS, true); // test coordinate: Berne, old reference point // see // http://www.swisstopo.admin.ch/internet/swisstopo/en/home/topics/survey/sys/refsys/switzerland.html DirectPosition2D source = new DirectPosition2D(sourceCRS, 46.9510827861504654, 7.4386324175389165); DirectPosition2D result = new DirectPosition2D(); transform.transform(source, result); assertEquals(600000.0, result.x, 0.1); assertEquals(200000.0, result.y, 0.1); }
final GeneralDirectPosition centerPt = new GeneralDirectPosition(mt.getTargetDimensions()); final GeneralEnvelope transformed = transform(mt, envelope, centerPt); sourcePt = new GeneralDirectPosition(dimension); for (int j = 0; j < dimension; j++) { sourcePt.setOrdinate(j, envelope.getMedian(j)); sourcePt.setOrdinate(i, v1); transformed.add(targetPt = mt.transform(sourcePt, targetPt)); sourcePt.setOrdinate(i, v2); transformed.add(targetPt = mt.transform(sourcePt, targetPt)); sourcePt.setOrdinate(i, envelope.getMedian(i)); return transformed; .getCode()); double originY = fn.doubleValue(); DirectPosition2D origin = new DirectPosition2D(originX, originY); if (isPole(origin, sourceCRS)) { if (generalEnvelope.contains(origin)) { DirectPosition lower = generalEnvelope.getLowerCorner(); DirectPosition upper = generalEnvelope.getUpperCorner(); DirectPosition dest = new DirectPosition2D(); for (int lon = -180; lon <= 180; lon += 90) { lower.setOrdinate(i, lon);
public List<RasterImage> paint(String boundsCrs, Bbox bounds, double scale) throws RenderException { try { CoordinateReferenceSystem google = CRS.decode("EPSG:900913"); MathTransform googleToLayer = geoService.findMathTransform(google, CRS.decode(boundsCrs)); MathTransform layerToGoogle = googleToLayer.inverse(); DirectPosition2D center = new DirectPosition2D(0.5 * (bounds.getX() + bounds.getMaxX()), 0.5 * (bounds.getY() + bounds.getMaxY())); DirectPosition mapUpperLeft = getMapFromGoogleIndices(googleToLayer, indicesUpperLeft, tileLevel); DirectPosition mapLowerRight = getMapFromGoogleIndices(googleToLayer, indicesLowerRight, tileLevel); double width = mapLowerRight.getOrdinate(0) - mapUpperLeft.getOrdinate(0);
private double getUnitLength(String mapCrsKey, Bbox mapBounds) throws LayerException { try { if (null == mapBounds) { throw new LayerException(ExceptionCode.MAP_MAX_EXTENT_MISSING); } CoordinateReferenceSystem crs = CRS.decode(mapCrsKey); GeodeticCalculator calculator = new GeodeticCalculator(crs); calculator.setStartingPosition(new DirectPosition2D(crs, mapBounds.getX(), mapBounds.getY())); calculator.setDestinationPosition(new DirectPosition2D(crs, mapBounds.getMaxX(), mapBounds.getY())); double distance = calculator.getOrthodromicDistance(); return distance / mapBounds.getWidth(); } catch (FactoryException e) { throw new LayerException(e, ExceptionCode.LAYER_CRS_INIT_PROBLEM); } catch (TransformException e) { throw new LayerException(e, ExceptionCode.LAYER_CRS_INIT_PROBLEM); } }
private double calculateMapUnitPerGoogleMeter(MathTransform layerToGoogle, DirectPosition2D mapPosition) { try { DirectPosition p1 = layerToGoogle.transform(mapPosition, null); DirectPosition mapdx = new DirectPosition2D(mapPosition.x + 1, mapPosition.y); DirectPosition p2 = layerToGoogle.transform(mapdx, null); return 1. / (p2.getOrdinate(0) - p1.getOrdinate(0)); } catch (MismatchedDimensionException e) { log.warn("calculateMapUnitPerGoogleMeter() : transformation failed", e); return 0.653; } catch (TransformException e) { log.warn("calculateMapUnitPerGoogleMeter() : transformation failed", e); return 0.653; } }
MathTransform layerToMap = geoService.findMathTransform(CRS.decode(getLayerInfo().getCrs()), runtime.getCrs(boundsCrs)); MathTransform mapToLayer = layerToMap.inverse(); DirectPosition leftTop = new DirectPosition2D(bounds.getX(), bounds.getMaxY()); DirectPosition rightBottom = new DirectPosition2D(bounds.getMaxX(), bounds.getY()); mapToLayer.transform(leftTop, leftTop); mapToLayer.transform(rightBottom, rightBottom); Bbox layerBounds = new Bbox(leftTop.getCoordinates()[0], leftTop.getCoordinates()[1], rightBottom.getCoordinates()[0] - leftTop.getCoordinates()[0], rightBottom.getCoordinates()[1] - leftTop.getCoordinates()[1]); double layerScale = bounds.getWidth() * scale / layerBounds.getWidth();
crs = CRS.decode((String) srsName); } catch (NoSuchAuthorityCodeException e) { throw new IllegalArgumentException( } else { geom = new DirectPosition2D(crs); geom.setOrdinate(1, parameters.get(3).evaluate(object, Double.class)); geom.setOrdinate(0, parameters.get(2).evaluate(object, Double.class)); } else { } else { geom = new DirectPosition2D(); geom.setOrdinate(1, parameters.get(1).evaluate(object, Double.class)); geom.setOrdinate(0, param1.evaluate(object, Double.class));
private static boolean isPole(DirectPosition point, CoordinateReferenceSystem crs) { DirectPosition result = new DirectPosition2D(); GeographicCRS geographic; try { ProjectedCRS projectedCRS = getProjectedCRS(crs); if (projectedCRS != null) { geographic = projectedCRS.getBaseCRS(); MathTransform mt = CRS.findMathTransform(projectedCRS, geographic); mt.transform(point, result); } else if (crs instanceof GeographicCRS) { result = point; geographic = (GeographicCRS) crs; } else { return false; } } catch (MismatchedDimensionException | TransformException | FactoryException e) { return false; } final double EPS = 1e-6; if (getAxisOrder(geographic) == AxisOrder.NORTH_EAST) { return Math.abs(result.getOrdinate(0) - 90) < EPS || Math.abs(result.getOrdinate(0) + 90) < EPS; } else { return Math.abs(result.getOrdinate(1) - 90) < EPS || Math.abs(result.getOrdinate(1) + 90) < EPS; } }
Point2D worldPos = new Point2D.Double(x, y); at.inverseTransform(screenPos, worldPos); DirectPosition2D fromPos = new DirectPosition2D(worldPos.getX(), worldPos.getY()); DirectPosition2D toPos = new DirectPosition2D(); MathTransform mt = CRS.findMathTransform( bbox.getCoordinateReferenceSystem(), getReader().requestCRS, true); mt.transform(fromPos, toPos); GetMapRequest mapRequest = getReader().mapRequest; return getReader().getFeatureInfo(toPos, infoFormat, featureCount, mapRequest);
private static void expandEnvelopeByLongitude( double longitude, DirectPosition input, GeneralEnvelope transformed, CoordinateReferenceSystem sourceCRS) { try { MathTransform mt = findMathTransform(sourceCRS, DefaultGeographicCRS.WGS84); DirectPosition2D pos = new DirectPosition2D(sourceCRS); mt.transform(input, pos); pos.setOrdinate(0, longitude); mt.inverse().transform(pos, pos); transformed.add(pos); } catch (Exception e) { LOGGER.log( Level.FINER, "Tried to expand target envelope to include longitude " + longitude + " but failed. This is not necesseraly and issue, " + "this is a best effort attempt to handle the polar stereographic " + "pole singularity during reprojection", e); } }
assertThat(circumscribed, is(notNullValue())); final DirectPosition2D p = new DirectPosition2D(); p.setLocation(circumscribed.getCenterX(), circumscribed.getMaxY()); sphericalGeosToGeog.transform(p, p); assertThat(p, is(notNullValue())); geogToSphericalGeos.transform(p, p); assertThat(p, is(notNullValue())); p.setLocation(circumscribed.getCenterX(), circumscribed.getMinY()); sphericalGeosToGeog.transform(p, p); assertThat(p, is(notNullValue())); geogToSphericalGeos.transform(p, p); assertThat(p, is(notNullValue())); p.setLocation(circumscribed.getMaxX(), circumscribed.getCenterY()); sphericalGeosToGeog.transform(p, p); assertThat(p, is(notNullValue())); assertThat(p, is(notNullValue())); p.setLocation(circumscribed.getMinX(), circumscribed.getCenterY()); sphericalGeosToGeog.transform(p, p); assertThat(p, is(notNullValue()));
double y = pol.getCoordinates()[index].y; try { DirectPosition pos = CRS.findMathTransform(product.getSceneGeoCoding().getMapCRS(), product.getSceneGeoCoding().getImageCRS()).transform(new DirectPosition2D(x, y), null); double[] values = pos.getCoordinate(); xCoordinates[index] = (int) values[0]; yCoordinates[index] = (int) values[1];
assertThat(inscribed, is(notNullValue())); final DirectPosition2D p = new DirectPosition2D(); p.setLocation(inscribed.getMaxX(), inscribed.getMaxY()); ellipsoidalGeosToGeog.transform(p, p); assertThat(p, is(notNullValue())); geogToEllipsoidalGeos.transform(p, p); assertThat(p, is(notNullValue())); p.setLocation(inscribed.getMaxX(), inscribed.getMinY()); ellipsoidalGeosToGeog.transform(p, p); assertThat(p, is(notNullValue())); geogToEllipsoidalGeos.transform(p, p); assertThat(p, is(notNullValue())); p.setLocation(inscribed.getMinX(), inscribed.getMaxY()); ellipsoidalGeosToGeog.transform(p, p); assertThat(p, is(notNullValue())); assertThat(p, is(notNullValue())); p.setLocation(inscribed.getMinX(), inscribed.getMinY()); ellipsoidalGeosToGeog.transform(p, p); assertThat(p, is(notNullValue()));
public static Rectangle worldToGrid(GridCoverage2D srcCoverage, ReferencedEnvelope envelope) throws TransformException { GridGeometry gg2D = srcCoverage.getGridGeometry(); MathTransform gridToCRS = gg2D.getGridToCRS(); MathTransform crsToGrid = gridToCRS.inverse(); DirectPosition lcGrid = new DirectPosition2D(); crsToGrid.transform(envelope.getLowerCorner(), lcGrid); DirectPosition ucGrid = new DirectPosition2D(); crsToGrid.transform(envelope.getUpperCorner(), ucGrid); int x = (int) Math.min(lcGrid.getOrdinate(0), ucGrid.getOrdinate(0)); int y = (int) Math.min(lcGrid.getOrdinate(1), ucGrid.getOrdinate(1)); int width = (int) Math.abs(lcGrid.getOrdinate(0) - ucGrid.getOrdinate(0)); int height = (int) Math.abs(lcGrid.getOrdinate(1) - ucGrid.getOrdinate(1)); return new Rectangle(x, y, width, height); }
if ((requestedCRS != null) && !CRS.equalsIgnoreMetadata(dataCRS, requestedCRS)) { try { MathTransform transform = CRS.findMathTransform(requestedCRS, dataCRS, true); final GeneralEnvelope requestedEnvelope=new GeneralEnvelope(new ReferencedEnvelope(bbox,requestedCRS)); final GridCoverage2D coverage=(GridCoverage2D) cinfo.getCoverage(requestedEnvelope, new Rectangle(0,0,width,height)); final DirectPosition position = new DirectPosition2D(requestedCRS, middle.x, middle.y); try { double[] pixelValues = null;
@Test @Ignore public void testEnvelopeTransformClipping() throws Exception { final CoordinateReferenceSystem source = WGS84; final CoordinateReferenceSystem target; target = CRS.parseWKT( "GEOGCS[\"GCS_North_American_1983\"," + "DATUM[\"North_American_Datum_1983\", " + "SPHEROID[\"GRS_1980\", 6378137.0, 298.257222101]], " + "PRIMEM[\"Greenwich\", 0.0], " + "UNIT[\"degree\", 0.017453292519943295], " + "AXIS[\"Longitude\", EAST], " + "AXIS[\"Latitude\", NORTH]]"); // bounds from geotiff GeneralEnvelope geotiff = new GeneralEnvelope(source); geotiff.add(new DirectPosition2D(source, -179.9, -90.0)); geotiff.add(new DirectPosition2D(source, 180.0, 89.9)); Envelope transformed = CRS.transform(geotiff, target); assertNotNull(transformed); assertTrue("clipped y", transformed.getUpperCorner().getOrdinate(1) > 88.0); assertTrue("clipped y", transformed.getLowerCorner().getOrdinate(1) < -88.0); assertTrue("clipped x", transformed.getUpperCorner().getOrdinate(0) > 170.0); assertTrue("clipped x", transformed.getLowerCorner().getOrdinate(0) < -170.0); }