This commit is contained in:
Timo Westkämper 2014-02-17 00:07:40 +02:00
parent 910bcad5e4
commit f751ff1af3
3 changed files with 68 additions and 19 deletions

View File

@ -200,7 +200,7 @@ public final class Connections {
.execute();
}
private static Map<Integer, String> getSpatialData() {
public static Map<Integer, String> getSpatialData() {
Map<Integer, String> m = Maps.newHashMap();
// point
m.put(1, "POINT (2 2)");
@ -226,25 +226,16 @@ public final class Connections {
"((20 35, 10 30, 10 10, 30 5, 45 20, 20 35), " +
"(30 20, 20 15, 20 25, 30 20)))");
// XXX POLYHEDRALSURFACE not supported
/* GEOMETRYCOLLECTION(POINT(4 6),LINESTRING(4 6,7 10))
POINT ZM (1 1 5 60)
POINT M (1 1 80)
POINT EMPTY
MULTIPOLYGON EMPTY
CIRCULARSTRING(1 5, 6 2, 7 3)
COMPOUNDCURVE(CIRCULARSTRING(0 0,1 1,1 0),(1 0,0 1))
CURVEPOLYGON(CIRCULARSTRING(-2 0,-1 -1,0 0,1 -1,2 0,0 2,-2 0),(-1 0,0 0.5,1 0,0 1,-1 0))
MULTICURVE((5 5,3 5,3 3,0 3),CIRCULARSTRING(0 0,2 1,2 2))
TRIANGLE((0 0 0,0 1 0,1 1 0,0 0 0))
TIN (((0 0 0, 0 0 1, 0 1 0, 0 0 0)), ((0 0 0, 0 1 0, 1 1 0, 0 0 0)))
POLYHEDRALSURFACE Z (
((0 0 0, 0 1 0, 1 1 0, 1 0 0, 0 0 0)),
((0 0 0, 0 1 0, 0 1 1, 0 0 1, 0 0 0)),
((0 0 0, 1 0 0, 1 0 1, 0 0 1, 0 0 0)),
((1 1 1, 1 0 1, 0 0 1, 0 1 1, 1 1 1)),
((1 1 1, 1 0 1, 1 0 0, 1 1 0, 1 1 1)),
((1 1 1, 1 1 0, 0 1 0, 0 1 1, 1 1 1))
)*/
*/
return m;
}

View File

@ -0,0 +1,17 @@
package com.mysema.query;
import static org.junit.Assert.assertNotNull;
import org.geolatte.geom.codec.Wkt;
import org.junit.Test;
public class ConnectionsTest {
@Test
public void Valid_Wkt() {
for (String wkt : Connections.getSpatialData().values()) {
assertNotNull(Wkt.newWktDecoder(Wkt.Dialect.POSTGIS_EWKT_1).decode(wkt));
}
}
}

View File

@ -32,6 +32,7 @@ import com.mysema.query.sql.spatial.QShapes;
import com.mysema.query.sql.spatial.Shapes;
import com.mysema.query.types.ConstantImpl;
import com.mysema.query.types.Expression;
import com.mysema.testutil.ExcludeIn;
public class SpatialBase extends AbstractBaseTest {
@ -68,6 +69,43 @@ public class SpatialBase extends AbstractBaseTest {
return query().from(shapes).where(shapes.id.between(14, 15));
}
@Test // FIXME, maybe use enum as the type ?!?
@ExcludeIn(H2)
public void GeometryType() {
List<Tuple> results = query().from(shapes).list(shapes.geometry, shapes.geometry.geometryType());
assertFalse(results.isEmpty());
for (Tuple row : results) {
assertEquals(
row.get(shapes.geometry).getGeometryType().name(),
row.get(shapes.geometry.geometryType()));
}
}
@Test
public void AsText() {
List<Tuple> results = query().from(shapes).list(shapes.geometry, shapes.geometry.asText());
assertFalse(results.isEmpty());
for (Tuple row : results) {
if (!(row.get(shapes.geometry) instanceof MultiPoint)) {
assertEquals(
row.get(shapes.geometry).asText().replace(" ", ""),
row.get(shapes.geometry.asText()).replace(" ", ""));
}
}
}
@Test
@ExcludeIn(H2)
public void Point_X_Y() {
PointPath<Point> point = new PointPath<Point>(Point.class, shapes, "geometry");
List<Tuple> results = withPoints().list(point, point.x(), point.y());
assertFalse(results.isEmpty());
for (Tuple row : results) {
assertEquals(Double.valueOf(row.get(point).getX()), row.get(point.x()));
assertEquals(Double.valueOf(row.get(point).getY()), row.get(point.y()));
}
}
@Test
public void Point_Instances() {
List<Shapes> results = withPoints().list(shapes);
@ -260,7 +298,7 @@ public class SpatialBase extends AbstractBaseTest {
// polygon specific
add(expressions, polygon.exterorRing(), H2);
add(expressions, polygon.numInteriorRing(), H2);
add(expressions, polygon.interiorRingN(0), H2);
add(expressions, polygon.interiorRingN(1), H2);
for (Expression<?> expr : expressions) {
boolean logged = false;
@ -289,7 +327,7 @@ public class SpatialBase extends AbstractBaseTest {
add(expressions, multipoint.isSimple());
// multipoint specific
add(expressions, multipoint.numGeometries(), H2);
add(expressions, multipoint.geometryN(0), H2);
add(expressions, multipoint.geometryN(1), H2);
for (Expression<?> expr : expressions) {
boolean logged = false;
@ -316,9 +354,12 @@ public class SpatialBase extends AbstractBaseTest {
add(expressions, multilinestring.geometryType(), H2);
add(expressions, multilinestring.isEmpty());
add(expressions, multilinestring.isSimple());
// multipoint specific
// multicurve specific
add(expressions, multilinestring.isClosed(), H2);
add(expressions, multilinestring.length(), H2);
// multilinestring specific
add(expressions, multilinestring.numGeometries(), H2);
add(expressions, multilinestring.geometryN(0), H2);
add(expressions, multilinestring.geometryN(1), H2);
for (Expression<?> expr : expressions) {
boolean logged = false;
@ -345,9 +386,9 @@ public class SpatialBase extends AbstractBaseTest {
add(expressions, multipolygon.geometryType(), H2);
add(expressions, multipolygon.isEmpty());
add(expressions, multipolygon.isSimple());
// multipoint specific
// multipolygon specific
add(expressions, multipolygon.numGeometries(), H2);
add(expressions, multipolygon.geometryN(0), H2);
add(expressions, multipolygon.geometryN(1), H2);
for (Expression<?> expr : expressions) {
boolean logged = false;