private static void addToPath(List<List<Coord>> lineList, List<GeneralPath> generalPathList) { for (final List<Coord> coordList : lineList) { if (coordList.size() >= 2) { final GeneralPath generalPath = new GeneralPath(); boolean restart = true; for (Coord coord : coordList) { PixelPos pixelPos = coord.pixelPos; if (pixelPos.isValid()) { if (restart) { generalPath.moveTo(pixelPos.x, pixelPos.y); } else { generalPath.lineTo(pixelPos.x, pixelPos.y); } restart = false; } else { restart = true; } } generalPathList.add(generalPath); } } }
@Override public void filter(Coordinate coordinate) { final GeoPos geoPos = new GeoPos((float) coordinate.y, (float) coordinate.x); final PixelPos pixelPos = geoCoding.getPixelPos(geoPos, null); if (pixelPos.isValid()) { x1 = min(x1, (int) floor(pixelPos.x)); x2 = max(x2, (int) ceil(pixelPos.x)); y1 = min(y1, (int) floor(pixelPos.y)); y2 = max(y2, (int) ceil(pixelPos.y)); } }
public static boolean isPixelValid(Product tsProduct, PixelPos pixelPos) { return pixelPos.isValid() && pixelPos.x < tsProduct.getSceneRasterWidth() && pixelPos.x >= 0 && pixelPos.y < tsProduct.getSceneRasterHeight() && pixelPos.y >= 0; }
/** * Not used, but useful for debugging: DON'T delete this method! * * @param geoCoding The geo-coding * @param geoBoundary The geo-boundary * @return the geo-boundary */ @SuppressWarnings({"UnusedDeclaration"}) private static GeneralPath createPixelBoundaryPath(final GeoCoding geoCoding, final GeoPos[] geoBoundary) { final GeneralPath generalPath = new GeneralPath(); boolean restart = true; for (final GeoPos geoPos : geoBoundary) { geoPos.lon = limitLon(geoPos.lon); final PixelPos pixelPos = geoCoding.getPixelPos(geoPos, null); if (pixelPos.isValid()) { if (restart) { generalPath.moveTo(pixelPos.x, pixelPos.y); } else { generalPath.lineTo(pixelPos.x, pixelPos.y); } restart = false; } else { restart = true; } } return generalPath; }
private static Placemark[] getValidGcps(ProductNodeGroup<Placemark> gcpGroup) { final List<Placemark> gcpList = new ArrayList<Placemark>(gcpGroup.getNodeCount()); for (int i = 0; i < gcpGroup.getNodeCount(); i++) { final Placemark p = gcpGroup.get(i); final PixelPos pixelPos = p.getPixelPos(); final GeoPos geoPos = p.getGeoPos(); if (pixelPos != null && pixelPos.isValid() && geoPos != null && geoPos.isValid()) { gcpList.add(p); } } return gcpList.toArray(new Placemark[gcpList.size()]); }
private static SimpleFeature createFeature(SimpleFeatureType type, GeoCoding geoCoding, int pointIndex, float lat, float lon, double data) { PixelPos pixelPos = geoCoding.getPixelPos(new GeoPos(lat, lon), null); if (!pixelPos.isValid()) { return null; } SimpleFeatureBuilder fb = new SimpleFeatureBuilder(type); GeometryFactory gf = new GeometryFactory(); /*0*/ fb.add(gf.createPoint(new Coordinate(pixelPos.x, pixelPos.y))); /*1*/ fb.add(gf.createPoint(new Coordinate(lon, lat))); /*2*/ fb.add(data); return fb.buildFeature(String.format("ID%08d", pointIndex)); }
private static boolean isValid(Placemark p) { final PixelPos pixelPos = p.getPixelPos(); final GeoPos geoPos = p.getGeoPos(); return pixelPos != null && pixelPos.isValid() && geoPos != null && geoPos.isValid(); }
/** * {@inheritDoc} */ public PixelPos getPixelPos(final GeoPos geoPos, PixelPos pixelPos) { final Point2D.Double point = new Point2D.Double(geoPos.lon, geoPos.lat); rotator.transform(point); if (pixelPos == null) { pixelPos = new PixelPos(); } pixelPos.setLocation(inverseMap.getValue(point)); if (!pixelPos.isValid() || pixelPos.x < 0 || pixelPos.x >= sceneWidth || pixelPos.y < 0 || pixelPos.y >= sceneHeight) { pixelPos.x = -1; pixelPos.y = -1; } return pixelPos; }
private void updateXYParams(GeoPos geoPos1, GeoPos geoPos2) { final GeoCoding geoCoding = product.getGeoCoding(); final PixelPos pixelPos1 = geoCoding.getPixelPos(geoPos1, null); if (!pixelPos1.isValid()) { pixelPos1.setLocation(0, 0); } final PixelPos pixelPos2 = geoCoding.getPixelPos(geoPos2, null); if (!pixelPos2.isValid()) { pixelPos2.setLocation(product.getSceneRasterWidth(), product.getSceneRasterHeight()); } final Rectangle.Float region = new Rectangle.Float(); region.setFrameFromDiagonal(pixelPos1.x, pixelPos1.y, pixelPos2.x, pixelPos2.y); final Rectangle.Float productBounds = new Rectangle.Float(0, 0, product.getSceneRasterWidth(), product.getSceneRasterHeight()); Rectangle2D finalRegion = productBounds.createIntersection(region); paramX1.setValue((int) finalRegion.getMinX(), null); paramY1.setValue((int) finalRegion.getMinY(), null); paramX2.setValue((int) finalRegion.getMaxX() - 1, null); paramY2.setValue((int) finalRegion.getMaxY() - 1, null); }
@Override public PixelPos getPixelPos(final GeoPos geoPos, PixelPos pixelPos) { if (pixelPos == null) { pixelPos = new PixelPos(); } if (geoPos.isValid()) { // ensurePixelPosEstimatorExist(); // if (pixelPosEstimator.canGetPixelPos()) { pixelPosEstimator.getPixelPos(geoPos, pixelPos); if (pixelPos.isValid()) { pixelFinder.findPixelPos(geoPos, pixelPos); } // } else { // pixelPos.setInvalid(); // } } else { pixelPos.setInvalid(); } return pixelPos; }
GeoApproximation getGeoPos(PixelPos p, GeoPos g) { GeoApproximation approximation = null; if (approximations != null) { if (g == null) { g = new GeoPos(); } if (p.isValid()) { approximation = GeoApproximation.findSuitable(approximations, p); if (approximation != null) { final double x = p.getX(); final double y = p.getY(); final Point2D q = new Point2D.Double(x, y); approximation.p2g(q); final double lon = q.getX(); final double lat = q.getY(); if (lon >= -180.0 && lon <= 180.0 && lat >= -90.0 && lat <= 90.0) { g.setLocation((float) lat, (float) lon); } else { g.setInvalid(); } } else { g.setInvalid(); } } else { g.setInvalid(); } } return approximation; }
/** * Returns the pixel co-ordinates as x/y for a given geographical position given as lat/lon. * * @param geoPos the geographical position as lat/lon in the coordinate system determined by {@link #getDatum()} * @param pixelPos an instance of <code>Point</code> to be used as return value. If this parameter is * <code>null</code>, the method creates a new instance which it then returns. * @return the pixel co-ordinates as x/y */ public PixelPos getPixelPos(GeoPos geoPos, PixelPos pixelPos) { if (pixelPos == null) { pixelPos = new PixelPos(); } pixelPos.setInvalid(); final int index = getGeoCodingIndexfor(geoPos); _lastCenterLineIndex = index; final GeoCoding gc = _gcList.get(index); if (gc != null) { gc.getPixelPos(geoPos, pixelPos); } if (pixelPos.isValid()) { pixelPos.y += (index * getScanlineHeight()) - getScanlineOffset(); if(pixelPos.y < 0 || pixelPos.y >= getSceneHeight()) pixelPos.setInvalid(); } return pixelPos; }
private void initCoordinates(Placemark[] gcps) { for (final Placemark gcp : gcps) { final PixelPos pixelPos = gcp.getPixelPos(); final GeoPos geoPos = gcp.getGeoPos(); if (pixelPos == null || !pixelPos.isValid() || geoPos == null || !geoPos.isValid()) { throw new IllegalArgumentException("Invalid ground control point."); } } x = new double[gcps.length]; y = new double[gcps.length]; lons = new double[gcps.length]; lats = new double[gcps.length]; for (int i = 0; i < gcps.length; i++) { final PixelPos pixelPos = gcps[i].getPixelPos(); x[i] = pixelPos.getX(); y[i] = pixelPos.getY(); final GeoPos geoPos = gcps[i].getGeoPos(); lons[i] = geoPos.getLon(); lats[i] = geoPos.getLat(); } }
@Override public void paintOverlay(LayerCanvas canvas, Rendering rendering) { if (geoPosition == null || !geoPosition.isValid()) { return; } final GeoCoding geoCoding = sceneView.getRaster().getGeoCoding(); if (!geoCoding.canGetPixelPos()) { return; } final Product product = sceneView.getRaster().getProduct(); final PixelPos pixelPos = geoCoding.getPixelPos(geoPosition, null); if (!pixelPos.isValid() || !product.containsPixel(pixelPos)) { return; } final Viewport viewport = canvas.getViewport(); drawCursor(rendering.getGraphics(), viewport, pixelPos); }
geoPos = new GeoPos(); if (pixelPos.isValid()) { int x0 = (int) Math.floor(pixelPos.getX()); int y0 = (int) Math.floor(pixelPos.getY());
public static void writeXML(Placemark placemark, XmlWriter writer, int indent) { Guardian.assertNotNull("writer", writer); Guardian.assertGreaterThan("indent", indent, -1); final String[][] attributes = {new String[]{DimapProductConstants.ATTRIB_NAME, placemark.getName()}}; final String[] pinTags = XmlWriter.createTags(indent, DimapProductConstants.TAG_PLACEMARK, attributes); writer.println(pinTags[0]); indent++; writer.printLine(indent, DimapProductConstants.TAG_PLACEMARK_LABEL, placemark.getLabel()); writer.printLine(indent, DimapProductConstants.TAG_PLACEMARK_DESCRIPTION, placemark.getDescription()); final GeoPos geoPos = placemark.getGeoPos(); if (geoPos != null) { writer.printLine(indent, DimapProductConstants.TAG_PLACEMARK_LATITUDE, geoPos.lat); writer.printLine(indent, DimapProductConstants.TAG_PLACEMARK_LONGITUDE, geoPos.lon); } final PixelPos pixelPos = placemark.getPixelPos(); if (pixelPos != null && pixelPos.isValid()) { writer.printLine(indent, DimapProductConstants.TAG_PLACEMARK_PIXEL_X, pixelPos.x); writer.printLine(indent, DimapProductConstants.TAG_PLACEMARK_PIXEL_Y, pixelPos.y); } final String styleCss = placemark.getStyleCss(); if (styleCss != null && !styleCss.isEmpty()) { writer.printLine(indent, DimapProductConstants.TAG_PLACEMARK_STYLE_CSS, styleCss); } writer.println(pinTags[1]); }
@Test @Ignore public void testGetPixelPosForSimulatedSwath() { final int nx = 512; final int ny = 36000; final PlanarImage[] images = generateSwathCoordinates(nx, ny, 0.009, 0.009, new Rotator(0.0, -5.0, 269.0)); final PlanarImage lonImage = images[0]; final PlanarImage latImage = images[1]; final PlanarImage maskImage = images[2]; final PixelPosEstimator estimator = new PixelPosEstimator(lonImage, latImage, maskImage, 0.5); final GeoPos g = new GeoPos(); final PixelPos p = new PixelPos(); for (int y = 0; y < ny; y++) { final Rectangle region = new Rectangle(0, y, nx, 1); final Raster lonData = lonImage.getData(region); final Raster latData = latImage.getData(region); for (int x = 0; x < nx; x++) { final float lon = lonData.getSampleFloat(x, y, 0); final float lat = latData.getSampleFloat(x, y, 0); g.setLocation(lat, lon); estimator.getPixelPos(g, p); assertTrue(p.isValid()); assertEquals(x + 0.5, p.getX(), 0.5); assertEquals(y + 0.5, p.getY(), 0.5); } } }