@Override public Geometry fromString(String string) { return Wkt.fromWkt( string ); }
@Override public Geometry getNullableResult(ResultSet rs, String columnName) throws SQLException { String value = rs.getString(columnName); if(!StringUtils.isEmpty(value)){ return Wkt.fromWkt(value); } return null; }
@Override public Geometry getNullableResult(ResultSet rs, int columnIndex) throws SQLException { String value = rs.getString(columnIndex); if(!StringUtils.isEmpty(value)){ return Wkt.fromWkt(value); } return null; }
@Override public Geometry getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { String value = cs.getString(columnIndex); if(!StringUtils.isEmpty(value)){ return Wkt.fromWkt(value); } return null; }
@Override public org.geolatte.geom.Geometry<?> convertObject(Object value) { if (isEmpty(value)){ return getDefaultValue(); }else if (value instanceof org.geolatte.geom.Geometry){ return (org.geolatte.geom.Geometry<?>)value; }else if (value instanceof String){ return Wkt.fromWkt((String)value); }else if (value instanceof com.vividsolutions.jts.geom.Geometry){ return JTS.from((com.vividsolutions.jts.geom.Geometry)value); } throw new IllegalArgumentException("value="+value); }
data.add(Wkt.fromWkt(wkt));
@Test public void polygon() { Polygon polygon = (org.geolatte.geom.Polygon) Wkt.fromWkt("POLYGON (" + "(30 10, 40 40, 20 40, 10 20, 30 10), " + "(20 30, 35 35, 30 20, 20 30))"); JGeometry geo = JGeometryConverter.convert(polygon); double[] extRing = new double[]{30, 10, 40, 40, 20, 40, 10, 20, 30, 10}; double[] intRing = new double[]{20, 30, 35, 35, 30, 20, 20, 30}; JGeometry geo2 = JGeometry.createLinearPolygon(new Object[]{extRing, intRing}, polygon.getCoordinateDimension(), polygon.getSRID()); assertEquals(geo2, geo); }
@Test public void point_methods2() { QShapes shapes1 = QShapes.shapes; QShapes shapes2 = new QShapes("shapes2"); List<Expression<?>> expressions = Lists.newArrayList(); expressions.addAll(createExpressions(shapes1.geometry.asPoint(), shapes2.geometry.asPoint())); expressions.addAll(createExpressions(shapes1.geometry.asPoint(), ConstantImpl.create((Point) Wkt.fromWkt("Point(2 2)")))); for (Expression<?> expr : expressions) { boolean logged = false; for (Object row : query().from(shapes1, shapes2) .where(shapes1.id.loe(5), shapes2.id.loe(5)).select(expr).fetch()) { if (row == null && !logged) { System.err.println(expr.toString()); logged = true; } } } }
@Test public void multiLineString() { MultiLineString multiLineString = (org.geolatte.geom.MultiLineString) Wkt.fromWkt("MULTILINESTRING (" + "(30 10, 40 40, 20 40, 10 20, 30 10), " + "(20 30, 35 35, 30 20, 20 30))"); JGeometry geo = JGeometryConverter.convert(multiLineString); double[] line1 = new double[]{30, 10, 40, 40, 20, 40, 10, 20, 30, 10}; double[] line2 = new double[]{20, 30, 35, 35, 30, 20, 20, 30}; JGeometry geo2 = JGeometry.createLinearMultiLineString(new Object[]{line1, line2}, multiLineString.getCoordinateDimension(), multiLineString.getSRID()); // System.err.println(Arrays.toString(geo.getElemInfo())); // System.err.println(Arrays.toString(geo.getOrdinatesArray())); // System.err.println(Arrays.toString(geo2.getElemInfo())); // System.err.println(Arrays.toString(geo2.getOrdinatesArray())); assertEquals(geo2, geo); }