/** * If the given object is one of the recognized types, returns a short string representation * (typically the class name and the bounds). Otherwise returns {@code null}. * * @param geometry the geometry from which to get a string representation, or {@code null}. * @return a short string representation of the given geometry, or {@code null} if the given * object is not a recognized geometry. */ public static String toString(final Object geometry) { for (Geometries<?> g = implementation; g != null; g = g.fallback) { String s = g.tryGetLabel(geometry); if (s != null) { GeneralEnvelope env = g.tryGetEnvelope(geometry); if (env != null) { final String bbox = env.toString(); s += bbox.substring(bbox.indexOf('(')); } return s; } } return null; }
/** * If the given object is one of the recognized types, returns a short string representation * (typically the class name and the bounds). Otherwise returns {@code null}. * * @param geometry the geometry from which to get a string representation, or {@code null}. * @return a short string representation of the given geometry, or {@code null} if the given * object is not a recognized geometry. */ public static String toString(final Object geometry) { for (Geometries<?> g = implementation; g != null; g = g.fallback) { String s = g.tryGetLabel(geometry); if (s != null) { GeneralEnvelope env = g.tryGetEnvelope(geometry); if (env != null) { final String bbox = env.toString(); s += bbox.substring(bbox.indexOf('(')); } return s; } } return null; }
/** * Tests the {@link GeneralEnvelope#toString()} method. */ @Test public void testToString() { GeneralEnvelope envelope = new GeneralEnvelope(new double[] {-180, -90}, new double[] {180, 90}); assertEquals("BOX(-180 -90, 180 90)", envelope.toString()); envelope = new GeneralEnvelope(3); envelope.setRange(0, -180, +180); envelope.setRange(1, -90, +90); envelope.setRange(2, 10, 30); assertEquals("BOX3D(-180 -90 10, 180 90 30)", envelope.toString()); }
validate(envelope); assertEquals("BOX(6 10, 6 10)", new GeneralEnvelope("POINT(6 10)").toString()); assertEquals("BOX3D(6 10 3, 6 10 3)", new GeneralEnvelope("POINT M [ 6 10 3 ] ").toString()); assertEquals("BOX(3 4, 20 50)", new GeneralEnvelope("LINESTRING(3 4,10 50,20 25)").toString()); assertEquals("BOX(1 1, 6 5)", new GeneralEnvelope( "MULTIPOLYGON(((1 1,5 1,5 5,1 5,1 1),(2 2, 3 2, 3 3, 2 3,2 2)),((3 3,6 2,6 4,3 3)))").toString()); assertEquals("BOX(3 6, 7 10)", new GeneralEnvelope("GEOMETRYCOLLECTION(POINT(4 6),LINESTRING(3 8,7 10))").toString()); assertEquals(0, new GeneralEnvelope("BOX()").getDimension());