MosaicGrid { private Polygon convertToJtsPolygon(PathIterator pathIterator) { ArrayList<double[]> coordList = new ArrayList<double[]>(); int lastOpenIndex = 0; while (!pathIterator.isDone()) { final double[] coords = new double[6]; final int segType = pathIterator.currentSegment(coords); if (segType == PathIterator.SEG_CLOSE) { coordList.add(coordList.get(lastOpenIndex)); lastOpenIndex = coordList.size(); } else { coordList.add(coords); } pathIterator.next(); } final Coordinate[] coordinates = new Coordinate[coordList.size()]; for (int i1 = 0; i1 < coordinates.length; i1++) { final double[] coord = coordList.get(i1); coordinates[i1] = new Coordinate(coord[0], coord[1]); } GeometryFactory factory = getGeometryFactory(); return factory.createPolygon(factory.createLinearRing(coordinates), null); } MosaicGrid();   MosaicGrid(int macroTileSize, int numTileY, int tileSize, boolean withIntersectionCheck, int maxReducers, int maxMacroTileCountX, String regionWkt); static MosaicGrid create(Configuration conf); void saveToConfiguration(Configuration conf); int getMacroTileSize(); int getTileSize(); double getPixelSize(); int getNumTileX(); int getNumTileY(); int getNumMacroTileX(); int getNumMacroTileY(); Rectangle computeBounds(Geometry roiGeometry); Rectangle alignToTileGrid(Rectangle rectangle); Geometry computeProductGeometry(Product product); TileIndexWritable[] getTileIndices(List<Point> tilePointIndices); Rectangle getTileRectangle(int tileX, int tileY); Rectangle getMacroTileRectangle(int tileX, int tileY); CrsGeoCoding createMacroCRS(Point macroTile); int getPartition(int macroTileX, int macroTileY); int getNumReducers();  }
@Test @Ignore public void testGetBounds() throws IOException { Product product = ProductIO.readProduct("/home/boe/tmp/sen2agri/S2A_MSIL2A_20170216T170351_N0204_R069_T14QNF_20170216T171642.SAFE/S2A_OPER_SSC_L2VALD_14QNF____20170216.HDR"); final GeneralPath[] paths = ProductUtils.createGeoBoundaryPaths(product); final com.vividsolutions.jts.geom.Polygon[] polygons = new com.vividsolutions.jts.geom.Polygon[paths.length]; for (int i = 0; i < paths.length; i++) { polygons[i] = convertToJtsPolygon(paths[i].getPathIterator(null)); } final DouglasPeuckerSimplifier peuckerSimplifier = new DouglasPeuckerSimplifier( polygons.length == 1 ? polygons[0] : new GeometryFactory().createMultiPolygon(polygons)); Geometry sourceGeometry = peuckerSimplifier.getResultGeometry(); System.out.println("class " + sourceGeometry.getClass()); System.out.println("sourceGeometry=" + sourceGeometry); Geometry regionGeometry = parseWKT("POLYGON ((-104 4, -73 4, -73 18, -104 18, -104 4))"); Geometry effectiveGeometry = regionGeometry.intersection(sourceGeometry); System.out.println("class " + effectiveGeometry.getClass()); System.out.println("effectiveGeometry=" + effectiveGeometry); Geometry boundary = effectiveGeometry.getBoundary(); System.out.println("class " + boundary.getClass()); System.out.println("boundary=" + boundary); }