@Test public void testGeoShapeLineStringWkt() { LineString geom = rgb.createRandomLineString(); assertTrue(parserUtil.createGeometry(rgb.toWkt(geom)).equalsExact(geom, 1e-9)); }
@SuppressWarnings("unchecked") public Geometry createGeometry(Object obj) { final Geometry geometry; if (obj instanceof String) { final Matcher listMatcher = GEO_POINT_PATTERN.matcher((String) obj); if (listMatcher.matches()) { final double y = Double.valueOf(listMatcher.group(1)); final double x = Double.valueOf(listMatcher.group(2)); geometry = geometryFactory.createPoint(new Coordinate(x, y)); } else if (GEO_HASH_PATTERN.matcher((String) obj).matches()) { final LatLong latLon = GeoHash.decodeHash((String) obj); final Coordinate geoPoint = new Coordinate(latLon.getLon(), latLon.getLat()); final double lat = geoPoint.y; final double lon = geoPoint.x; geometry = geometryFactory.createPoint(new Coordinate(lon, lat)); } else if (WKT_PATTERN.matcher((String) obj).matches()) { Geometry geom; try { geom = wktReader.read((String) obj); } catch (ParseException e) { geom = null; } geometry = geom; } else { geometry = null; } } else if (obj instanceof List && ((List<?>) obj).size() == 2) { final List<?> values = (List<?>) obj; if (Number.class.isAssignableFrom(values.get(0).getClass())) { final double x = ((Number) values.get(0)).doubleValue(); final double y = ((Number) values.get(1)).doubleValue(); geometry = geometryFactory.createPoint(new Coordinate(x, y)); } else if (values.get(0) instanceof String) { final double x = Double.valueOf((String) values.get(0)); final double y = Double.valueOf((String) values.get(1)); geometry = geometryFactory.createPoint(new Coordinate(x, y)); } else { geometry = null; } } else if (obj instanceof Map) { geometry = createGeometry((Map<String, Object>) obj); } else { geometry = null; } return geometry; }
ElasticParserUtil { @SuppressWarnings("unchecked") public Geometry createGeometry(Object obj) { final Geometry geometry; if (obj instanceof String) { final Matcher listMatcher = GEO_POINT_PATTERN.matcher((String) obj); if (listMatcher.matches()) { final double y = Double.valueOf(listMatcher.group(1)); final double x = Double.valueOf(listMatcher.group(2)); geometry = geometryFactory.createPoint(new Coordinate(x, y)); } else if (GEO_HASH_PATTERN.matcher((String) obj).matches()) { final LatLong latLon = GeoHash.decodeHash((String) obj); final Coordinate geoPoint = new Coordinate(latLon.getLon(), latLon.getLat()); final double lat = geoPoint.y; final double lon = geoPoint.x; geometry = geometryFactory.createPoint(new Coordinate(lon, lat)); } else if (WKT_PATTERN.matcher((String) obj).matches()) { Geometry geom; try { geom = wktReader.read((String) obj); } catch (ParseException e) { geom = null; } geometry = geom; } else { geometry = null; } } else if (obj instanceof List && ((List<?>) obj).size() == 2) { final List<?> values = (List<?>) obj; if (Number.class.isAssignableFrom(values.get(0).getClass())) { final double x = ((Number) values.get(0)).doubleValue(); final double y = ((Number) values.get(1)).doubleValue(); geometry = geometryFactory.createPoint(new Coordinate(x, y)); } else if (values.get(0) instanceof String) { final double x = Double.valueOf((String) values.get(0)); final double y = Double.valueOf((String) values.get(1)); geometry = geometryFactory.createPoint(new Coordinate(x, y)); } else { geometry = null; } } else if (obj instanceof Map) { geometry = createGeometry((Map<String, Object>) obj); } else { geometry = null; } return geometry; } }
ElasticParserUtil { @SuppressWarnings("unchecked") public Geometry createGeometry(Object obj) { final Geometry geometry; if (obj instanceof String) { final Matcher listMatcher = GEO_POINT_PATTERN.matcher((String) obj); if (listMatcher.matches()) { final double y = Double.valueOf(listMatcher.group(1)); final double x = Double.valueOf(listMatcher.group(2)); geometry = geometryFactory.createPoint(new Coordinate(x, y)); } else if (GEO_HASH_PATTERN.matcher((String) obj).matches()) { final LatLong latLon = GeoHash.decodeHash((String) obj); final Coordinate geoPoint = new Coordinate(latLon.getLon(), latLon.getLat()); final double lat = geoPoint.y; final double lon = geoPoint.x; geometry = geometryFactory.createPoint(new Coordinate(lon, lat)); } else if (WKT_PATTERN.matcher((String) obj).matches()) { Geometry geom; try { geom = wktReader.read((String) obj); } catch (ParseException e) { geom = null; } geometry = geom; } else { geometry = null; } } else if (obj instanceof List && ((List<?>) obj).size() == 2) { final List<?> values = (List<?>) obj; if (Number.class.isAssignableFrom(values.get(0).getClass())) { final double x = ((Number) values.get(0)).doubleValue(); final double y = ((Number) values.get(1)).doubleValue(); geometry = geometryFactory.createPoint(new Coordinate(x, y)); } else if (values.get(0) instanceof String) { final double x = Double.valueOf((String) values.get(0)); final double y = Double.valueOf((String) values.get(1)); geometry = geometryFactory.createPoint(new Coordinate(x, y)); } else { geometry = null; } } else if (obj instanceof Map) { geometry = createGeometry((Map<String, Object>) obj); } else { geometry = null; } return geometry; } ElasticParserUtil(); }
ElasticParserUtil { @SuppressWarnings("unchecked") public Geometry createGeometry(Object obj) { final Geometry geometry; if (obj instanceof String) { final Matcher listMatcher = GEO_POINT_PATTERN.matcher((String) obj); if (listMatcher.matches()) { final double y = Double.valueOf(listMatcher.group(1)); final double x = Double.valueOf(listMatcher.group(2)); geometry = geometryFactory.createPoint(new Coordinate(x, y)); } else if (GEO_HASH_PATTERN.matcher((String) obj).matches()) { final LatLong latLon = GeoHash.decodeHash((String) obj); final Coordinate geoPoint = new Coordinate(latLon.getLon(), latLon.getLat()); final double lat = geoPoint.y; final double lon = geoPoint.x; geometry = geometryFactory.createPoint(new Coordinate(lon, lat)); } else if (WKT_PATTERN.matcher((String) obj).matches()) { Geometry geom; try { geom = wktReader.read((String) obj); } catch (ParseException e) { geom = null; } geometry = geom; } else { geometry = null; } } else if (obj instanceof List && ((List<?>) obj).size() == 2) { final List<?> values = (List<?>) obj; if (Number.class.isAssignableFrom(values.get(0).getClass())) { final double x = ((Number) values.get(0)).doubleValue(); final double y = ((Number) values.get(1)).doubleValue(); geometry = geometryFactory.createPoint(new Coordinate(x, y)); } else if (values.get(0) instanceof String) { final double x = Double.valueOf((String) values.get(0)); final double y = Double.valueOf((String) values.get(1)); geometry = geometryFactory.createPoint(new Coordinate(x, y)); } else { geometry = null; } } else if (obj instanceof Map) { geometry = createGeometry((Map<String, Object>) obj); } else { geometry = null; } return geometry; } ElasticParserUtil(); @SuppressWarnings("unchecked") Geometry createGeometry(Object obj); @SuppressWarnings({"rawtypes", "unchecked"}) Geometry createGeometry(final Map<String, Object> properties); List<Object> readField(Map<String, Object> source, String name); @SuppressWarnings("rawtypes") static boolean isGeoPointFeature(Map<String, Object> map); static String urlDecode(String value); }
ElasticParserUtil { @SuppressWarnings("unchecked") public Geometry createGeometry(Object obj) { final Geometry geometry; if (obj instanceof String) { final Matcher listMatcher = GEO_POINT_PATTERN.matcher((String) obj); if (listMatcher.matches()) { final double y = Double.valueOf(listMatcher.group(1)); final double x = Double.valueOf(listMatcher.group(2)); geometry = geometryFactory.createPoint(new Coordinate(x, y)); } else if (GEO_HASH_PATTERN.matcher((String) obj).matches()) { final LatLong latLon = GeoHash.decodeHash((String) obj); final Coordinate geoPoint = new Coordinate(latLon.getLon(), latLon.getLat()); final double lat = geoPoint.y; final double lon = geoPoint.x; geometry = geometryFactory.createPoint(new Coordinate(lon, lat)); } else if (WKT_PATTERN.matcher((String) obj).matches()) { Geometry geom; try { geom = wktReader.read((String) obj); } catch (ParseException e) { geom = null; } geometry = geom; } else { geometry = null; } } else if (obj instanceof List && ((List<?>) obj).size() == 2) { final List<?> values = (List<?>) obj; if (Number.class.isAssignableFrom(values.get(0).getClass())) { final double x = ((Number) values.get(0)).doubleValue(); final double y = ((Number) values.get(1)).doubleValue(); geometry = geometryFactory.createPoint(new Coordinate(x, y)); } else if (values.get(0) instanceof String) { final double x = Double.valueOf((String) values.get(0)); final double y = Double.valueOf((String) values.get(1)); geometry = geometryFactory.createPoint(new Coordinate(x, y)); } else { geometry = null; } } else if (obj instanceof Map) { geometry = createGeometry((Map<String, Object>) obj); } else { geometry = null; } return geometry; } ElasticParserUtil(); @SuppressWarnings("unchecked") Geometry createGeometry(Object obj); @SuppressWarnings({"rawtypes", "unchecked"}) Geometry createGeometry(final Map<String, Object> properties); List<Object> readField(Map<String, Object> source, String name); @SuppressWarnings("rawtypes") static boolean isGeoPointFeature(Map<String, Object> map); static String urlDecode(String value);  }