private static Coordinate toCoordinate(GeoPos geoPos) { if (geoPos != null) { return new Coordinate(geoPos.getLon(), geoPos.getLat()); } return null; }
private Point2D.Double modelToView(GeoPos geoPos, AffineTransform modelToView) { Point2D.Double result = new Point2D.Double(); modelToView.transform(new Point2D.Double(geoPos.getLon(), geoPos.getLat()), result); return result; }
private void exportLatLon(Band refBand, StringBuilder row, PixelPos pixelPos) { final GeoPos geoPos = new GeoPos(); refBand.getGeoCoding().getGeoPos(pixelPos, geoPos); row.append(geoPos.getLon()); row.append(getSeparator()); row.append(geoPos.getLat()); row.append(getSeparator()); }
ExpectedGeoCoding(Product product, Random random) { this(); final ArrayList<Point2D> pointList = ExpectedPixel.createPointList(product, random); final GeoCoding geoCoding = product.getGeoCoding(); coordinates = new ExpectedGeoCoordinate[pointList.size()]; for (int i = 0; i < pointList.size(); i++) { Point2D point = pointList.get(i); final float x = (float) point.getX(); final float y = (float) point.getY(); final GeoPos geoPos = geoCoding.getGeoPos(new PixelPos(x, y), null); final PixelPos pixelPos = geoCoding.getPixelPos(geoPos, null); float xAccuracy = Math.abs(x - pixelPos.x); float yAccuracy = Math.abs(y - pixelPos.y); float accuracy = Math.max(xAccuracy, yAccuracy); reverseAccuracy = Math.max(reverseAccuracy, accuracy); coordinates[i] = new ExpectedGeoCoordinate(x, y, geoPos.getLat(), geoPos.getLon()); } }
@Override public PixelPos getPixelPos(final GeoPos geoPos, PixelPos pixelPos) { if (pixelPos == null) { pixelPos = new PixelPos(); } pixelPos.setLocation(_width / 360.0f * (geoPos.getLon() + 180.0f), _height - (_height / 180.0f * (geoPos.getLat() + 90.0f))); return pixelPos; }
private PixelPos getProductCenter(final Product product) { final GeoCoding geoCoding = product.getGeoCoding(); PixelPos centerPos = null; if (geoCoding != null) { final float pixelX = (float) Math.floor(0.5f * product.getSceneRasterWidth()) + 0.5f; final float pixelY = (float) Math.floor(0.5f * product.getSceneRasterHeight()) + 0.5f; final GeoPos geoPos = geoCoding.getGeoPos(new PixelPos(pixelX, pixelY), null); final AffineTransform transform = layerCanvas.getViewport().getModelToViewTransform(); final Point2D point2D = transform.transform(new Point2D.Double(geoPos.getLon(), geoPos.getLat()), null); centerPos = new PixelPos((float) point2D.getX(), (float) point2D.getY()); } return centerPos; }
/** * Inverse project map co-ordinates into geographical co-ordinates. * * @param mapPoint the source location in x/y map coordinates * @param geoPoint the target position in lat/lon (might be null, then a new object is created) */ @Override public GeoPos inverse(Point2D mapPoint, GeoPos geoPoint) { if (geoPoint == null) { geoPoint = new GeoPos(); } geoPoint = inverse_impl((mapPoint.getX() - _x0) * _invA, (mapPoint.getY() - _y0) * _invA, geoPoint); geoPoint.setLocation(geoPoint.getLat(), geoPoint.getLon() + _centralMeridian); return geoPoint; }
/** * Gets the UTM projection suitable for the given geodetic coordinate. * * @param geoPos a geodetic coordinate * * @return a suitable UTM projection */ public static MapProjection getSuitableProjection(final GeoPos geoPos) { int zoneIndex = getZoneIndex(geoPos.getLon()); final boolean south = geoPos.getLat() < 0.0; final String projName = getProjectionName(zoneIndex, south); MapProjection projection = MapProjectionRegistry.getProjection(projName); return projection; }
private void syncLatLonWithXYParams() { final PixelPos pixelPos1 = new PixelPos(((Number) paramX1.getValue()).intValue(), ((Number) paramY1.getValue()).intValue()); final PixelPos pixelPos2 = new PixelPos(((Number) paramX2.getValue()).intValue(), ((Number) paramY2.getValue()).intValue()); final GeoCoding geoCoding = product.getGeoCoding(); final GeoPos geoPos1 = geoCoding.getGeoPos(pixelPos1, null); final GeoPos geoPos2 = geoCoding.getGeoPos(pixelPos2, null); paramNorthLat1.setValue(geoPos1.getLat(), null); paramWestLon1.setValue(geoPos1.getLon(), null); paramSouthLat2.setValue(geoPos2.getLat(), null); paramEastLon2.setValue(geoPos2.getLon(), null); }
public DistanceData(GeoCoding geoCoding, final Point pH, final Point pN) { this.xH = pH.x; this.yH = pH.y; this.xN = pN.x; this.yN = pN.y; final GeoPos geoPosH = geoCoding.getGeoPos(new PixelPos(xH, yH), null); final GeoPos geoPosN = geoCoding.getGeoPos(new PixelPos(xN, yN), null); this.lonH = geoPosH.getLon(); this.latH = geoPosH.getLat(); this.lonN = geoPosN.getLon(); this.latN = geoPosN.getLat(); this.lamH = (float) (MathUtils.DTOR * lonH); this.phiH = (float) (MathUtils.DTOR * latH); this.lamN = (float) (MathUtils.DTOR * lonN); this.phiN = (float) (MathUtils.DTOR * latN); this.distance = (float) MathUtils.sphereDistance(MEAN_EARTH_RADIUS_KM, lamH, phiH, lamN, phiN); this.distanceError = distance * (1 - MEAN_ERROR_FACTOR); } }
@Override public CoordinateReferenceSystem getCRS(final GeoPos referencePos, ParameterValueGroup parameters, GeodeticDatum datum) throws FactoryException { int zoneIndex = getZoneIndex(referencePos.getLon()); final boolean south = referencePos.getLat() < 0.0; ParameterValueGroup tmParameters = createTransverseMercatorParameters(zoneIndex, south, datum); final String projName = getProjectionName(zoneIndex, south); return createCrs(projName, new TransverseMercator.Provider(), tmParameters, datum); } }
private void addGeographicCoordinateVariables(NFileWriteable ncFile, GeoPos ul, GeoPos br) throws IOException { final NVariable lat = ncFile.addVariable(Constants.LAT_VAR_NAME, DataType.FLOAT, null, "lat"); lat.addAttribute("units", "degrees_north"); lat.addAttribute("long_name", "latitude"); lat.addAttribute("standard_name", "latitude"); lat.addAttribute(Constants.VALID_MIN_ATT_NAME, br.getLat()); lat.addAttribute(Constants.VALID_MAX_ATT_NAME, ul.getLat()); final NVariable lon = ncFile.addVariable(Constants.LON_VAR_NAME, DataType.FLOAT, null, "lon"); lon.addAttribute("units", "degrees_east"); lon.addAttribute("long_name", "longitude"); lon.addAttribute("standard_name", "longitude"); lon.addAttribute(Constants.VALID_MIN_ATT_NAME, ul.getLon()); lon.addAttribute(Constants.VALID_MAX_ATT_NAME, br.getLon()); }
@Override public PixelPos getPixelPos(GeoPos geoPos, PixelPos pixelPos) { if (pixelPos == null) { pixelPos = new PixelPos(); } try { DirectPosition directGeoPos = new DirectPosition2D(geoPos.getLon(), geoPos.getLat()); DirectPosition directPixelPos = geoToImage.transform(directGeoPos, null); pixelPos.setLocation((float) directPixelPos.getOrdinate(0), (float) directPixelPos.getOrdinate(1)); } catch (Exception ignored) { pixelPos.setInvalid(); } return pixelPos; }
public void testForwardAndInverseTransform() { final MapTransform transform = MapTransformFactory.createTransform(StereographicDescriptor.TYPE_ID, DEFAULT_PARAMS); float lat = 90f, lon = 11.87305555f; GeoPos geoPos = new GeoPos(lat, lon); Point2D mapPoint = transform.forward(geoPos, null); GeoPos testPos = transform.inverse(mapPoint, null); assertEquals(90.0, testPos.getLat(), EPSILON); assertEquals(0, testPos.getLon(), EPSILON); lat = 53.786666666f; lon = 11.87305555f; geoPos = new GeoPos(lat, lon); mapPoint = transform.forward(geoPos, null); testPos = transform.inverse(mapPoint, null); assertEquals(lat, testPos.getLat(), EPSILON); assertEquals(lon, testPos.getLon(), EPSILON); }
public void testForwarAndInverseTransform() { // values for this test are from Frank Fell! double[] params = new double[]{Ellipsoid.WGS_84.getSemiMajor(), Ellipsoid.WGS_84.getSemiMinor(), 0.0, 9.0, 0.9996, 500000.0, 0.0}; MapTransform transform = MapTransformFactory.createTransform("Transverse_Mercator", params); float lat = 53.786666666f, lon = 11.87305555f; GeoPos geoPos = new GeoPos(lat, lon); Point2D mapPoint = transform.forward(geoPos, null); assertEquals(689265.13, mapPoint.getX(), _metricDelta); assertEquals(5963616.5, mapPoint.getY(), _metricDelta); GeoPos testPos = transform.inverse(mapPoint, null); assertEquals(lon, testPos.getLon(), _geodeticDelta); assertEquals(lat, testPos.getLat(), _geodeticDelta); }
public Coordinate[] getCoordinates() { Coordinate[] coordinates = new Coordinate[coordinateTableModel.getRowCount()]; for (int i = 0; i < coordinateTableModel.getRowCount(); i++) { final Placemark placemark = coordinateTableModel.getPlacemarkAt(i); SimpleFeature feature = placemark.getFeature(); final Date dateTime = (Date) feature.getAttribute(Placemark.PROPERTY_NAME_DATETIME); final Coordinate.OriginalValue[] originalValues = PixExOp.getOriginalValues(feature); if (placemark.getGeoPos() == null) { final Point point = (Point) feature.getDefaultGeometry(); coordinates[i] = new Coordinate(placemark.getName(), (float) point.getY(), (float) point.getX(), dateTime, originalValues); } else { coordinates[i] = new Coordinate(placemark.getName(), placemark.getGeoPos().getLat(), placemark.getGeoPos().getLon(), dateTime, originalValues); } } return coordinates; }
public void testConstructor() { GeoPos geoPos1 = new GeoPos(); assertEquals(0.0F, geoPos1.lat, 1.e-10F); assertEquals(0.0F, geoPos1.lon, 1.e-10F); GeoPos geoPos2 = new GeoPos(-1.4F, 180.3F); assertEquals(-1.4F, geoPos2.lat, 1.e-10F); assertEquals(180.3F, geoPos2.lon, 1.e-10F); assertEquals(geoPos2.lat, geoPos2.getLat(), 1.e-10F); assertEquals(geoPos2.lon, geoPos2.getLon(), 1.e-10F); GeoPos geoPos3 = new GeoPos(geoPos2); assertEquals(geoPos3.lat, geoPos3.lat, 1.e-10F); assertEquals(geoPos3.lon, geoPos3.lon, 1.e-10F); }
@Test public void initialState() { final double x = placemark.getPixelPos().getX(); final double y = placemark.getPixelPos().getY(); assertEquals(1.0, x, 0.0); assertEquals(1.0, y, 0.0); final Point point = (Point) placemark.getFeature().getDefaultGeometry(); assertEquals(2.0, point.getX(), 0.0); assertEquals(2.0, point.getY(), 0.0); final double lon = placemark.getGeoPos().getLon(); final double lat = placemark.getGeoPos().getLat(); assertEquals(2.0, lon, 0.0); assertEquals(2.0, lat, 0.0); }
@Test public void movePinByPixelPosition() { placemark.setPixelPos(new PixelPos(2.0f, 1.0f)); final double x = placemark.getPixelPos().getX(); final double y = placemark.getPixelPos().getY(); assertEquals(2.0, x, 0.0); assertEquals(1.0, y, 0.0); // todo: rq/?? - make asserts successful final Point point = (Point) placemark.getFeature().getDefaultGeometry(); assertEquals(4.0, point.getX(), 0.0); assertEquals(2.0, point.getY(), 0.0); // todo: rq/?? - make asserts successful final double lon = placemark.getGeoPos().getLon(); final double lat = placemark.getGeoPos().getLat(); assertEquals(4.0, lon, 0.0); assertEquals(2.0, lat, 0.0); }
@Test public void movePinByGeometry() { placemark.getFeature().setDefaultGeometry(newPoint(4.0, 2.0)); placemark.getProduct().getVectorDataGroup().get("pins").fireFeaturesChanged(placemark.getFeature()); final Point point = (Point) placemark.getFeature().getDefaultGeometry(); assertEquals(4.0, point.getX(), 0.0); assertEquals(2.0, point.getY(), 0.0); // todo: rq/?? - make asserts successful final double x = placemark.getPixelPos().getX(); final double y = placemark.getPixelPos().getY(); assertEquals(2.0, x, 0.0); assertEquals(1.0, y, 0.0); // todo: rq/?? - make asserts successful final double lon = placemark.getGeoPos().getLon(); final double lat = placemark.getGeoPos().getLat(); assertEquals(4.0, lon, 0.0); assertEquals(2.0, lat, 0.0); }