/** * @param location * The {@link Location} to check * @return the resulting {@link CountryCodeProperties} * @see #getCountryCodeISO3(Geometry) */ public CountryCodeProperties getCountryCodeISO3(final Location location) { return this.getCountryCodeISO3(JTS_POINT_CONVERTER.convert(location)); }
@Override public byte[] convert(final Location location) { final Geometry geometry = new JtsPointConverter().convert(location); final byte[] wkb = new WKBWriter().write(geometry); return wkb; } }
@Override public String convert(final Location location) { final Geometry geometry = new JtsPointConverter().convert(location); final String wkt = new WKTWriter().write(geometry); return wkt; } }
/** * Query country boundaries which cover given {@link Location} * * @param location * Any {@link Location} * @return a list of {@link CountryBoundary} */ public List<CountryBoundary> boundaries(final Location location) { return this.boundariesHelper(() -> this.query(location.bounds().asEnvelope()), boundary -> boundary.covers(JTS_POINT_CONVERTER.convert(location))); }
final Point point = new JtsPointConverter().convert(location); return polygon.covers(point);
@Test public void testGetCountryCode() { final CountryBoundaryMap map = CountryBoundaryMap.fromPlainText(new InputStreamResource( CountryBoundaryMapTest.class.getResourceAsStream("HTI_DOM_osm_boundaries.txt.gz")) .withDecompressor(Decompressor.GZIP)); Assert.assertFalse(map.hasGridIndex()); Point point = JTS_POINT_CONVERTER .convert(Location.forString("19.068387997775737, -71.7029007844633")); CountryCodeProperties countryDetails = map.getCountryCodeISO3(point); Assert.assertEquals("DOM", countryDetails.getIso3CountryCode()); point = JTS_POINT_CONVERTER .convert(Location.forString("19.069172931560374, -71.70712929872246")); countryDetails = map.getCountryCodeISO3(point); Assert.assertEquals("HTI", countryDetails.getIso3CountryCode()); point = JTS_POINT_CONVERTER.convert(Location.forString("19.0681781, -71.7075623")); countryDetails = map.getCountryCodeISO3(point, false); Assert.assertEquals("HTI,DOM", countryDetails.getIso3CountryCode()); }