public static GeometryType geometryFromGeoJson(ClobType json, int srid) throws FunctionExecutionException { try { GeoJSONReader reader = new GeoJSONReader(); String jsonText = ClobType.getString(json); Geometry jtsGeometry = reader.read(jsonText); return getGeometryType(jtsGeometry, srid); } catch (SQLException e) { throw new FunctionExecutionException(e); } catch (IOException e) { throw new FunctionExecutionException(e); } }
public static GeometryType geometryFromGeoJson(ClobType json, int srid) throws FunctionExecutionException { try { GeoJSONReader reader = new GeoJSONReader(); String jsonText = ClobType.getString(json); Geometry jtsGeometry = reader.read(jsonText); return getGeometryType(jtsGeometry, srid); } catch (SQLException e) { throw new FunctionExecutionException(e); } catch (IOException e) { throw new FunctionExecutionException(e); } }
public static GeometryType geometryFromGeoJson(ClobType json, int srid) throws FunctionExecutionException { try { GeoJSONReader reader = new GeoJSONReader(); String jsonText = ClobType.getString(json); Geometry jtsGeometry = reader.read(jsonText); return getGeometryType(jtsGeometry, srid); } catch (SQLException e) { throw new FunctionExecutionException(e); } catch (IOException e) { throw new FunctionExecutionException(e); } }
@Test public void testUpperLowerClob() throws Exception { char[] val = new char[] {87, 122, 147, 0xD801, 0xDC37}; assertEquals(new String(val).toUpperCase(), ClobType.getString(FunctionMethods.upperCase(new ClobType(ClobImpl.createClob(val))))); assertEquals(new String(val).toLowerCase(), ClobType.getString(FunctionMethods.lowerCase(new ClobType(ClobImpl.createClob(val))))); }
@Test public void testGeoJson() throws Exception { Expression ex = TestFunctionResolving.getExpression("ST_AsText(ST_GeomFromGeoJson(ST_AsGeoJSON(ST_GeomFromText('MULTIPOINT ((10 40), (40 30), (20 20), (30 10))'))))"); assertEquals("MULTIPOINT ((10 40), (40 30), (20 20), (30 10))", ClobType.getString((ClobType)Evaluator.evaluate(ex))); ex = TestFunctionResolving.getExpression("ST_AsText(ST_GeomFromGeoJson(ST_AsGeoJSON(ST_GeomFromText('MULTILINESTRING ((10 10, 20 20, 10 40),(40 40, 30 30, 40 20, 30 10))'))))"); assertEquals("MULTILINESTRING ((10 10, 20 20, 10 40), (40 40, 30 30, 40 20, 30 10))", ClobType.getString((ClobType)Evaluator.evaluate(ex))); ex = TestFunctionResolving.getExpression("ST_AsText(ST_GeomFromGeoJson(ST_AsGeoJSON(ST_GeomFromText('LINESTRING (30 10, 10 30, 40 40)'))))"); assertEquals("LINESTRING (30 10, 10 30, 40 40)", ClobType.getString((ClobType)Evaluator.evaluate(ex))); }
@Test public void testIntersection() throws Exception { Expression ex = TestFunctionResolving.getExpression("ST_AsText(st_intersection(ST_GeomFromText('POLYGON ((0 50, 50 50, 40 0, 0 0, 0 50))'), ST_GeomFromText('POLYGON ((0 50, 40 50, 40 0, 0 0, 0 50))')))"); ClobType intersection = (ClobType) Evaluator.evaluate(ex); assertEquals("POLYGON ((0 50, 40 50, 40 0, 0 0, 0 50))", ClobType.getString(intersection)); ex = TestFunctionResolving.getExpression("ST_AsText(st_intersection(ST_GeomFromText('POLYGON ((0 50, 50 50, 40 0, 0 0, 0 50))'), ST_GeomFromText('POLYGON ((150 50, 200 50, 190 0, 150 0, 150 50))')))"); intersection = (ClobType) Evaluator.evaluate(ex); assertEquals("POLYGON EMPTY", ClobType.getString(intersection)); }
@Test public void testPointOnSurface() throws Exception { Expression ex = TestFunctionResolving.getExpression("ST_AsText(ST_PointOnSurface(ST_GeomFromText('POLYGON ((67 13, 67 18, 59 18, 59 13, 67 13))')));"); ClobType pointOnSurface = (ClobType) Evaluator.evaluate(ex); assertEquals("POINT (63 15.5)", ClobType.getString(pointOnSurface)); ex = TestFunctionResolving.getExpression("ST_AsText(ST_PointOnSurface(ST_GeomFromText('POLYGON ((50 0, 50 10, 10 10, 10 50, 50 50, 50 60, 0 60, 0 0, 50 0))')));"); pointOnSurface = (ClobType) Evaluator.evaluate(ex); assertEquals("POINT (5 30)", ClobType.getString(pointOnSurface)); }
@Test public void testAsText() throws Exception { Expression ex2 = TestFunctionResolving.getExpression("st_astext(ST_GeomFromText('POLYGON ((40 0, 50 50, 0 50, 0 0, 40 0))'))"); Clob val = (Clob) Evaluator.evaluate(ex2); assertEquals("POLYGON ((40 0, 50 50, 0 50, 0 0, 40 0))", ClobType.getString(val)); }
@Test public void testGeoJsonCollection() throws Exception { Expression ex = TestFunctionResolving.getExpression("ST_AsGeoJson(ST_GeomFromText('GEOMETRYCOLLECTION(POINT(4 6),LINESTRING(4 6,7 10))'))"); ClobType c = (ClobType) Evaluator.evaluate(ex); assertEquals("{\"type\":\"GeometryCollection\",\"geometries\":[{\"type\":\"Point\",\"coordinates\":[4.0,6.0]},{\"type\":\"LineString\",\"coordinates\":[[4.0,6.0],[7.0,10.0]]}]}", ClobType.getString(c)); }
@Test public void testEwkt() throws Exception { Expression ex = TestFunctionResolving.getExpression("st_asewkt(ST_GeomFromEwkt('POINT(0 0 0)')))"); assertEquals("POINT (0 0)", ClobType.getString((ClobType)Evaluator.evaluate(ex))); }
@Test public void testStartPoint() throws Exception { Expression ex = TestFunctionResolving.getExpression("ST_AsText(st_startpoint(ST_GEOMFROMTEXT('LINESTRING(0 0, 1 3)'))))"); assertEquals("POINT (0 0)", ClobType.getString((ClobType)Evaluator.evaluate(ex))); }
@Test public void testEndPoint() throws Exception { Expression ex = TestFunctionResolving.getExpression("ST_AsText(st_endpoint(ST_GEOMFROMTEXT('LINESTRING(0 0, 1 3)'))))"); assertEquals("POINT (1 3)", ClobType.getString((ClobType)Evaluator.evaluate(ex))); }
@Test public void testPolygon() throws Exception { Expression ex = TestFunctionResolving.getExpression("ST_ASEWKT(ST_Polygon(ST_GeomFromText('LINESTRING(75.15 29.53,77 29,77.6 29.5, 75.15 29.53)'), 4326))"); assertEquals("SRID=4326;POLYGON ((75.15 29.53, 77 29, 77.6 29.5, 75.15 29.53))", ClobType.getString((ClobType)Evaluator.evaluate(ex))); }
@Test public void testEnvelope() throws Exception { Expression ex = TestFunctionResolving.getExpression("ST_AsText(ST_Envelope(ST_GEOMFROMTEXT('LINESTRING(0 0, 1 3)')))"); ClobType c = (ClobType) Evaluator.evaluate(ex); assertEquals("POLYGON ((0 0, 0 3, 1 3, 1 0, 0 0))", ClobType.getString(c)); }
@Test public void testAsFromEwkb() throws Exception { Expression ex = TestFunctionResolving.getExpression("st_asewkt(st_geomfromewkb(st_asewkb(ST_GeomFromEwkt('SrID=4326;POINT(0 0)'))))"); assertEquals("SRID=4326;POINT (0 0)", ClobType.getString((ClobType)Evaluator.evaluate(ex))); }
@Test public void testSimplifyPreserveTopology() throws Exception { Expression ex = TestFunctionResolving.getExpression("ST_AsText(ST_SimplifyPreserveTopology(ST_GeomFromText('POLYGON((6 3,1 -2,-4 3,1 8,6 3))'),5))"); assertEquals("POLYGON ((6 3, 1 -2, -4 3, 1 8, 6 3))", ClobType.getString((ClobType)Evaluator.evaluate(ex))); }
@Test public void testSnapToGrid() throws Exception { Expression ex = TestFunctionResolving.getExpression("ST_AsText(ST_SnapToGrid(ST_GeomFromText('LINESTRING(1.1115678 2.123, 4.111111 3.2374897, 4.11112 3.23748667)'),.001))"); assertEquals("LINESTRING (1.112 2.123, 4.111 3.237)", ClobType.getString((ClobType)Evaluator.evaluate(ex))); }
@Test public void testForce2d() throws Exception { Expression ex = TestFunctionResolving.getExpression("st_astext(st_force_2d(ST_GEOMFROMTEXT('LINESTRING(0 0, 1 3)')))"); assertEquals("LINESTRING (0 0, 1 3)", ClobType.getString((ClobType)Evaluator.evaluate(ex))); }
@Test public void testSimplify() throws Exception { Expression ex = TestFunctionResolving.getExpression("ST_AsText(ST_SIMPLIFY(ST_GeomFromText('LINESTRING(1 1,2 2,2 3.5,1 3,1 2,2 1)'), 1))"); assertEquals("LINESTRING (1 1, 2 3.5, 2 1)", ClobType.getString((ClobType)Evaluator.evaluate(ex))); //ensure it creates an empty geometry ex = TestFunctionResolving.getExpression("ST_ISEmpty(ST_Simplify(ST_GeomFromText('POLYGON((6 3,1 -2,-4 3,1 8,6 3))'),5))"); assertTrue((Boolean)Evaluator.evaluate(ex)); }
@Test public void testEwktWithSRID() throws Exception { Expression ex = TestFunctionResolving.getExpression("st_asewkt(ST_GeomFromEwkt('SRID=4326;POINT(0 0)')))"); Evaluator.evaluate(ex); //whitespace ex = TestFunctionResolving.getExpression("st_asewkt(ST_GeomFromEwkt(' SRID=4326;POINT(0 0)')))"); Evaluator.evaluate(ex); //mixed case ex = TestFunctionResolving.getExpression("st_asewkt(ST_GeomFromEwkt('SrID=4326;POINT(0 0)')))"); assertEquals("SRID=4326;POINT (0 0)", ClobType.getString((ClobType)Evaluator.evaluate(ex))); }