@Override public String convert(final MultiPolygon multiPolygon) { final com.vividsolutions.jts.geom.MultiPolygon geometry = new JtsMultiPolygonToMultiPolygonConverter() .backwardConvert(multiPolygon); return new WKTWriter().write(geometry); } }
@Override public MultiPolygon backwardConvert(final byte[] wkb) { com.vividsolutions.jts.geom.MultiPolygon geometry = null; try { geometry = (com.vividsolutions.jts.geom.MultiPolygon) WKB_READER.read(wkb); } catch (final ParseException | ClassCastException e) { throw new CoreException("Cannot parse wkb : {}", WKBWriter.toHex(wkb)); } return new JtsMultiPolygonToMultiPolygonConverter().convert(geometry); }
/** * @param boundaries * A {@link Map} from country names to country boundaries in {@link MultiPolygon} * format * @return {@link CountryBoundaryMap} created from existing boundaries */ public static CountryBoundaryMap fromBoundaryMap(final Map<String, MultiPolygon> boundaries) { final CountryBoundaryMap map = new CountryBoundaryMap(Rectangle.MAXIMUM); boundaries.forEach((name, multiPolygon) -> map.addCountry(name, JTS_MULTI_POLYGON_TO_MULTI_POLYGON_CONVERTER.backwardConvert(multiPolygon))); return map; }
.backwardConvert(multiPolygon).toText());
@Override public byte[] convert(final MultiPolygon multiPolygon) { final Geometry geometry = new JtsMultiPolygonToMultiPolygonConverter() .backwardConvert(multiPolygon); final byte[] wkb = new WKBWriter().write(geometry); return wkb; } }
@Override public MultiPolygon backwardConvert(final String wkt) { com.vividsolutions.jts.geom.MultiPolygon geometry = null; final WKTReader myReader = new WKTReader(); try { geometry = (com.vividsolutions.jts.geom.MultiPolygon) myReader.read(wkt); } catch (final ParseException | ClassCastException e) { throw new CoreException("Cannot parse wkt : {}", wkt); } return new JtsMultiPolygonToMultiPolygonConverter().convert(geometry); }
.backwardConvert(multiPolygon); this.initializeGridIndex(area);
@Test public void testOnDemandIndexAndIndexFromFileViaArea() { // Generate grid index for the first time final CountryBoundaryMap firstMap = CountryBoundaryMap .fromPlainText(new InputStreamResource(CountryBoundaryMapTest.class .getResourceAsStream("MAF_AIA_osm_boundaries.txt.gz")) .withDecompressor(Decompressor.GZIP)); Assert.assertFalse(firstMap.hasGridIndex()); firstMap.initializeGridIndex( new JtsMultiPolygonToMultiPolygonConverter().backwardConvert(MultiPolygon.MAXIMUM)); Assert.assertTrue(firstMap.hasGridIndex()); // Read grid index from file final CountryBoundaryMap secondMap = CountryBoundaryMap .fromPlainText(new InputStreamResource(CountryBoundaryMapTest.class .getResourceAsStream("MAF_AIA_osm_boundaries_with_grid_index.txt.gz")) .withDecompressor(Decompressor.GZIP)); Assert.assertTrue(secondMap.hasGridIndex()); // Compare Assert.assertTrue(CountryBoundaryMapCompareCommand.areSTRtreesEqual(firstMap.getGridIndex(), secondMap.getGridIndex())); }
.backwardConvert(outline); complexBoundary.getCountries().forEach(isoCountry -> this .addCountry(isoCountry.getIso3CountryCode(), multiPolygon));