GeoPoint extends GeoShapeBase implements Comparable<GeoPoint> { public static GeoPoint parse(String str) { String description; Matcher m = WITH_DESCRIPTION_PATTERN.matcher(str); if (m.matches()) { description = m.group(1).trim(); str = m.group(2).trim(); } else { description = null; } String[] parts = str.split(","); if (parts.length < 2) { throw new VertexiumInvalidShapeException("Too few parts to GeoPoint string. Expected at least 2 found " + parts.length + " for string: " + str); } if (parts.length >= 5) { throw new VertexiumInvalidShapeException("Too many parts to GeoPoint string. Expected less than or equal to 4 found " + parts.length + " for string: " + str); } int part = 0; double latitude = parsePart(parts[part++]); double longitude = parsePart(parts[part++]); Double altitude = null; Double accuracy = null; while (part < parts.length) { String p = parts[part].trim(); if (p.startsWith("~")) { if (accuracy != null) { throw new VertexiumInvalidShapeException("Cannot specify two accuracies (~) in GeoPoint string."); } accuracy = Double.parseDouble(p.substring(1)); } else { if (altitude != null) { throw new VertexiumInvalidShapeException("Cannot specify two altitudes in GeoPoint string."); } altitude = Double.parseDouble(p); } part++; } return new GeoPoint(latitude, longitude, altitude, accuracy, description); } protected  GeoPoint();  GeoPoint(double latitude, double longitude, Double altitude, Double accuracy, String description);  GeoPoint(double latitude, double longitude, Double altitude, String description);  GeoPoint(double latitude, double longitude, Double altitude);  GeoPoint(double latitude, double longitude);  GeoPoint(double latitude, double longitude, String description);  GeoPoint(double latitude, double longitude, Double altitude, Double accuracy); double getLatitude(); double getLongitude(); Double getAltitude(); Double getAccuracy(); @Override String toString(); @Override boolean intersects(GeoShape geoShape); @Override int hashCode(); @Override boolean equals(Object obj); static double distanceBetween(GeoPoint geoPoint1, GeoPoint geoPoint2); double distanceFrom(GeoPoint geoPoint); @Override int compareTo(GeoPoint other); static GeoPoint parse(String str); boolean isSouthEastOf(GeoPoint pt); boolean isSouthOf(GeoPoint pt); boolean isNorthWestOf(GeoPoint pt); double longitudinalDistanceTo(GeoPoint pt); boolean isNorthOf(GeoPoint pt); static GeoPoint calculateCenter(List<GeoPoint> geoPoints); static final double EQUALS_TOLERANCE_KM; }
@Test public void testParse() throws Exception { assertEquals(new GeoPoint(38.9283, -77.1753), GeoPoint.parse("38.9283, -77.1753")); assertEquals(new GeoPoint(38.9283, -77.1753, 500.0), GeoPoint.parse("38.9283, -77.1753, 500")); assertEquals(new GeoPoint(38.9283, -77.1753, 500.0, 25.0), GeoPoint.parse("38.9283, -77.1753, 500, ~25")); assertEquals(new GeoPoint(38.9283, -77.1753, null, 25.0), GeoPoint.parse("38.9283, -77.1753, ~25")); assertEquals(new GeoPoint(38.9283, -77.1753), GeoPoint.parse("38° 55' 41.88\", -77° 10' 31.0794\"")); try { GeoPoint.parse("38.9283"); throw new RuntimeException("Expected an exception"); } catch (VertexiumException ex) { } try { GeoPoint.parse("38.9283, -77.1753, 500, 10"); throw new RuntimeException("Expected an exception"); } catch (VertexiumException ex) { } try { GeoPoint.parse("38.9283, -77.1753, ~500, ~10"); throw new RuntimeException("Expected an exception"); } catch (VertexiumException ex) { } try { GeoPoint.parse("38.9283, -77.1753, 500, 10, 10"); throw new RuntimeException("Expected an exception"); } catch (VertexiumException ex) { } }