List of usage examples for com.google.common.geometry S2CellUnion cellIds
ArrayList cellIds
To view the source code for com.google.common.geometry S2CellUnion cellIds.
Click Source Link
From source file:org.esa.beam.occci.MerisCoverageMain.java
public static void main(String[] args) throws ParseException { S2Polygon polygon = S2EoProduct.createPolygon(poly); // System.out.println("polygon = " + polygon); S2RegionCoverer coverer = new S2RegionCoverer(); coverer.setMinLevel(0);//from ww w . j ava2 s .c om coverer.setMaxLevel(5); coverer.setMaxCells(500); S2CellUnion covering = coverer.getCovering(polygon); final GeometryFactory factory = new GeometryFactory(); List<S2CellId> s2CellIds = covering.cellIds(); System.out.println("s2CellIds.size() = " + s2CellIds.size()); List<Polygon> polys = new ArrayList<>(); for (S2CellId s2CellId : s2CellIds) { // System.out.println("s2CellId = " + s2CellId); ArrayList<double[]> coordList = new ArrayList<double[]>(); //System.out.println("s2CellId = " + s2CellId); S2Cell s2Cell = new S2Cell(s2CellId); //System.out.println("s2Cell = " + s2Cell); S2LatLng s2LatLng = new S2LatLng(s2Cell.getVertex(0)); coordList.add(new double[] { s2LatLng.lat().degrees(), s2LatLng.lng().degrees() }); s2LatLng = new S2LatLng(s2Cell.getVertex(1)); coordList.add(new double[] { s2LatLng.lat().degrees(), s2LatLng.lng().degrees() }); s2LatLng = new S2LatLng(s2Cell.getVertex(2)); coordList.add(new double[] { s2LatLng.lat().degrees(), s2LatLng.lng().degrees() }); s2LatLng = new S2LatLng(s2Cell.getVertex(3)); coordList.add(new double[] { s2LatLng.lat().degrees(), s2LatLng.lng().degrees() }); s2LatLng = new S2LatLng(s2Cell.getVertex(0)); coordList.add(new double[] { s2LatLng.lat().degrees(), s2LatLng.lng().degrees() }); 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[1], coord[0]); } Polygon p = factory.createPolygon(factory.createLinearRing(coordinates)); //System.out.println(p); polys.add(p); } MultiPolygon multiPolygon = factory.createMultiPolygon(polys.toArray(new Polygon[polys.size()])); Geometry simplify = TopologyPreservingSimplifier.simplify(multiPolygon, 0.01); System.out.println(multiPolygon); System.out.println(simplify); Geometry origin = new WKTReader().read(poly); Geometry both = multiPolygon.union(origin); System.out.println(both); }
From source file:org.esa.beam.occci.S2IndexCreatorMain.java
public static void main(String[] args) throws IOException, ParseException { if (args.length != 2) { printUsage();// w w w . j a va 2 s .c o m } File productListFile = new File(args[0]); if (!productListFile.exists()) { System.err.printf("productList file '%s' does not exits%n", args[0]); printUsage(); } int counter = 0; List<EoProduct> eoProductList = ProductDB.readProducts("s2", productListFile); Collections.sort(eoProductList, ProductDB.EO_PRODUCT_COMPARATOR); File indexFile = new File(args[1]); File urlFile = new File(indexFile + ".url"); File poylFile = new File(indexFile + ".polygon"); File coverFile = new File(indexFile + ".coverages"); List<S2IntCoverage> allCoverages = new ArrayList<>(); try (DataOutputStream dosIndex = new DataOutputStream( new BufferedOutputStream(new FileOutputStream(indexFile))); DataOutputStream dosUrl = new DataOutputStream( new BufferedOutputStream(new FileOutputStream(urlFile))); DataOutputStream dosPoly = new DataOutputStream( new BufferedOutputStream(new FileOutputStream(poylFile)))) { for (EoProduct eoProduct : eoProductList) { eoProduct.createGeo(); S2EoProduct s2EoProduct = (S2EoProduct) eoProduct; dosUrl.writeUTF(eoProduct.getName()); dosIndex.writeLong(eoProduct.getStartTime()); dosIndex.writeLong(eoProduct.getEndTime()); S2CellUnion cellUnion = s2EoProduct.cellUnion; S2IntCoverage s2IntCoverage = new S2IntCoverage(cellUnion); int index = allCoverages.indexOf(s2IntCoverage); if (index <= 0) { allCoverages.add(s2IntCoverage); index = allCoverages.size() - 1; } dosIndex.writeInt(index); int level1Mask = 0; for (int i = 0; i < cellUnion.cellIds().size(); i++) { S2CellId s2CellId = cellUnion.cellIds().get(i); level1Mask |= (1 << (int) (s2CellId.id() >>> MASK_SHIFT)); } dosIndex.writeInt(level1Mask); s2EoProduct.writePolygone(dosPoly); s2EoProduct.reset(); counter++; if (counter % 10000 == 0) { System.out.println("counter = " + counter); } } } System.out.println("allCoverages.size() = " + allCoverages.size()); try (DataOutputStream dosCover = new DataOutputStream( new BufferedOutputStream(new FileOutputStream(coverFile)))) { dosCover.writeInt(allCoverages.size()); for (S2IntCoverage s2Cover : allCoverages) { int[] intIds = s2Cover.intIds; dosCover.writeInt(intIds.length); for (int intId : intIds) { dosCover.writeInt(intId); } } } }
From source file:com.bc.inventory.utils.S2Integer.java
public static int[] cellUnion2Ints(S2CellUnion cellUnion) { int[] intIds; ArrayList<S2CellId> s2CellIds = cellUnion.cellIds(); intIds = new int[s2CellIds.size()]; for (int i = 0; i < intIds.length; i++) { intIds[i] = S2Integer.asInt(s2CellIds.get(i)); }/*from ww w . j a v a2 s . c o m*/ return intIds; }
From source file:org.esa.beam.occci.S2EoProduct.java
private static String cellUnionToString(S2CellUnion cellUnion) { ArrayList<S2CellId> s2CellIds = cellUnion.cellIds(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < s2CellIds.size(); i++) { S2CellId s2CellId = s2CellIds.get(i); sb.append(s2CellId.id());/*from w w w . ja v a2s. c o m*/ if (i < s2CellIds.size() - 1) { sb.append(";"); } } return sb.toString(); }
From source file:com.grublr.geo.GeoDataManager.java
/** * Merge continuous cells in cellUnion and return a list of merged GeohashRanges. * /*w ww . j av a 2 s. c o m*/ * @param cellUnion * Container for multiple cells. * * @return A list of merged GeohashRanges. */ private List<GeohashRange> mergeCells(S2CellUnion cellUnion) { List<GeohashRange> ranges = new ArrayList<GeohashRange>(); for (S2CellId c : cellUnion.cellIds()) { GeohashRange range = new GeohashRange(c.rangeMin().id(), c.rangeMax().id()); boolean wasMerged = false; for (GeohashRange r : ranges) { if (r.tryMerge(range)) { wasMerged = true; break; } } if (!wasMerged) { ranges.add(range); } } return ranges; }