From 30d9a923f166a0d94a817a65ff61c5c6c397dcd9 Mon Sep 17 00:00:00 2001 From: Erwan Bocher Date: Thu, 18 Dec 2014 22:56:12 +0100 Subject: [PATCH 1/8] Add singlesidebuffer function --- .../h2spatialext/CreateSpatialExtension.java | 3 +- .../processing/ST_SingleSideBuffer.java | 121 ++++++++++++++++++ 2 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/processing/ST_SingleSideBuffer.java diff --git a/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/CreateSpatialExtension.java b/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/CreateSpatialExtension.java index 071fd4241d..105fdfbbcb 100644 --- a/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/CreateSpatialExtension.java +++ b/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/CreateSpatialExtension.java @@ -180,7 +180,8 @@ public static Function[] getBuiltInsFunctions() throws SQLException { new ST_ProjectPoint(), new ST_CollectExtract(), new DoubleRange(), - new IntegerRange()}; + new IntegerRange(), + new ST_SingleSideBuffer()}; } /** diff --git a/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/processing/ST_SingleSideBuffer.java b/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/processing/ST_SingleSideBuffer.java new file mode 100644 index 0000000000..d3eef6bbc0 --- /dev/null +++ b/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/processing/ST_SingleSideBuffer.java @@ -0,0 +1,121 @@ +/** + * h2spatial is a library that brings spatial support to the H2 Java database. + * + * h2spatial is distributed under GPL 3 license. It is produced by the "Atelier SIG" + * team of the IRSTV Institute CNRS FR 2488. + * + * Copyright (C) 2007-2014 IRSTV (FR CNRS 2488) + * + * h2patial is free software: you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later + * version. + * + * h2spatial is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * h2spatial. If not, see . + * + * For more information, please consult: + * or contact directly: + * info_at_ orbisgis.org + */ + +package org.h2gis.h2spatialext.function.spatial.processing; + +import com.vividsolutions.jts.geom.Geometry; +import com.vividsolutions.jts.operation.buffer.BufferOp; +import com.vividsolutions.jts.operation.buffer.BufferParameters; +import org.h2gis.h2spatialapi.DeterministicScalarFunction; + +/** + * Compute a single buffer on one side. + * + * @author Erwan Bocher + */ +public class ST_SingleSideBuffer extends DeterministicScalarFunction{ + + public ST_SingleSideBuffer() { + addProperty(PROP_REMARKS, "Return a buffer at a given distance on only one side of each input lines of the geometry.\n" + + "The optional third parameter can either specify number of segments used\n" + + " to approximate a quarter circle (integer case, defaults to 8)\n" + + " or a list of blank-separated key=value pairs (string case) to manage line style parameters :\n" + + "'quad_segs=8' endcap=round|flat|square' 'join=round|mitre|bevel' 'mitre_limit=5'"); + } + + + + @Override + public String getJavaStaticMethod() { + return "singleSideBuffer"; + } + + /** + * + * @param geometry + * @param distance + * @return + */ + public static Geometry singleSideBuffer(Geometry geometry, double distance){ + return computeSingleSideBuffer(geometry, distance, new BufferParameters()); + } + + /** + * + * @param geometry + * @param distance + * @param parameters + * @return + */ + public static Geometry singleSideBuffer(Geometry geometry, double distance, String parameters){ + String[] buffParemeters = parameters.split("\\s+"); + BufferParameters bufferParameters = new BufferParameters(); + for (String params : buffParemeters) { + String[] keyValue = params.split("="); + if (keyValue[0].equalsIgnoreCase("endcap")) { + String param = keyValue[1]; + if (param.equalsIgnoreCase("round")) { + bufferParameters.setEndCapStyle(BufferParameters.CAP_ROUND); + } else if (param.equalsIgnoreCase("flat") || param.equalsIgnoreCase("butt")) { + bufferParameters.setEndCapStyle(BufferParameters.CAP_FLAT); + } else if (param.equalsIgnoreCase("square")) { + bufferParameters.setEndCapStyle(BufferParameters.CAP_SQUARE); + } else { + throw new IllegalArgumentException("Supported join values are round, flat, butt or square."); + } + } else if (keyValue[0].equalsIgnoreCase("join")) { + String param = keyValue[1]; + if (param.equalsIgnoreCase("bevel")) { + bufferParameters.setJoinStyle(BufferParameters.JOIN_BEVEL); + } else if (param.equalsIgnoreCase("mitre") || param.equalsIgnoreCase("miter")) { + bufferParameters.setJoinStyle(BufferParameters.JOIN_MITRE); + } else if (param.equalsIgnoreCase("round")) { + bufferParameters.setJoinStyle(BufferParameters.JOIN_ROUND); + } else { + throw new IllegalArgumentException("Supported join values are bevel, mitre, miter or round."); + } + } else if (keyValue[0].equalsIgnoreCase("mitre_limit") || keyValue[0].equalsIgnoreCase("miter_limit")) { + bufferParameters.setMitreLimit(Double.valueOf(keyValue[1])); + } else if (keyValue[0].equalsIgnoreCase("quad_segs")) { + bufferParameters.setQuadrantSegments(Integer.valueOf(keyValue[1])); + } else { + throw new IllegalArgumentException("Unknown parameters. Please read the documentation."); + } + } + return computeSingleSideBuffer(geometry, distance, bufferParameters); + } + + /** + * + * @param geometry + * @param distance + * @param bufferParameters + * @return + */ + private static Geometry computeSingleSideBuffer(Geometry geometry, double distance, BufferParameters bufferParameters){ + bufferParameters.setSingleSided(true); + return BufferOp.bufferOp(geometry, distance, bufferParameters); + } +} From fd7486911f079c7d03932e87c13d431d117f0db2 Mon Sep 17 00:00:00 2001 From: Erwan Bocher Date: Fri, 19 Dec 2014 16:15:56 +0100 Subject: [PATCH 2/8] Add singlesidebuffer function --- .../spatial/create/ST_RingBuffer.java | 2 + .../processing/ST_SingleSideBuffer.java | 26 +++++------ .../h2spatialext/SpatialFunctionTest.java | 44 +++++++++++++++++++ 3 files changed, 56 insertions(+), 16 deletions(-) diff --git a/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/create/ST_RingBuffer.java b/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/create/ST_RingBuffer.java index a84f4618ec..d8608c148d 100644 --- a/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/create/ST_RingBuffer.java +++ b/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/create/ST_RingBuffer.java @@ -75,6 +75,7 @@ public static Geometry ringBuffer(Geometry geom, double bufferSize, int numBuffe * @param numBuffer * @param endCapStyle * @return + * @throws java.sql.SQLException */ public static Geometry ringBuffer(Geometry geom, double bufferDistance, int numBuffer, String endCapStyle) throws SQLException { @@ -87,6 +88,7 @@ public static Geometry ringBuffer(Geometry geom, double bufferDistance, * @param bufferDistance * @param numBuffer * @param endCapStyle + * @param doDifference * @throws SQLException * @return */ diff --git a/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/processing/ST_SingleSideBuffer.java b/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/processing/ST_SingleSideBuffer.java index d3eef6bbc0..5bd0618a2c 100644 --- a/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/processing/ST_SingleSideBuffer.java +++ b/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/processing/ST_SingleSideBuffer.java @@ -28,11 +28,13 @@ import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.operation.buffer.BufferOp; import com.vividsolutions.jts.operation.buffer.BufferParameters; +import org.h2gis.h2spatial.internal.function.spatial.operators.ST_Buffer; import org.h2gis.h2spatialapi.DeterministicScalarFunction; /** * Compute a single buffer on one side. * + * * @author Erwan Bocher */ public class ST_SingleSideBuffer extends DeterministicScalarFunction{ @@ -42,7 +44,8 @@ public ST_SingleSideBuffer() { + "The optional third parameter can either specify number of segments used\n" + " to approximate a quarter circle (integer case, defaults to 8)\n" + " or a list of blank-separated key=value pairs (string case) to manage line style parameters :\n" - + "'quad_segs=8' endcap=round|flat|square' 'join=round|mitre|bevel' 'mitre_limit=5'"); + + "'quad_segs=8' 'join=round|mitre|bevel' 'mitre_limit=5'\n" + + "The End Cap Style for single-sided buffers is always ignored, and forced to the equivalent of flat."); } @@ -53,7 +56,7 @@ public String getJavaStaticMethod() { } /** - * + * Compute a single side buffer with default parameters * @param geometry * @param distance * @return @@ -63,7 +66,9 @@ public static Geometry singleSideBuffer(Geometry geometry, double distance){ } /** - * + * Compute a single side buffer with join and mitre parameters + * Note : + * The End Cap Style for single-sided buffers is always ignored, and forced to the equivalent of flat. * @param geometry * @param distance * @param parameters @@ -74,18 +79,7 @@ public static Geometry singleSideBuffer(Geometry geometry, double distance, Stri BufferParameters bufferParameters = new BufferParameters(); for (String params : buffParemeters) { String[] keyValue = params.split("="); - if (keyValue[0].equalsIgnoreCase("endcap")) { - String param = keyValue[1]; - if (param.equalsIgnoreCase("round")) { - bufferParameters.setEndCapStyle(BufferParameters.CAP_ROUND); - } else if (param.equalsIgnoreCase("flat") || param.equalsIgnoreCase("butt")) { - bufferParameters.setEndCapStyle(BufferParameters.CAP_FLAT); - } else if (param.equalsIgnoreCase("square")) { - bufferParameters.setEndCapStyle(BufferParameters.CAP_SQUARE); - } else { - throw new IllegalArgumentException("Supported join values are round, flat, butt or square."); - } - } else if (keyValue[0].equalsIgnoreCase("join")) { + if (keyValue[0].equalsIgnoreCase("join")) { String param = keyValue[1]; if (param.equalsIgnoreCase("bevel")) { bufferParameters.setJoinStyle(BufferParameters.JOIN_BEVEL); @@ -108,7 +102,7 @@ public static Geometry singleSideBuffer(Geometry geometry, double distance, Stri } /** - * + * Compute the buffer * @param geometry * @param distance * @param bufferParameters diff --git a/h2spatial-ext/src/test/java/org/h2gis/h2spatialext/SpatialFunctionTest.java b/h2spatial-ext/src/test/java/org/h2gis/h2spatialext/SpatialFunctionTest.java index df90eca290..3d5614fc97 100644 --- a/h2spatial-ext/src/test/java/org/h2gis/h2spatialext/SpatialFunctionTest.java +++ b/h2spatial-ext/src/test/java/org/h2gis/h2spatialext/SpatialFunctionTest.java @@ -3261,6 +3261,50 @@ public void test_ST_CollectExtract6() throws Exception { rs.close(); } + @Test + public void test_ST_SingleSideBuffer1() throws Exception { + ResultSet rs = st.executeQuery("SELECT ST_SingleSideBuffer('LINESTRING (120 150, 180 270)', 10);"); + rs.next(); + assertEquals("POLYGON ((180 270, 120 150, 111.05572809000084 154.47213595499957, 171.05572809000085 274.4721359549996, 180 270))", + rs.getString(1)); + rs.close(); + } + + @Test + public void test_ST_SingleSideBuffer2() throws Exception { + ResultSet rs = st.executeQuery("SELECT ST_SingleSideBuffer('LINESTRING (120 150, 180 270)', -10);"); + rs.next(); + assertEquals("POLYGON ((120 150, 180 270, 188.94427190999915 265.5278640450004, 128.94427190999915 145.52786404500043, 120 150))", + rs.getString(1)); + rs.close(); + } + + @Test(expected = IllegalArgumentException.class) + public void test_ST_SingleSideBuffer3() throws Throwable { + try { + st.execute("SELECT ST_SingleSideBuffer('LINESTRING (120 150, 180 270)', 10, 'endcap=square');"); + } catch (JdbcSQLException e) { + throw e.getOriginalCause(); + } + } + + @Test + public void test_ST_SingleSideBuffer4() throws Exception { + ResultSet rs = st.executeQuery("SELECT ST_SingleSideBuffer('LINESTRING (100 200, 150 250, 200 200)', 10, 'join=round quad_segs=2');"); + rs.next(); + assertEquals("POLYGON ((200 200, 150 250, 100 200, 92.92893218813452 207.07106781186548, 142.92893218813452 257.0710678118655, 150 260, 157.07106781186548 257.0710678118655, 207.07106781186548 207.07106781186548, 200 200))", + rs.getString(1)); + rs.close(); + } + + @Test + public void test_ST_SingleSideBuffer5() throws Exception { + ResultSet rs = st.executeQuery("SELECT ST_SingleSideBuffer('POINT (100 200)', 10, 'join=round quad_segs=2');"); + rs.next(); + assertEquals("POLYGON ((110 200, 107.07106781186548 192.92893218813452, 100 190, 92.92893218813452 192.92893218813452, 90 200, 92.92893218813452 207.07106781186548, 100 210, 107.07106781186548 207.07106781186548, 110 200))", + rs.getString(1)); + rs.close(); + } From 0ec6cb46a17e857c9fe344a8e2309ccea8de8270 Mon Sep 17 00:00:00 2001 From: Erwan Bocher Date: Fri, 19 Dec 2014 18:00:55 +0100 Subject: [PATCH 3/8] Improve ringbuffer parameters --- .../spatial/create/ST_RingBuffer.java | 69 ++++++++++++------- .../processing/ST_SingleSideBuffer.java | 2 +- .../h2spatialext/SpatialFunctionTest.java | 19 +++-- 3 files changed, 59 insertions(+), 31 deletions(-) diff --git a/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/create/ST_RingBuffer.java b/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/create/ST_RingBuffer.java index d8608c148d..73cb9e0eae 100644 --- a/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/create/ST_RingBuffer.java +++ b/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/create/ST_RingBuffer.java @@ -25,7 +25,6 @@ import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.GeometryFactory; -import com.vividsolutions.jts.geom.MultiPolygon; import com.vividsolutions.jts.geom.Polygon; import com.vividsolutions.jts.operation.buffer.BufferOp; import com.vividsolutions.jts.operation.buffer.BufferParameters; @@ -40,8 +39,6 @@ */ public class ST_RingBuffer extends AbstractFunction implements ScalarFunction { - private static final String CAP_STYLE_SQUARE = "square"; - private static final String CAP_STYLE_ROUND = "round"; private static final GeometryFactory GF = new GeometryFactory(); public ST_RingBuffer() { @@ -63,9 +60,10 @@ public String getJavaStaticMethod() { * @param bufferSize * @param numBuffer * @return + * @throws java.sql.SQLException */ public static Geometry ringBuffer(Geometry geom, double bufferSize, int numBuffer) throws SQLException { - return ringBuffer(geom, bufferSize, numBuffer, CAP_STYLE_ROUND); + return ringBuffer(geom, bufferSize, numBuffer, "endcap=round"); } /** @@ -73,13 +71,13 @@ public static Geometry ringBuffer(Geometry geom, double bufferSize, int numBuffe * @param geom * @param bufferDistance * @param numBuffer - * @param endCapStyle + * @param parameters * @return * @throws java.sql.SQLException */ public static Geometry ringBuffer(Geometry geom, double bufferDistance, - int numBuffer, String endCapStyle) throws SQLException { - return ringBuffer(geom, bufferDistance, numBuffer, endCapStyle, true); + int numBuffer, String parameters) throws SQLException { + return ringBuffer(geom, bufferDistance, numBuffer, parameters, true); } /** @@ -87,23 +85,56 @@ public static Geometry ringBuffer(Geometry geom, double bufferDistance, * @param geom * @param bufferDistance * @param numBuffer - * @param endCapStyle + * @param parameters * @param doDifference * @throws SQLException * @return */ public static Geometry ringBuffer(Geometry geom, double bufferDistance, - int numBuffer, String endCapStyle, boolean doDifference) throws SQLException { + int numBuffer, String parameters, boolean doDifference) throws SQLException { if(!(bufferDistance > 0)) { // If buffer distance is not superior than zero return the same geometry. return geom; + } + String[] buffParemeters = parameters.split("\\s+"); + BufferParameters bufferParameters = new BufferParameters(); + for (String params : buffParemeters) { + String[] keyValue = params.split("="); + if (keyValue[0].equalsIgnoreCase("endcap")) { + String param = keyValue[1]; + if (param.equalsIgnoreCase("round")) { + bufferParameters.setEndCapStyle(BufferParameters.CAP_ROUND); + } else if (param.equalsIgnoreCase("square")) { + bufferParameters.setEndCapStyle(BufferParameters.CAP_SQUARE); + } else { + throw new IllegalArgumentException("Supported join values are round or square."); + } + } else if(keyValue[0].equalsIgnoreCase("join")) { + String param = keyValue[1]; + if (param.equalsIgnoreCase("bevel")) { + bufferParameters.setJoinStyle(BufferParameters.JOIN_BEVEL); + } else if (param.equalsIgnoreCase("mitre") || param.equalsIgnoreCase("miter")) { + bufferParameters.setJoinStyle(BufferParameters.JOIN_MITRE); + } else if (param.equalsIgnoreCase("round")) { + bufferParameters.setJoinStyle(BufferParameters.JOIN_ROUND); + } else { + throw new IllegalArgumentException("Supported join values are bevel, mitre, miter or round."); + } + } else if (keyValue[0].equalsIgnoreCase("mitre_limit") || keyValue[0].equalsIgnoreCase("miter_limit")) { + bufferParameters.setMitreLimit(Double.valueOf(keyValue[1])); + } else if (keyValue[0].equalsIgnoreCase("quad_segs")) { + bufferParameters.setQuadrantSegments(Integer.valueOf(keyValue[1])); + } else { + throw new IllegalArgumentException("Unknown parameters. Please read the documentation."); + } } + Polygon[] buffers = new Polygon[numBuffer]; Geometry previous = geom; double distance = 0; for (int i = 0; i < numBuffer; i++) { distance += bufferDistance; - Geometry newBuffer = runBuffer(geom, distance, endCapStyle); + Geometry newBuffer = runBuffer(geom, distance, bufferParameters); if(doDifference) { buffers[i] = (Polygon) newBuffer.difference(previous); } else { @@ -119,25 +150,11 @@ public static Geometry ringBuffer(Geometry geom, double bufferDistance, * * @param geom * @param bufferSize - * @param endCapStyle * @return * @throws SQLException */ private static Geometry runBuffer(final Geometry geom, final double bufferSize, - final String endCapStyle) throws SQLException { - BufferOp bufOp; - if (endCapStyle.equalsIgnoreCase(CAP_STYLE_SQUARE)) { - bufOp = new BufferOp(geom, new BufferParameters( - BufferParameters.DEFAULT_QUADRANT_SEGMENTS, - BufferParameters.CAP_SQUARE)); - return bufOp.getResultGeometry(bufferSize); - } else if (endCapStyle.equalsIgnoreCase(CAP_STYLE_ROUND)){ - bufOp = new BufferOp(geom, new BufferParameters( - BufferParameters.DEFAULT_QUADRANT_SEGMENTS, - BufferParameters.CAP_ROUND)); - return bufOp.getResultGeometry(bufferSize); - } - throw new SQLException("Invalid cap style value. Please use "+ CAP_STYLE_ROUND + " or " - + CAP_STYLE_SQUARE); + final BufferParameters bufferParameters) throws SQLException { + return BufferOp.bufferOp(geom, bufferSize, bufferParameters); } } diff --git a/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/processing/ST_SingleSideBuffer.java b/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/processing/ST_SingleSideBuffer.java index 5bd0618a2c..0d68bdec82 100644 --- a/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/processing/ST_SingleSideBuffer.java +++ b/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/processing/ST_SingleSideBuffer.java @@ -45,7 +45,7 @@ public ST_SingleSideBuffer() { + " to approximate a quarter circle (integer case, defaults to 8)\n" + " or a list of blank-separated key=value pairs (string case) to manage line style parameters :\n" + "'quad_segs=8' 'join=round|mitre|bevel' 'mitre_limit=5'\n" - + "The End Cap Style for single-sided buffers is always ignored, and forced to the equivalent of flat."); + + "The end cap style for single-sided buffers is always ignored, and forced to the equivalent of flat."); } diff --git a/h2spatial-ext/src/test/java/org/h2gis/h2spatialext/SpatialFunctionTest.java b/h2spatial-ext/src/test/java/org/h2gis/h2spatialext/SpatialFunctionTest.java index 3d5614fc97..6543380ea3 100644 --- a/h2spatial-ext/src/test/java/org/h2gis/h2spatialext/SpatialFunctionTest.java +++ b/h2spatial-ext/src/test/java/org/h2gis/h2spatialext/SpatialFunctionTest.java @@ -2689,7 +2689,7 @@ public void test_ST_RingBuffer2() throws Exception { @Test public void test_ST_RingBufferEndCapSQUARE() throws Exception { - ResultSet rs = st.executeQuery("SELECT ST_RingBuffer('POINT(2 2)', 2, 2, 'square');"); + ResultSet rs = st.executeQuery("SELECT ST_RingBuffer('POINT(2 2)', 2, 2, 'endcap=square');"); assertTrue(rs.next()); assertGeometryEquals("MULTIPOLYGON(((4 4, 4 0, 0 0, 0 4, 4 4)), ((6 6, 6 -2, -2 -2, -2 6, 6 6), (4 4, 0 4, 0 0, 4 0, 4 4)))", rs.getObject(1)); rs.close(); @@ -2697,7 +2697,7 @@ public void test_ST_RingBufferEndCapSQUARE() throws Exception { @Test public void test_ST_RingBufferEndCapROUND() throws Exception { - ResultSet rs = st.executeQuery("SELECT ST_RingBuffer('LINESTRING (-10 10, 10 10)'::GEOMETRY, 10, 3,'ROUND');"); + ResultSet rs = st.executeQuery("SELECT ST_RingBuffer('LINESTRING (-10 10, 10 10)'::GEOMETRY, 10, 3,'endcap=ROUND');"); assertTrue(rs.next()); assertGeometryBarelyEquals("MULTIPOLYGON (((10 20, 11.950903220161283 19.807852804032304, 13.826834323650898 19.238795325112868, 15.555702330196024 18.314696123025453, 17.071067811865476 17.071067811865476, 18.314696123025453 15.555702330196022, 19.238795325112868 13.826834323650898, 19.807852804032304 11.950903220161283, 20 10, 19.807852804032304 8.049096779838717, 19.238795325112868 6.173165676349102, 18.314696123025453 4.444297669803979, 17.071067811865476 2.9289321881345254, 15.55570233019602 1.6853038769745474, 13.826834323650894 0.7612046748871304, 11.950903220161276 0.1921471959676939, 10 0, -10 0, -11.950903220161287 0.1921471959676975, -13.826834323650903 0.7612046748871357, -15.555702330196022 1.6853038769745474, -17.071067811865476 2.9289321881345254, -18.314696123025456 4.44429766980398, -19.238795325112868 6.173165676349104, -19.807852804032304 8.049096779838717, -20 10.000000000000002, -19.807852804032304 11.950903220161287, -19.238795325112868 13.8268343236509, -18.314696123025453 15.555702330196022, -17.071067811865476 17.071067811865476, -15.55570233019602 18.314696123025453, -13.826834323650893 19.238795325112868, -11.950903220161276 19.807852804032308, -10 20, 10 20)), ((10 30, 13.901806440322567 29.61570560806461, 17.653668647301796 28.477590650225736, 21.111404660392047 26.629392246050905, 24.14213562373095 24.14213562373095, 26.629392246050905 21.111404660392044, 28.477590650225736 17.653668647301796, 29.61570560806461 13.901806440322565, 30 10, 29.61570560806461 6.098193559677435, 28.477590650225736 2.346331352698204, 26.629392246050905 -1.1114046603920418, 24.14213562373095 -4.142135623730949, 21.11140466039204 -6.629392246050905, 17.65366864730179 -8.47759065022574, 13.901806440322552 -9.615705608064612, 10 -10, -10 -10, -13.901806440322574 -9.615705608064605, -17.653668647301807 -8.477590650225729, -21.111404660392044 -6.629392246050905, -24.142135623730955 -4.142135623730949, -26.62939224605091 -1.11140466039204, -28.477590650225736 2.346331352698207, -29.61570560806461 6.098193559677433, -30 10.000000000000002, -29.61570560806461 13.901806440322572, -28.477590650225736 17.6536686473018, -26.629392246050905 21.111404660392044, -24.14213562373095 24.14213562373095, -21.11140466039204 26.629392246050905, -17.653668647301785 28.47759065022574, -13.90180644032255 29.615705608064612, -10 30, 10 30), (10 20, -10 20, -11.950903220161276 19.807852804032308, -13.826834323650893 19.238795325112868, -15.55570233019602 18.314696123025453, -17.071067811865476 17.071067811865476, -18.314696123025453 15.555702330196022, -19.238795325112868 13.8268343236509, -19.807852804032304 11.950903220161287, -20 10.000000000000002, -19.807852804032304 8.049096779838717, -19.238795325112868 6.173165676349104, -18.314696123025456 4.44429766980398, -17.071067811865476 2.9289321881345254, -15.555702330196022 1.6853038769745474, -13.826834323650903 0.7612046748871357, -11.950903220161287 0.1921471959676975, -10 0, 10 0, 11.950903220161276 0.1921471959676939, 13.826834323650894 0.7612046748871304, 15.55570233019602 1.6853038769745474, 17.071067811865476 2.9289321881345254, 18.314696123025453 4.444297669803979, 19.238795325112868 6.173165676349102, 19.807852804032304 8.049096779838717, 20 10, 19.807852804032304 11.950903220161283, 19.238795325112868 13.826834323650898, 18.314696123025453 15.555702330196022, 17.071067811865476 17.071067811865476, 15.555702330196024 18.314696123025453, 13.826834323650898 19.238795325112868, 11.950903220161283 19.807852804032304, 10 20)), ((10 40, 15.85270966048385 39.42355841209691, 21.480502970952696 37.7163859753386, 26.667106990588067 34.944088369076354, 31.213203435596427 31.213203435596423, 34.944088369076354 26.667106990588067, 37.7163859753386 21.480502970952692, 39.42355841209691 15.852709660483846, 40 10, 39.42355841209691 4.147290339516153, 37.7163859753386 -1.4805029709526938, 34.94408836907636 -6.6671069905880636, 31.213203435596427 -11.213203435596423, 26.667106990588064 -14.944088369076361, 21.48050297095268 -17.71638597533861, 15.85270966048383 -19.423558412096916, 10 -20, -10 -20, -15.85270966048386 -19.42355841209691, -21.48050297095271 -17.716385975338596, -26.667106990588067 -14.944088369076358, -31.21320343559643 -11.213203435596423, -34.94408836907637 -6.66710699058806, -37.71638597533861 -1.4805029709526902, -39.42355841209691 4.147290339516149, -40 10.000000000000004, -39.42355841209691 15.852709660483859, -37.7163859753386 21.4805029709527, -34.94408836907636 26.667106990588067, -31.213203435596423 31.213203435596427, -26.66710699058806 34.94408836907636, -21.480502970952678 37.71638597533861, -15.852709660483827 39.42355841209692, -10 40, 10 40), (10 30, -10 30, -13.90180644032255 29.615705608064612, -17.653668647301785 28.47759065022574, -21.11140466039204 26.629392246050905, -24.14213562373095 24.14213562373095, -26.629392246050905 21.111404660392044, -28.477590650225736 17.6536686473018, -29.61570560806461 13.901806440322572, -30 10.000000000000002, -29.61570560806461 6.098193559677433, -28.477590650225736 2.346331352698207, -26.62939224605091 -1.11140466039204, -24.142135623730955 -4.142135623730949, -21.111404660392044 -6.629392246050905, -17.653668647301807 -8.477590650225729, -13.901806440322574 -9.615705608064605, -10 -10, 10 -10, 13.901806440322552 -9.615705608064612, 17.65366864730179 -8.47759065022574, 21.11140466039204 -6.629392246050905, 24.14213562373095 -4.142135623730949, 26.629392246050905 -1.1114046603920418, 28.477590650225736 2.346331352698204, 29.61570560806461 6.098193559677435, 30 10, 29.61570560806461 13.901806440322565, 28.477590650225736 17.653668647301796, 26.629392246050905 21.111404660392044, 24.14213562373095 24.14213562373095, 21.111404660392047 26.629392246050905, " + "17.653668647301796 28.477590650225736, 13.901806440322567 29.61570560806461, 10 30)))", rs.getObject(1)); @@ -2706,16 +2706,27 @@ public void test_ST_RingBufferEndCapROUND() throws Exception { @Test(expected = SQLException.class) public void test_ST_RingBufferEndCapBUTT() throws Exception { - st.execute("SELECT ST_RingBuffer('LINESTRING (-10 10, 10 10)'::GEOMETRY, 10, 3,'BUTT');"); + st.execute("SELECT ST_RingBuffer('LINESTRING (-10 10, 10 10)'::GEOMETRY, 10, 3,'endcap=BUTT');"); } + @Test public void test_ST_RingBufferNoHole() throws Exception { - ResultSet rs = st.executeQuery("SELECT ST_RingBuffer('POINT(2 2)', 2, 2, 'square', false);"); + ResultSet rs = st.executeQuery("SELECT ST_RingBuffer('POINT(2 2)', 2, 2, 'endcap=square', false);"); assertTrue(rs.next()); assertGeometryEquals("MULTIPOLYGON(((4 4, 4 0, 0 0, 0 4, 4 4)), ((6 6, 6 -2, -2 -2, -2 6, 6 6)))", rs.getObject(1)); rs.close(); } + + @Test + public void test_ST_RingBufferComplex() throws Exception { + ResultSet rs = st.executeQuery("SELECT ST_RingBuffer('LINESTRING (-10 10, 10 10)'::GEOMETRY, 10, 3,'endcap=ROUND quad_segs=4');"); + assertTrue(rs.next()); + System.out.println(rs.getString(1)); + assertGeometryBarelyEquals("MULTIPOLYGON (((10 20, 11.950903220161283 19.807852804032304, 13.826834323650898 19.238795325112868, 15.555702330196024 18.314696123025453, 17.071067811865476 17.071067811865476, 18.314696123025453 15.555702330196022, 19.238795325112868 13.826834323650898, 19.807852804032304 11.950903220161283, 20 10, 19.807852804032304 8.049096779838717, 19.238795325112868 6.173165676349102, 18.314696123025453 4.444297669803979, 17.071067811865476 2.9289321881345254, 15.55570233019602 1.6853038769745474, 13.826834323650894 0.7612046748871304, 11.950903220161276 0.1921471959676939, 10 0, -10 0, -11.950903220161287 0.1921471959676975, -13.826834323650903 0.7612046748871357, -15.555702330196022 1.6853038769745474, -17.071067811865476 2.9289321881345254, -18.314696123025456 4.44429766980398, -19.238795325112868 6.173165676349104, -19.807852804032304 8.049096779838717, -20 10.000000000000002, -19.807852804032304 11.950903220161287, -19.238795325112868 13.8268343236509, -18.314696123025453 15.555702330196022, -17.071067811865476 17.071067811865476, -15.55570233019602 18.314696123025453, -13.826834323650893 19.238795325112868, -11.950903220161276 19.807852804032308, -10 20, 10 20)), ((10 30, 13.901806440322567 29.61570560806461, 17.653668647301796 28.477590650225736, 21.111404660392047 26.629392246050905, 24.14213562373095 24.14213562373095, 26.629392246050905 21.111404660392044, 28.477590650225736 17.653668647301796, 29.61570560806461 13.901806440322565, 30 10, 29.61570560806461 6.098193559677435, 28.477590650225736 2.346331352698204, 26.629392246050905 -1.1114046603920418, 24.14213562373095 -4.142135623730949, 21.11140466039204 -6.629392246050905, 17.65366864730179 -8.47759065022574, 13.901806440322552 -9.615705608064612, 10 -10, -10 -10, -13.901806440322574 -9.615705608064605, -17.653668647301807 -8.477590650225729, -21.111404660392044 -6.629392246050905, -24.142135623730955 -4.142135623730949, -26.62939224605091 -1.11140466039204, -28.477590650225736 2.346331352698207, -29.61570560806461 6.098193559677433, -30 10.000000000000002, -29.61570560806461 13.901806440322572, -28.477590650225736 17.6536686473018, -26.629392246050905 21.111404660392044, -24.14213562373095 24.14213562373095, -21.11140466039204 26.629392246050905, -17.653668647301785 28.47759065022574, -13.90180644032255 29.615705608064612, -10 30, 10 30), (10 20, -10 20, -11.950903220161276 19.807852804032308, -13.826834323650893 19.238795325112868, -15.55570233019602 18.314696123025453, -17.071067811865476 17.071067811865476, -18.314696123025453 15.555702330196022, -19.238795325112868 13.8268343236509, -19.807852804032304 11.950903220161287, -20 10.000000000000002, -19.807852804032304 8.049096779838717, -19.238795325112868 6.173165676349104, -18.314696123025456 4.44429766980398, -17.071067811865476 2.9289321881345254, -15.555702330196022 1.6853038769745474, -13.826834323650903 0.7612046748871357, -11.950903220161287 0.1921471959676975, -10 0, 10 0, 11.950903220161276 0.1921471959676939, 13.826834323650894 0.7612046748871304, 15.55570233019602 1.6853038769745474, 17.071067811865476 2.9289321881345254, 18.314696123025453 4.444297669803979, 19.238795325112868 6.173165676349102, 19.807852804032304 8.049096779838717, 20 10, 19.807852804032304 11.950903220161283, 19.238795325112868 13.826834323650898, 18.314696123025453 15.555702330196022, 17.071067811865476 17.071067811865476, 15.555702330196024 18.314696123025453, 13.826834323650898 19.238795325112868, 11.950903220161283 19.807852804032304, 10 20)), ((10 40, 15.85270966048385 39.42355841209691, 21.480502970952696 37.7163859753386, 26.667106990588067 34.944088369076354, 31.213203435596427 31.213203435596423, 34.944088369076354 26.667106990588067, 37.7163859753386 21.480502970952692, 39.42355841209691 15.852709660483846, 40 10, 39.42355841209691 4.147290339516153, 37.7163859753386 -1.4805029709526938, 34.94408836907636 -6.6671069905880636, 31.213203435596427 -11.213203435596423, 26.667106990588064 -14.944088369076361, 21.48050297095268 -17.71638597533861, 15.85270966048383 -19.423558412096916, 10 -20, -10 -20, -15.85270966048386 -19.42355841209691, -21.48050297095271 -17.716385975338596, -26.667106990588067 -14.944088369076358, -31.21320343559643 -11.213203435596423, -34.94408836907637 -6.66710699058806, -37.71638597533861 -1.4805029709526902, -39.42355841209691 4.147290339516149, -40 10.000000000000004, -39.42355841209691 15.852709660483859, -37.7163859753386 21.4805029709527, -34.94408836907636 26.667106990588067, -31.213203435596423 31.213203435596427, -26.66710699058806 34.94408836907636, -21.480502970952678 37.71638597533861, -15.852709660483827 39.42355841209692, -10 40, 10 40), (10 30, -10 30, -13.90180644032255 29.615705608064612, -17.653668647301785 28.47759065022574, -21.11140466039204 26.629392246050905, -24.14213562373095 24.14213562373095, -26.629392246050905 21.111404660392044, -28.477590650225736 17.6536686473018, -29.61570560806461 13.901806440322572, -30 10.000000000000002, -29.61570560806461 6.098193559677433, -28.477590650225736 2.346331352698207, -26.62939224605091 -1.11140466039204, -24.142135623730955 -4.142135623730949, -21.111404660392044 -6.629392246050905, -17.653668647301807 -8.477590650225729, -13.901806440322574 -9.615705608064605, -10 -10, 10 -10, 13.901806440322552 -9.615705608064612, 17.65366864730179 -8.47759065022574, 21.11140466039204 -6.629392246050905, 24.14213562373095 -4.142135623730949, 26.629392246050905 -1.1114046603920418, 28.477590650225736 2.346331352698204, 29.61570560806461 6.098193559677435, 30 10, 29.61570560806461 13.901806440322565, 28.477590650225736 17.653668647301796, 26.629392246050905 21.111404660392044, 24.14213562373095 24.14213562373095, 21.111404660392047 26.629392246050905, " + + "17.653668647301796 28.477590650225736, 13.901806440322567 29.61570560806461, 10 30)))", rs.getObject(1)); + rs.close(); + } @Test public void test_ST_MinimumDiameter1() throws Exception { From 7ab44d5bcfba59c3f8c4710cd4d77247edd4de11 Mon Sep 17 00:00:00 2001 From: Erwan Bocher Date: Mon, 5 Jan 2015 13:39:24 +0100 Subject: [PATCH 4/8] Improve ringbuffer parameters and add new tests --- .../spatial/create/ST_RingBuffer.java | 6 ++++-- .../processing/ST_SingleSideBuffer.java | 1 - .../h2spatialext/SpatialFunctionTest.java | 20 ++++++++++++++++--- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/create/ST_RingBuffer.java b/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/create/ST_RingBuffer.java index 73cb9e0eae..98819a0252 100644 --- a/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/create/ST_RingBuffer.java +++ b/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/create/ST_RingBuffer.java @@ -45,8 +45,10 @@ public ST_RingBuffer() { addProperty(PROP_REMARKS, "Compute a ring buffer around a geometry.\n" + "Avalaible arguments are :\n" + " (1) the geometry, (2) the size of each ring, " - + " (3) the number of rings, (4) optional - the end cap style (square, round) Default is round\n"+ - " (5) optional - createHole True if you want to keep only difference between buffers Default is true"); + + " (3) the number of rings, (4) optional - the end cap style (square, round) Default is round\n" + + "a list of blank-separated key=value pairs (string case) iso used t manage line style parameters.\n " + + "Please read the ST_Buffer documention.\n" + + " (5) optional - createHole True if you want to keep only difference between buffers Default is true"); } @Override diff --git a/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/processing/ST_SingleSideBuffer.java b/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/processing/ST_SingleSideBuffer.java index 0d68bdec82..08176211d6 100644 --- a/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/processing/ST_SingleSideBuffer.java +++ b/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/processing/ST_SingleSideBuffer.java @@ -28,7 +28,6 @@ import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.operation.buffer.BufferOp; import com.vividsolutions.jts.operation.buffer.BufferParameters; -import org.h2gis.h2spatial.internal.function.spatial.operators.ST_Buffer; import org.h2gis.h2spatialapi.DeterministicScalarFunction; /** diff --git a/h2spatial-ext/src/test/java/org/h2gis/h2spatialext/SpatialFunctionTest.java b/h2spatial-ext/src/test/java/org/h2gis/h2spatialext/SpatialFunctionTest.java index 6543380ea3..21d5510d30 100644 --- a/h2spatial-ext/src/test/java/org/h2gis/h2spatialext/SpatialFunctionTest.java +++ b/h2spatial-ext/src/test/java/org/h2gis/h2spatialext/SpatialFunctionTest.java @@ -2722,9 +2722,23 @@ public void test_ST_RingBufferNoHole() throws Exception { public void test_ST_RingBufferComplex() throws Exception { ResultSet rs = st.executeQuery("SELECT ST_RingBuffer('LINESTRING (-10 10, 10 10)'::GEOMETRY, 10, 3,'endcap=ROUND quad_segs=4');"); assertTrue(rs.next()); - System.out.println(rs.getString(1)); - assertGeometryBarelyEquals("MULTIPOLYGON (((10 20, 11.950903220161283 19.807852804032304, 13.826834323650898 19.238795325112868, 15.555702330196024 18.314696123025453, 17.071067811865476 17.071067811865476, 18.314696123025453 15.555702330196022, 19.238795325112868 13.826834323650898, 19.807852804032304 11.950903220161283, 20 10, 19.807852804032304 8.049096779838717, 19.238795325112868 6.173165676349102, 18.314696123025453 4.444297669803979, 17.071067811865476 2.9289321881345254, 15.55570233019602 1.6853038769745474, 13.826834323650894 0.7612046748871304, 11.950903220161276 0.1921471959676939, 10 0, -10 0, -11.950903220161287 0.1921471959676975, -13.826834323650903 0.7612046748871357, -15.555702330196022 1.6853038769745474, -17.071067811865476 2.9289321881345254, -18.314696123025456 4.44429766980398, -19.238795325112868 6.173165676349104, -19.807852804032304 8.049096779838717, -20 10.000000000000002, -19.807852804032304 11.950903220161287, -19.238795325112868 13.8268343236509, -18.314696123025453 15.555702330196022, -17.071067811865476 17.071067811865476, -15.55570233019602 18.314696123025453, -13.826834323650893 19.238795325112868, -11.950903220161276 19.807852804032308, -10 20, 10 20)), ((10 30, 13.901806440322567 29.61570560806461, 17.653668647301796 28.477590650225736, 21.111404660392047 26.629392246050905, 24.14213562373095 24.14213562373095, 26.629392246050905 21.111404660392044, 28.477590650225736 17.653668647301796, 29.61570560806461 13.901806440322565, 30 10, 29.61570560806461 6.098193559677435, 28.477590650225736 2.346331352698204, 26.629392246050905 -1.1114046603920418, 24.14213562373095 -4.142135623730949, 21.11140466039204 -6.629392246050905, 17.65366864730179 -8.47759065022574, 13.901806440322552 -9.615705608064612, 10 -10, -10 -10, -13.901806440322574 -9.615705608064605, -17.653668647301807 -8.477590650225729, -21.111404660392044 -6.629392246050905, -24.142135623730955 -4.142135623730949, -26.62939224605091 -1.11140466039204, -28.477590650225736 2.346331352698207, -29.61570560806461 6.098193559677433, -30 10.000000000000002, -29.61570560806461 13.901806440322572, -28.477590650225736 17.6536686473018, -26.629392246050905 21.111404660392044, -24.14213562373095 24.14213562373095, -21.11140466039204 26.629392246050905, -17.653668647301785 28.47759065022574, -13.90180644032255 29.615705608064612, -10 30, 10 30), (10 20, -10 20, -11.950903220161276 19.807852804032308, -13.826834323650893 19.238795325112868, -15.55570233019602 18.314696123025453, -17.071067811865476 17.071067811865476, -18.314696123025453 15.555702330196022, -19.238795325112868 13.8268343236509, -19.807852804032304 11.950903220161287, -20 10.000000000000002, -19.807852804032304 8.049096779838717, -19.238795325112868 6.173165676349104, -18.314696123025456 4.44429766980398, -17.071067811865476 2.9289321881345254, -15.555702330196022 1.6853038769745474, -13.826834323650903 0.7612046748871357, -11.950903220161287 0.1921471959676975, -10 0, 10 0, 11.950903220161276 0.1921471959676939, 13.826834323650894 0.7612046748871304, 15.55570233019602 1.6853038769745474, 17.071067811865476 2.9289321881345254, 18.314696123025453 4.444297669803979, 19.238795325112868 6.173165676349102, 19.807852804032304 8.049096779838717, 20 10, 19.807852804032304 11.950903220161283, 19.238795325112868 13.826834323650898, 18.314696123025453 15.555702330196022, 17.071067811865476 17.071067811865476, 15.555702330196024 18.314696123025453, 13.826834323650898 19.238795325112868, 11.950903220161283 19.807852804032304, 10 20)), ((10 40, 15.85270966048385 39.42355841209691, 21.480502970952696 37.7163859753386, 26.667106990588067 34.944088369076354, 31.213203435596427 31.213203435596423, 34.944088369076354 26.667106990588067, 37.7163859753386 21.480502970952692, 39.42355841209691 15.852709660483846, 40 10, 39.42355841209691 4.147290339516153, 37.7163859753386 -1.4805029709526938, 34.94408836907636 -6.6671069905880636, 31.213203435596427 -11.213203435596423, 26.667106990588064 -14.944088369076361, 21.48050297095268 -17.71638597533861, 15.85270966048383 -19.423558412096916, 10 -20, -10 -20, -15.85270966048386 -19.42355841209691, -21.48050297095271 -17.716385975338596, -26.667106990588067 -14.944088369076358, -31.21320343559643 -11.213203435596423, -34.94408836907637 -6.66710699058806, -37.71638597533861 -1.4805029709526902, -39.42355841209691 4.147290339516149, -40 10.000000000000004, -39.42355841209691 15.852709660483859, -37.7163859753386 21.4805029709527, -34.94408836907636 26.667106990588067, -31.213203435596423 31.213203435596427, -26.66710699058806 34.94408836907636, -21.480502970952678 37.71638597533861, -15.852709660483827 39.42355841209692, -10 40, 10 40), (10 30, -10 30, -13.90180644032255 29.615705608064612, -17.653668647301785 28.47759065022574, -21.11140466039204 26.629392246050905, -24.14213562373095 24.14213562373095, -26.629392246050905 21.111404660392044, -28.477590650225736 17.6536686473018, -29.61570560806461 13.901806440322572, -30 10.000000000000002, -29.61570560806461 6.098193559677433, -28.477590650225736 2.346331352698207, -26.62939224605091 -1.11140466039204, -24.142135623730955 -4.142135623730949, -21.111404660392044 -6.629392246050905, -17.653668647301807 -8.477590650225729, -13.901806440322574 -9.615705608064605, -10 -10, 10 -10, 13.901806440322552 -9.615705608064612, 17.65366864730179 -8.47759065022574, 21.11140466039204 -6.629392246050905, 24.14213562373095 -4.142135623730949, 26.629392246050905 -1.1114046603920418, 28.477590650225736 2.346331352698204, 29.61570560806461 6.098193559677435, 30 10, 29.61570560806461 13.901806440322565, 28.477590650225736 17.653668647301796, 26.629392246050905 21.111404660392044, 24.14213562373095 24.14213562373095, 21.111404660392047 26.629392246050905, " - + "17.653668647301796 28.477590650225736, 13.901806440322567 29.61570560806461, 10 30)))", rs.getObject(1)); + assertGeometryBarelyEquals("MULTIPOLYGON (((10 20, 13.826834323650898 19.238795325112868, 17.071067811865476 17.071067811865476, 19.238795325112868 13.826834323650898, 20 10, 19.238795325112868 6.173165676349102, 17.071067811865476 2.9289321881345254, 13.826834323650898 0.7612046748871322, 10 0, -10 0, -13.826834323650903 0.7612046748871357, -17.071067811865476 2.9289321881345254, -19.238795325112868 6.173165676349104, -20 10.000000000000002, -19.238795325112868 13.8268343236509, -17.071067811865476 17.071067811865476, -13.826834323650896 19.238795325112868, -10 20, 10 20))," + + " ((10 30, 17.653668647301796 28.477590650225736, 24.14213562373095 24.14213562373095, 28.477590650225736 17.653668647301796, 30 10, 28.477590650225736 2.346331352698204, 24.14213562373095 -4.142135623730949, 17.653668647301796 -8.477590650225736, 10 -10, -10 -10, -17.653668647301807 -8.477590650225729, -24.142135623730955 -4.142135623730949, -28.477590650225736 2.346331352698207, -30 10.000000000000002, -28.477590650225736 17.6536686473018, -24.14213562373095 24.14213562373095, -17.653668647301792 28.477590650225736, -10 30, 10 30)," + + " (10 20, -10 20, -13.826834323650896 19.238795325112868, -17.071067811865476 17.071067811865476, -19.238795325112868 13.8268343236509, -20 10.000000000000002, -19.238795325112868 6.173165676349104, -17.071067811865476 2.9289321881345254, -13.826834323650903 0.7612046748871357, -10 0, 10 0, 13.826834323650898 0.7612046748871322, 17.071067811865476 2.9289321881345254, 19.238795325112868 6.173165676349102, 20 10, 19.238795325112868 13.826834323650898, 17.071067811865476 17.071067811865476, 13.826834323650898 19.238795325112868, 10 20))," + + " ((10 40, 21.480502970952696 37.7163859753386, 31.213203435596427 31.213203435596423, 37.7163859753386 21.480502970952692, 40 10, 37.7163859753386 -1.4805029709526938, 31.213203435596427 -11.213203435596423, 21.480502970952696 -17.716385975338603, 10 -20, -10 -20, -21.48050297095271 -17.716385975338596, -31.21320343559643 -11.213203435596423, -37.71638597533861 -1.4805029709526902, -40 10.000000000000004, -37.7163859753386 21.4805029709527, -31.213203435596423 31.213203435596427, -21.480502970952692 37.7163859753386, -10 40, 10 40)," + + " (10 30, -10 30, -17.653668647301792 28.477590650225736, -24.14213562373095 24.14213562373095, -28.477590650225736 17.6536686473018, -30 10.000000000000002, -28.477590650225736 2.346331352698207, -24.142135623730955 -4.142135623730949, -17.653668647301807 -8.477590650225729, -10 -10, 10 -10, 17.653668647301796 -8.477590650225736, 24.14213562373095 -4.142135623730949, 28.477590650225736 2.346331352698204, 30 10, 28.477590650225736 17.653668647301796, 24.14213562373095 24.14213562373095, 17.653668647301796 28.477590650225736, 10 30)))", rs.getObject(1)); + rs.close(); + } + + @Test + public void test_ST_RingBufferComplex2() throws Exception { + ResultSet rs = st.executeQuery("SELECT ST_RingBuffer('LINESTRING (-10 10, 10 10)'::GEOMETRY, 10, 3,'endcap=ROUND');"); + assertTrue(rs.next()); + assertGeometryBarelyEquals("MULTIPOLYGON (((10 20, 11.950903220161283 19.807852804032304, 13.826834323650898 19.238795325112868, 15.555702330196024 18.314696123025453, 17.071067811865476 17.071067811865476, 18.314696123025453 15.555702330196022, 19.238795325112868 13.826834323650898, 19.807852804032304 11.950903220161283, 20 10, 19.807852804032304 8.049096779838717, 19.238795325112868 6.173165676349102, 18.314696123025453 4.444297669803979, 17.071067811865476 2.9289321881345254, 15.55570233019602 1.6853038769745474, 13.826834323650894 0.7612046748871304, 11.950903220161276 0.1921471959676939, 10 0, -10 0, -11.950903220161287 0.1921471959676975, -13.826834323650903 0.7612046748871357, -15.555702330196022 1.6853038769745474, -17.071067811865476 2.9289321881345254, -18.314696123025456 4.44429766980398, -19.238795325112868 6.173165676349104, -19.807852804032304 8.049096779838717, -20 10.000000000000002, -19.807852804032304 11.950903220161287, -19.238795325112868 13.8268343236509, -18.314696123025453 15.555702330196022, -17.071067811865476 17.071067811865476, -15.55570233019602 18.314696123025453, -13.826834323650893 19.238795325112868, -11.950903220161276 19.807852804032308, -10 20, 10 20))," + + " ((10 30, 13.901806440322567 29.61570560806461, 17.653668647301796 28.477590650225736, 21.111404660392047 26.629392246050905, 24.14213562373095 24.14213562373095, 26.629392246050905 21.111404660392044, 28.477590650225736 17.653668647301796, 29.61570560806461 13.901806440322565, 30 10, 29.61570560806461 6.098193559677435, 28.477590650225736 2.346331352698204, 26.629392246050905 -1.1114046603920418, 24.14213562373095 -4.142135623730949, 21.11140466039204 -6.629392246050905, 17.65366864730179 -8.47759065022574, 13.901806440322552 -9.615705608064612, 10 -10, -10 -10, -13.901806440322574 -9.615705608064605, -17.653668647301807 -8.477590650225729, -21.111404660392044 -6.629392246050905, -24.142135623730955 -4.142135623730949, -26.62939224605091 -1.11140466039204, -28.477590650225736 2.346331352698207, -29.61570560806461 6.098193559677433, -30 10.000000000000002, -29.61570560806461 13.901806440322572, -28.477590650225736 17.6536686473018, -26.629392246050905 21.111404660392044, -24.14213562373095 24.14213562373095, -21.11140466039204 26.629392246050905, -17.653668647301785 28.47759065022574, -13.90180644032255 29.615705608064612, -10 30, 10 30)," + + " (10 20, -10 20, -11.950903220161276 19.807852804032308, -13.826834323650893 19.238795325112868, -15.55570233019602 18.314696123025453, -17.071067811865476 17.071067811865476, -18.314696123025453 15.555702330196022, -19.238795325112868 13.8268343236509, -19.807852804032304 11.950903220161287, -20 10.000000000000002, -19.807852804032304 8.049096779838717, -19.238795325112868 6.173165676349104, -18.314696123025456 4.44429766980398, -17.071067811865476 2.9289321881345254, -15.555702330196022 1.6853038769745474, -13.826834323650903 0.7612046748871357, -11.950903220161287 0.1921471959676975, -10 0, 10 0, 11.950903220161276 0.1921471959676939, 13.826834323650894 0.7612046748871304, 15.55570233019602 1.6853038769745474, 17.071067811865476 2.9289321881345254, 18.314696123025453 4.444297669803979, 19.238795325112868 6.173165676349102, 19.807852804032304 8.049096779838717, 20 10, 19.807852804032304 11.950903220161283, 19.238795325112868 13.826834323650898, 18.314696123025453 15.555702330196022, 17.071067811865476 17.071067811865476, 15.555702330196024 18.314696123025453, 13.826834323650898 19.238795325112868, 11.950903220161283 19.807852804032304, 10 20))," + + " ((10 40, 15.85270966048385 39.42355841209691, 21.480502970952696 37.7163859753386, 26.667106990588067 34.944088369076354, 31.213203435596427 31.213203435596423, 34.944088369076354 26.667106990588067, 37.7163859753386 21.480502970952692, 39.42355841209691 15.852709660483846, 40 10, 39.42355841209691 4.147290339516153, 37.7163859753386 -1.4805029709526938, 34.94408836907636 -6.6671069905880636, 31.213203435596427 -11.213203435596423, 26.667106990588064 -14.944088369076361, 21.48050297095268 -17.71638597533861, 15.85270966048383 -19.423558412096916, 10 -20, -10 -20, -15.85270966048386 -19.42355841209691, -21.48050297095271 -17.716385975338596, -26.667106990588067 -14.944088369076358, -31.21320343559643 -11.213203435596423, -34.94408836907637 -6.66710699058806, -37.71638597533861 -1.4805029709526902, -39.42355841209691 4.147290339516149, -40 10.000000000000004, -39.42355841209691 15.852709660483859, -37.7163859753386 21.4805029709527, -34.94408836907636 26.667106990588067, -31.213203435596423 31.213203435596427, -26.66710699058806 34.94408836907636, -21.480502970952678 37.71638597533861, -15.852709660483827 39.42355841209692, -10 40, 10 40)," + + " (10 30, -10 30, -13.90180644032255 29.615705608064612, -17.653668647301785 28.47759065022574, -21.11140466039204 26.629392246050905, -24.14213562373095 24.14213562373095, -26.629392246050905 21.111404660392044, -28.477590650225736 17.6536686473018, -29.61570560806461 13.901806440322572, -30 10.000000000000002, -29.61570560806461 6.098193559677433, -28.477590650225736 2.346331352698207, -26.62939224605091 -1.11140466039204, -24.142135623730955 -4.142135623730949, -21.111404660392044 -6.629392246050905, -17.653668647301807 -8.477590650225729, -13.901806440322574 -9.615705608064605, -10 -10, 10 -10, 13.901806440322552 -9.615705608064612, 17.65366864730179 -8.47759065022574, 21.11140466039204 -6.629392246050905, 24.14213562373095 -4.142135623730949, 26.629392246050905 -1.1114046603920418, 28.477590650225736 2.346331352698204, 29.61570560806461 6.098193559677435, 30 10, 29.61570560806461 13.901806440322565, 28.477590650225736 17.653668647301796, 26.629392246050905 21.111404660392044, 24.14213562373095 24.14213562373095, 21.111404660392047 26.629392246050905, 17.653668647301796 28.477590650225736, 13.901806440322567 29.61570560806461, 10 30)))", rs.getObject(1)); rs.close(); } From 2d8b267ae29d61b23e6443849f4fc335dc9fd50d Mon Sep 17 00:00:00 2001 From: Erwan Bocher Date: Mon, 5 Jan 2015 13:47:26 +0100 Subject: [PATCH 5/8] Rename ST_SingleSideBuffer by ST_SideBuffer --- .../h2spatialext/CreateSpatialExtension.java | 2 +- ...ngleSideBuffer.java => ST_SideBuffer.java} | 4 +-- .../h2spatialext/SpatialFunctionTest.java | 25 ++++++++----------- 3 files changed, 14 insertions(+), 17 deletions(-) rename h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/processing/{ST_SingleSideBuffer.java => ST_SideBuffer.java} (97%) diff --git a/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/CreateSpatialExtension.java b/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/CreateSpatialExtension.java index 105fdfbbcb..282b357e65 100644 --- a/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/CreateSpatialExtension.java +++ b/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/CreateSpatialExtension.java @@ -181,7 +181,7 @@ public static Function[] getBuiltInsFunctions() throws SQLException { new ST_CollectExtract(), new DoubleRange(), new IntegerRange(), - new ST_SingleSideBuffer()}; + new ST_SideBuffer()}; } /** diff --git a/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/processing/ST_SingleSideBuffer.java b/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/processing/ST_SideBuffer.java similarity index 97% rename from h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/processing/ST_SingleSideBuffer.java rename to h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/processing/ST_SideBuffer.java index 08176211d6..91bd046e4a 100644 --- a/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/processing/ST_SingleSideBuffer.java +++ b/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/processing/ST_SideBuffer.java @@ -36,9 +36,9 @@ * * @author Erwan Bocher */ -public class ST_SingleSideBuffer extends DeterministicScalarFunction{ +public class ST_SideBuffer extends DeterministicScalarFunction{ - public ST_SingleSideBuffer() { + public ST_SideBuffer() { addProperty(PROP_REMARKS, "Return a buffer at a given distance on only one side of each input lines of the geometry.\n" + "The optional third parameter can either specify number of segments used\n" + " to approximate a quarter circle (integer case, defaults to 8)\n" diff --git a/h2spatial-ext/src/test/java/org/h2gis/h2spatialext/SpatialFunctionTest.java b/h2spatial-ext/src/test/java/org/h2gis/h2spatialext/SpatialFunctionTest.java index 21d5510d30..9eaf999659 100644 --- a/h2spatial-ext/src/test/java/org/h2gis/h2spatialext/SpatialFunctionTest.java +++ b/h2spatial-ext/src/test/java/org/h2gis/h2spatialext/SpatialFunctionTest.java @@ -3287,8 +3287,8 @@ public void test_ST_CollectExtract6() throws Exception { } @Test - public void test_ST_SingleSideBuffer1() throws Exception { - ResultSet rs = st.executeQuery("SELECT ST_SingleSideBuffer('LINESTRING (120 150, 180 270)', 10);"); + public void test_ST_SideBuffer1() throws Exception { + ResultSet rs = st.executeQuery("SELECT ST_SideBuffer('LINESTRING (120 150, 180 270)', 10);"); rs.next(); assertEquals("POLYGON ((180 270, 120 150, 111.05572809000084 154.47213595499957, 171.05572809000085 274.4721359549996, 180 270))", rs.getString(1)); @@ -3296,8 +3296,8 @@ public void test_ST_SingleSideBuffer1() throws Exception { } @Test - public void test_ST_SingleSideBuffer2() throws Exception { - ResultSet rs = st.executeQuery("SELECT ST_SingleSideBuffer('LINESTRING (120 150, 180 270)', -10);"); + public void test_ST_SideBuffer2() throws Exception { + ResultSet rs = st.executeQuery("SELECT ST_SideBuffer('LINESTRING (120 150, 180 270)', -10);"); rs.next(); assertEquals("POLYGON ((120 150, 180 270, 188.94427190999915 265.5278640450004, 128.94427190999915 145.52786404500043, 120 150))", rs.getString(1)); @@ -3305,17 +3305,17 @@ public void test_ST_SingleSideBuffer2() throws Exception { } @Test(expected = IllegalArgumentException.class) - public void test_ST_SingleSideBuffer3() throws Throwable { + public void test_ST_SideBuffer3() throws Throwable { try { - st.execute("SELECT ST_SingleSideBuffer('LINESTRING (120 150, 180 270)', 10, 'endcap=square');"); + st.execute("SELECT ST_SideBuffer('LINESTRING (120 150, 180 270)', 10, 'endcap=square');"); } catch (JdbcSQLException e) { throw e.getOriginalCause(); } } @Test - public void test_ST_SingleSideBuffer4() throws Exception { - ResultSet rs = st.executeQuery("SELECT ST_SingleSideBuffer('LINESTRING (100 200, 150 250, 200 200)', 10, 'join=round quad_segs=2');"); + public void test_ST_SideBuffer4() throws Exception { + ResultSet rs = st.executeQuery("SELECT ST_SideBuffer('LINESTRING (100 200, 150 250, 200 200)', 10, 'join=round quad_segs=2');"); rs.next(); assertEquals("POLYGON ((200 200, 150 250, 100 200, 92.92893218813452 207.07106781186548, 142.92893218813452 257.0710678118655, 150 260, 157.07106781186548 257.0710678118655, 207.07106781186548 207.07106781186548, 200 200))", rs.getString(1)); @@ -3323,14 +3323,11 @@ public void test_ST_SingleSideBuffer4() throws Exception { } @Test - public void test_ST_SingleSideBuffer5() throws Exception { - ResultSet rs = st.executeQuery("SELECT ST_SingleSideBuffer('POINT (100 200)', 10, 'join=round quad_segs=2');"); + public void test_ST_SideBuffer5() throws Exception { + ResultSet rs = st.executeQuery("SELECT ST_SideBuffer('POINT (100 200)', 10, 'join=round quad_segs=2');"); rs.next(); assertEquals("POLYGON ((110 200, 107.07106781186548 192.92893218813452, 100 190, 92.92893218813452 192.92893218813452, 90 200, 92.92893218813452 207.07106781186548, 100 210, 107.07106781186548 207.07106781186548, 110 200))", rs.getString(1)); rs.close(); - } - - - + } } From f8f23756a5d73023db49e24b606fb8f1d9b2475f Mon Sep 17 00:00:00 2001 From: Erwan Bocher Date: Wed, 7 Jan 2015 08:47:20 +0100 Subject: [PATCH 6/8] St_RingBuffer works with negative offset --- .../h2spatialext/CreateSpatialExtension.java | 3 +- .../spatial/create/ST_RingBuffer.java | 138 ++++++++++++---- .../spatial/processing/ST_RingSideBuffer.java | 154 ++++++++++++++++++ .../h2spatialext/SpatialFunctionTest.java | 65 +++++++- 4 files changed, 323 insertions(+), 37 deletions(-) create mode 100644 h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/processing/ST_RingSideBuffer.java diff --git a/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/CreateSpatialExtension.java b/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/CreateSpatialExtension.java index 282b357e65..ca18e49b81 100644 --- a/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/CreateSpatialExtension.java +++ b/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/CreateSpatialExtension.java @@ -181,7 +181,8 @@ public static Function[] getBuiltInsFunctions() throws SQLException { new ST_CollectExtract(), new DoubleRange(), new IntegerRange(), - new ST_SideBuffer()}; + new ST_SideBuffer(), + new ST_RingSideBuffer()}; } /** diff --git a/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/create/ST_RingBuffer.java b/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/create/ST_RingBuffer.java index 98819a0252..7df5260835 100644 --- a/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/create/ST_RingBuffer.java +++ b/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/create/ST_RingBuffer.java @@ -25,6 +25,7 @@ import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.GeometryFactory; +import com.vividsolutions.jts.geom.Point; import com.vividsolutions.jts.geom.Polygon; import com.vividsolutions.jts.operation.buffer.BufferOp; import com.vividsolutions.jts.operation.buffer.BufferParameters; @@ -94,57 +95,125 @@ public static Geometry ringBuffer(Geometry geom, double bufferDistance, */ public static Geometry ringBuffer(Geometry geom, double bufferDistance, int numBuffer, String parameters, boolean doDifference) throws SQLException { - if(!(bufferDistance > 0)) { - // If buffer distance is not superior than zero return the same geometry. - return geom; - } - String[] buffParemeters = parameters.split("\\s+"); - BufferParameters bufferParameters = new BufferParameters(); - for (String params : buffParemeters) { - String[] keyValue = params.split("="); - if (keyValue[0].equalsIgnoreCase("endcap")) { - String param = keyValue[1]; - if (param.equalsIgnoreCase("round")) { - bufferParameters.setEndCapStyle(BufferParameters.CAP_ROUND); - } else if (param.equalsIgnoreCase("square")) { - bufferParameters.setEndCapStyle(BufferParameters.CAP_SQUARE); + if(geom==null){ + return null; + } + if (geom.getNumGeometries() > 1) { + throw new SQLException("This function supports only single geometry : point, linestring or polygon."); + } else { + String[] buffParemeters = parameters.split("\\s+"); + BufferParameters bufferParameters = new BufferParameters(); + for (String params : buffParemeters) { + String[] keyValue = params.split("="); + if (keyValue[0].equalsIgnoreCase("endcap")) { + String param = keyValue[1]; + if (param.equalsIgnoreCase("round")) { + bufferParameters.setEndCapStyle(BufferParameters.CAP_ROUND); + } else if (param.equalsIgnoreCase("square")) { + bufferParameters.setEndCapStyle(BufferParameters.CAP_SQUARE); + } else { + throw new IllegalArgumentException("Supported join values are round or square."); + } + } else if (keyValue[0].equalsIgnoreCase("join")) { + String param = keyValue[1]; + if (param.equalsIgnoreCase("bevel")) { + bufferParameters.setJoinStyle(BufferParameters.JOIN_BEVEL); + } else if (param.equalsIgnoreCase("mitre") || param.equalsIgnoreCase("miter")) { + bufferParameters.setJoinStyle(BufferParameters.JOIN_MITRE); + } else if (param.equalsIgnoreCase("round")) { + bufferParameters.setJoinStyle(BufferParameters.JOIN_ROUND); + } else { + throw new IllegalArgumentException("Supported join values are bevel, mitre, miter or round."); + } + } else if (keyValue[0].equalsIgnoreCase("mitre_limit") || keyValue[0].equalsIgnoreCase("miter_limit")) { + bufferParameters.setMitreLimit(Double.valueOf(keyValue[1])); + } else if (keyValue[0].equalsIgnoreCase("quad_segs")) { + bufferParameters.setQuadrantSegments(Integer.valueOf(keyValue[1])); } else { - throw new IllegalArgumentException("Supported join values are round or square."); + throw new IllegalArgumentException("Unknown parameters. Please read the documentation."); } - } else if(keyValue[0].equalsIgnoreCase("join")) { - String param = keyValue[1]; - if (param.equalsIgnoreCase("bevel")) { - bufferParameters.setJoinStyle(BufferParameters.JOIN_BEVEL); - } else if (param.equalsIgnoreCase("mitre") || param.equalsIgnoreCase("miter")) { - bufferParameters.setJoinStyle(BufferParameters.JOIN_MITRE); - } else if (param.equalsIgnoreCase("round")) { - bufferParameters.setJoinStyle(BufferParameters.JOIN_ROUND); + } + if (bufferDistance > 0) { + return computePositiveRingBuffer(geom, bufferDistance, numBuffer, bufferParameters, doDifference); + } else if (bufferDistance < 0) { + if (geom instanceof Point) { + throw new SQLException("Cannot compute a negative ring side buffer on a point."); } else { - throw new IllegalArgumentException("Supported join values are bevel, mitre, miter or round."); + return computeNegativeRingBuffer(geom, bufferDistance, numBuffer, bufferParameters, doDifference); } - } else if (keyValue[0].equalsIgnoreCase("mitre_limit") || keyValue[0].equalsIgnoreCase("miter_limit")) { - bufferParameters.setMitreLimit(Double.valueOf(keyValue[1])); - } else if (keyValue[0].equalsIgnoreCase("quad_segs")) { - bufferParameters.setQuadrantSegments(Integer.valueOf(keyValue[1])); } else { - throw new IllegalArgumentException("Unknown parameters. Please read the documentation."); + return geom; } } - - Polygon[] buffers = new Polygon[numBuffer]; + } + + /** + * Compute a ring buffer with a positive offset + * + * @param geom + * @param bufferDistance + * @param numBuffer + * @param bufferParameters + * @param doDifference + * @return + * @throws SQLException + */ + public static Geometry computePositiveRingBuffer(Geometry geom, double bufferDistance, + int numBuffer, BufferParameters bufferParameters, boolean doDifference) throws SQLException { + Polygon[] buffers = new Polygon[numBuffer]; + if (geom instanceof Polygon) { + //Work arround to manage polygon with hole + geom = geom.getFactory().createPolygon(((Polygon) geom).getExteriorRing().getCoordinateSequence()); + } Geometry previous = geom; double distance = 0; for (int i = 0; i < numBuffer; i++) { distance += bufferDistance; Geometry newBuffer = runBuffer(geom, distance, bufferParameters); - if(doDifference) { + if (doDifference) { buffers[i] = (Polygon) newBuffer.difference(previous); } else { buffers[i] = (Polygon) newBuffer; } previous = newBuffer; } - return GF.createMultiPolygon(buffers); + return geom.getFactory().createMultiPolygon(buffers); + } + + /** + * Compute a ring buffer with a negative offset + * + * @param geom + * @param bufferDistance + * @param numBuffer + * @param bufferParameters + * @param doDifference + * @return + * @throws SQLException + */ + public static Geometry computeNegativeRingBuffer(Geometry geom, double bufferDistance, + int numBuffer, BufferParameters bufferParameters, boolean doDifference) throws SQLException { + Polygon[] buffers = new Polygon[numBuffer]; + Geometry previous = geom; + double distance = 0; + if (geom instanceof Polygon) { + geom = ((Polygon) geom).getExteriorRing(); + } + for (int i = 0; i < numBuffer; i++) { + distance += bufferDistance; + Geometry newBuffer = runBuffer(geom, distance, bufferParameters); + if (i == 0) { + buffers[i] = (Polygon) newBuffer; + } else { + if (doDifference) { + buffers[i] = (Polygon) newBuffer.difference(previous); + } else { + buffers[i] = (Polygon) newBuffer; + } + } + previous = newBuffer; + } + return geom.getFactory().createMultiPolygon(buffers); } /** @@ -152,10 +221,11 @@ public static Geometry ringBuffer(Geometry geom, double bufferDistance, * * @param geom * @param bufferSize + * @param bufferParameters * @return * @throws SQLException */ - private static Geometry runBuffer(final Geometry geom, final double bufferSize, + public static Geometry runBuffer(final Geometry geom, final double bufferSize, final BufferParameters bufferParameters) throws SQLException { return BufferOp.bufferOp(geom, bufferSize, bufferParameters); } diff --git a/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/processing/ST_RingSideBuffer.java b/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/processing/ST_RingSideBuffer.java new file mode 100644 index 0000000000..18bfec5e14 --- /dev/null +++ b/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/processing/ST_RingSideBuffer.java @@ -0,0 +1,154 @@ +/** + * h2spatial is a library that brings spatial support to the H2 Java database. + * + * h2spatial is distributed under GPL 3 license. It is produced by the "Atelier + * SIG" team of the IRSTV Institute CNRS FR 2488. + * + * Copyright (C) 2007-2014 IRSTV (FR CNRS 2488) + * + * h2patial is free software: you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later + * version. + * + * h2spatial is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * h2spatial. If not, see . + * + * For more information, please consult: + * or contact directly: info_at_ orbisgis.org + */ + +package org.h2gis.h2spatialext.function.spatial.processing; + +import com.vividsolutions.jts.geom.Geometry; +import com.vividsolutions.jts.geom.Point; +import com.vividsolutions.jts.geom.Polygon; +import com.vividsolutions.jts.operation.buffer.BufferOp; +import com.vividsolutions.jts.operation.buffer.BufferParameters; +import java.sql.SQLException; +import org.h2gis.h2spatialapi.DeterministicScalarFunction; +import org.h2gis.h2spatialext.function.spatial.create.ST_RingBuffer; + +/** + *Compute a ring buffer on one side + * + * @author Erwan Bocher + */ +public class ST_RingSideBuffer extends DeterministicScalarFunction{ + + + public ST_RingSideBuffer(){ + addProperty(PROP_REMARKS, "Return a ring buffer at a given distance on only one side of each input lines of the geometry.\n" + + "Avalaible arguments are :\n" + + " (1) the geometry, (2) the size of each ring, " + + " (3) the number of rings, (4) optional - \n" + + "a list of blank-separated key=value pairs (string case) iso used t manage line style parameters.\n " + + " The end cap style for single-sided buffers is always ignored, and forced to the equivalent of flat.\n" + + "Please read the ST_Buffer documention.\n" + + " (5) optional - createHole True if you want to keep only difference between buffers Default is true"); + + } + + @Override + public String getJavaStaticMethod() { + return "ringSideBuffer"; + } + + /** + * Compute a ring buffer on one side of the geometry + * @param geom + * @param bufferSize + * @param numBuffer + * @return + * @throws java.sql.SQLException + */ + public static Geometry ringSideBuffer(Geometry geom, double bufferSize, int numBuffer) throws SQLException { + return ringSideBuffer(geom, bufferSize, numBuffer, "endcap=flat"); + } + + /** + * + * @param geom + * @param bufferDistance + * @param numBuffer + * @param parameters + * @return + * @throws java.sql.SQLException + */ + public static Geometry ringSideBuffer(Geometry geom, double bufferDistance, + int numBuffer, String parameters) throws SQLException { + return ringSideBuffer(geom, bufferDistance, numBuffer, parameters, true); + } + + /** + * Compute a ring buffer on one side of the geometry + * @param geom + * @param bufferDistance + * @param numBuffer + * @param parameters + * @param doDifference + * @throws SQLException + * @return + */ + public static Geometry ringSideBuffer(Geometry geom, double bufferDistance, + int numBuffer, String parameters, boolean doDifference) throws SQLException { + if(geom==null){ + return null; + } + if (geom.getNumGeometries() > 1) { + throw new SQLException("This function supports only single geometry : point, linestring or polygon."); + } else { + String[] buffParemeters = parameters.split("\\s+"); + BufferParameters bufferParameters = new BufferParameters(); + bufferParameters.setSingleSided(true); + for (String params : buffParemeters) { + String[] keyValue = params.split("="); + if (keyValue[0].equalsIgnoreCase("endcap")) { + String param = keyValue[1]; + if (param.equalsIgnoreCase("round")) { + bufferParameters.setEndCapStyle(BufferParameters.CAP_FLAT); + } else if (param.equalsIgnoreCase("square")) { + bufferParameters.setEndCapStyle(BufferParameters.CAP_FLAT); + } else if (param.equalsIgnoreCase("flat")) { + bufferParameters.setEndCapStyle(BufferParameters.CAP_FLAT); + } else { + throw new IllegalArgumentException("Supported join values are round or square."); + } + } else if (keyValue[0].equalsIgnoreCase("join")) { + String param = keyValue[1]; + if (param.equalsIgnoreCase("bevel")) { + bufferParameters.setJoinStyle(BufferParameters.JOIN_BEVEL); + } else if (param.equalsIgnoreCase("mitre") || param.equalsIgnoreCase("miter")) { + bufferParameters.setJoinStyle(BufferParameters.JOIN_MITRE); + } else if (param.equalsIgnoreCase("round")) { + bufferParameters.setJoinStyle(BufferParameters.JOIN_ROUND); + } else { + throw new IllegalArgumentException("Supported join values are bevel, mitre, miter or round."); + } + } else if (keyValue[0].equalsIgnoreCase("mitre_limit") || keyValue[0].equalsIgnoreCase("miter_limit")) { + bufferParameters.setMitreLimit(Double.valueOf(keyValue[1])); + } else if (keyValue[0].equalsIgnoreCase("quad_segs")) { + bufferParameters.setQuadrantSegments(Integer.valueOf(keyValue[1])); + } else { + throw new IllegalArgumentException("Unknown parameters. Please read the documentation."); + } + } + + if (bufferDistance > 0) { + return ST_RingBuffer.computePositiveRingBuffer(geom, bufferDistance, numBuffer, bufferParameters, doDifference); + } else if (bufferDistance < 0) { + if (geom instanceof Point) { + throw new SQLException("Cannot compute a negative ring side buffer on a point."); + } else { + return ST_RingBuffer.computeNegativeRingBuffer(geom, bufferDistance, numBuffer, bufferParameters, doDifference); + } + } else { + return geom; + } + } + } +} diff --git a/h2spatial-ext/src/test/java/org/h2gis/h2spatialext/SpatialFunctionTest.java b/h2spatial-ext/src/test/java/org/h2gis/h2spatialext/SpatialFunctionTest.java index 9eaf999659..4043fd114e 100644 --- a/h2spatial-ext/src/test/java/org/h2gis/h2spatialext/SpatialFunctionTest.java +++ b/h2spatial-ext/src/test/java/org/h2gis/h2spatialext/SpatialFunctionTest.java @@ -3322,12 +3322,73 @@ public void test_ST_SideBuffer4() throws Exception { rs.close(); } - @Test + @Test public void test_ST_SideBuffer5() throws Exception { ResultSet rs = st.executeQuery("SELECT ST_SideBuffer('POINT (100 200)', 10, 'join=round quad_segs=2');"); rs.next(); assertEquals("POLYGON ((110 200, 107.07106781186548 192.92893218813452, 100 190, 92.92893218813452 192.92893218813452, 90 200, 92.92893218813452 207.07106781186548, 100 210, 107.07106781186548 207.07106781186548, 110 200))", rs.getString(1)); rs.close(); - } + } + + @Test + public void test_ST_RingSideBuffer1() throws Exception { + ResultSet rs = st.executeQuery("SELECT ST_RingSideBuffer('LINESTRING (-10 10, 10 10)'::GEOMETRY, 10, 3);"); + assertTrue(rs.next()); + assertGeometryBarelyEquals("MULTIPOLYGON (((10 10, -10 10, -10 20, 10 20, 10 10))," + + " ((-10 20, -10 30, 10 30, 10 20, -10 20))," + + " ((-10 30, -10 40, 10 40, 10 30, -10 30)))", rs.getObject(1)); + rs.close(); + } + + @Test + public void test_ST_RingSideBuffer2() throws Exception { + ResultSet rs = st.executeQuery("SELECT ST_RingSideBuffer('LINESTRING (-10 10, 10 10)'::GEOMETRY, -10, 3);"); + assertTrue(rs.next()); + assertGeometryBarelyEquals("MULTIPOLYGON (((-10 10, 10 10, 10 0, -10 0, -10 10)), ((10 0, 10 -10, -10 -10, -10 0, 10 0)), ((10 -10, 10 -20, -10 -20, -10 -10, 10 -10)))", rs.getObject(1)); + rs.close(); + } + + @Test + public void test_ST_RingSideBuffer3() throws Exception { + ResultSet rs = st.executeQuery("SELECT ST_RingSideBuffer('POLYGON ((10 20, 20 20, 20 10, 10 10, 10 20))'::GEOMETRY, -1, 3);"); + assertTrue(rs.next()); + assertGeometryBarelyEquals("MULTIPOLYGON (((10 19, 10 20, 11 20, 20 20, 20 10, 10 10, 10 19)," + + " (11 19, 11 11, 19 11, 19 19, 11 19))," + + " ((11 19, 19 19, 19 11, 11 11, 11 19)," + + " (12 18, 12 12, 18 12, 18 18, 12 18))," + + " ((12 18, 18 18, 18 12, 12 12, 12 18)," + + " (13 17, 13 13, 17 13, 17 17, 13 17)))", rs.getObject(1)); + rs.close(); + } + + @Test(expected = SQLException.class) + public void test_ST_RingSideBuffer4() throws Throwable { + try { + st.execute("SELECT ST_RingSideBuffer('MULTIPOLYGON (((10 20, 20 20, 20 10, 10 10, 10 20))," + + " ((0 29, 10 29, 10 20, 0 20, 0 29)))'::GEOMETRY, -1, 3);"); + } catch (JdbcSQLException e) { + throw e.getOriginalCause(); + } + } + + @Test(expected = SQLException.class) + public void test_ST_RingSideBuffer5() throws Throwable { + try { + st.execute("SELECT ST_RingSideBuffer('POINT(10 20)'::GEOMETRY, -1, 3);"); + } catch (JdbcSQLException e) { + throw e.getOriginalCause(); + } + } + + @Test + public void test_ST_RingSideBuffer6() throws Exception { + ResultSet rs = st.executeQuery("SELECT ST_RingSideBuffer('POLYGON ((10 20, 20 20, 20 10, 10 10, 10 20)," + + " (12.1 18.1, 14.1 18.1, 14.1 16, 12.1 16, 12.1 18.1)," + + " (15.6 14, 18 14, 18 11.5, 15.6 11.5, 15.6 14))'::GEOMETRY, 1, 3);"); + assertTrue(rs.next()); + assertGeometryBarelyEquals("MULTIPOLYGON (((9 20, 9.01921471959677 20.195090322016128, 9.076120467488714 20.38268343236509, 9.168530387697455 20.5555702330196, 9.292893218813452 20.707106781186546, 9.444429766980399 20.831469612302545, 9.61731656763491 20.923879532511286, 9.804909677983872 20.980785280403232, 10 21, 20 21, 20.195090322016128 20.980785280403232, 20.38268343236509 20.923879532511286, 20.5555702330196 20.831469612302545, 20.707106781186546 20.707106781186546, 20.831469612302545 20.5555702330196, 20.923879532511286 20.38268343236509, 20.980785280403232 20.195090322016128, 21 20, 21 10, 20.980785280403232 9.804909677983872, 20.923879532511286 9.61731656763491, 20.831469612302545 9.444429766980399, 20.707106781186546 9.292893218813452, 20.5555702330196 9.168530387697455, 20.38268343236509 9.076120467488714, 20.195090322016128 9.01921471959677, 20 9, 10 9, 9.804909677983872 9.01921471959677, 9.61731656763491 9.076120467488714, 9.444429766980399 9.168530387697455, 9.292893218813452 9.292893218813452, 9.168530387697455 9.444429766980399, 9.076120467488714 9.61731656763491, 9.01921471959677 9.804909677983872, 9 10, 9 20), (10 20, 10 10, 20 10, 20 20, 10 20)), ((8 20, 8.03842943919354 20.390180644032256, 8.152240934977426 20.76536686473018, 8.33706077539491 21.111140466039203, 8.585786437626904 21.414213562373096, 8.888859533960796 21.66293922460509, 9.23463313526982 21.847759065022572, 9.609819355967744 21.96157056080646, 10 22, 20 22, 20.390180644032256 21.96157056080646, 20.76536686473018 21.847759065022572, 21.111140466039206 21.66293922460509, 21.414213562373096 21.414213562373096, 21.66293922460509 21.111140466039203, 21.847759065022572 20.76536686473018, 21.96157056080646 20.390180644032256, 22 20, 22 10, 21.96157056080646 9.609819355967744, 21.847759065022572 9.23463313526982, 21.66293922460509 8.888859533960796, 21.414213562373096 8.585786437626904, 21.111140466039206 8.33706077539491, 20.76536686473018 8.152240934977426, 20.390180644032256 8.03842943919354, 20 8, 10 8, 9.609819355967742 8.03842943919354, 9.234633135269819 8.152240934977428, 8.888859533960796 8.33706077539491, 8.585786437626904 8.585786437626904, 8.337060775394908 8.888859533960796, 8.152240934977426 9.23463313526982, 8.03842943919354 9.609819355967744, 8 10, 8 20), (9 20, 9 10, 9.01921471959677 9.804909677983872, 9.076120467488714 9.61731656763491, 9.168530387697455 9.444429766980399, 9.292893218813452 9.292893218813452, 9.444429766980399 9.168530387697455, 9.61731656763491 9.076120467488714, 9.804909677983872 9.01921471959677, 10 9, 20 9, 20.195090322016128 9.01921471959677, 20.38268343236509 9.076120467488714, 20.5555702330196 9.168530387697455, 20.707106781186546 9.292893218813452, 20.831469612302545 9.444429766980399, 20.923879532511286 9.61731656763491, 20.980785280403232 9.804909677983872, 21 10, 21 20, 20.980785280403232 20.195090322016128, 20.923879532511286 20.38268343236509, 20.831469612302545 20.5555702330196, 20.707106781186546 20.707106781186546, 20.5555702330196 20.831469612302545, 20.38268343236509 20.923879532511286, 20.195090322016128 20.980785280403232, 20 21, 10 21, 9.804909677983872 20.980785280403232, 9.61731656763491 20.923879532511286, 9.444429766980399 20.831469612302545, 9.292893218813452 20.707106781186546, 9.168530387697455 20.5555702330196, 9.076120467488714 20.38268343236509, 9.01921471959677 20.195090322016128, 9 20)), ((7 20, 7.057644158790309 20.585270966048387, 7.22836140246614 21.14805029709527, 7.5055911630923635 21.666710699058807, 7.878679656440358 22.121320343559642, 8.333289300941194 22.494408836907635, 8.851949702904731 22.771638597533858, 9.414729033951616 22.94235584120969, 10 23, 20 23, 20.585270966048384 22.94235584120969, 21.14805029709527 22.771638597533858, 21.666710699058807 22.494408836907635, 22.121320343559642 22.121320343559642, 22.494408836907635 21.666710699058807, 22.771638597533858 21.14805029709527, 22.94235584120969 20.585270966048384, 23 20, 23 10, 22.94235584120969 9.414729033951616, 22.771638597533858 8.851949702904731, 22.494408836907635 8.333289300941193, 22.121320343559642 7.878679656440358, 21.666710699058807 7.505591163092364, 21.14805029709527 7.22836140246614, 20.585270966048384 7.057644158790309, 20 7, 10 7, 9.414729033951614 7.057644158790309, 8.85194970290473 7.22836140246614, 8.333289300941193 7.505591163092364, 7.878679656440357 7.878679656440358, 7.5055911630923635 8.333289300941194, 7.22836140246614 8.851949702904731, 7.057644158790309 9.414729033951614, 7 10, 7 20), (8 20, 8 10, 8.03842943919354 9.609819355967744, 8.152240934977426 9.23463313526982, 8.337060775394908 8.888859533960796, 8.585786437626904 8.585786437626904, 8.888859533960796 8.33706077539491, 9.234633135269819 8.152240934977428, 9.609819355967742 8.03842943919354, 10 8, 20 8, 20.390180644032256 8.03842943919354, 20.76536686473018 8.152240934977426, 21.111140466039206 8.33706077539491, 21.414213562373096 8.585786437626904, 21.66293922460509 8.888859533960796, 21.847759065022572 9.23463313526982, 21.96157056080646 9.609819355967744, 22 10, 22 20, 21.96157056080646 20.390180644032256, 21.847759065022572 20.76536686473018, 21.66293922460509 21.111140466039203, 21.414213562373096 21.414213562373096, 21.111140466039206 21.66293922460509, 20.76536686473018 21.847759065022572, 20.390180644032256 21.96157056080646, 20 22, 10 22, 9.609819355967744 21.96157056080646, 9.23463313526982 21.847759065022572, 8.888859533960796 21.66293922460509, 8.585786437626904 21.414213562373096, 8.33706077539491 21.111140466039203, 8.152240934977426 20.76536686473018, 8.03842943919354 20.390180644032256, 8 20)))", rs.getObject(1)); + rs.close(); + } + } From 29169ba4c1691f4b3186aea56531c4eadb2fe3c4 Mon Sep 17 00:00:00 2001 From: Erwan Bocher Date: Wed, 7 Jan 2015 09:45:08 +0100 Subject: [PATCH 7/8] Fix test and negative ring buffer on polygon --- .../spatial/create/ST_RingBuffer.java | 8 ++-- .../spatial/processing/ST_RingSideBuffer.java | 2 - .../h2spatialext/SpatialFunctionTest.java | 37 ++++++++++++++++++- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/create/ST_RingBuffer.java b/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/create/ST_RingBuffer.java index 7df5260835..14c7249167 100644 --- a/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/create/ST_RingBuffer.java +++ b/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/create/ST_RingBuffer.java @@ -24,7 +24,6 @@ package org.h2gis.h2spatialext.function.spatial.create; import com.vividsolutions.jts.geom.Geometry; -import com.vividsolutions.jts.geom.GeometryFactory; import com.vividsolutions.jts.geom.Point; import com.vividsolutions.jts.geom.Polygon; import com.vividsolutions.jts.operation.buffer.BufferOp; @@ -39,9 +38,7 @@ * @author Erwan Bocher */ public class ST_RingBuffer extends AbstractFunction implements ScalarFunction { - - private static final GeometryFactory GF = new GeometryFactory(); - + public ST_RingBuffer() { addProperty(PROP_REMARKS, "Compute a ring buffer around a geometry.\n" + "Avalaible arguments are :\n" @@ -137,7 +134,7 @@ public static Geometry ringBuffer(Geometry geom, double bufferDistance, return computePositiveRingBuffer(geom, bufferDistance, numBuffer, bufferParameters, doDifference); } else if (bufferDistance < 0) { if (geom instanceof Point) { - throw new SQLException("Cannot compute a negative ring side buffer on a point."); + throw new SQLException("Cannot compute a negative ring buffer on a point."); } else { return computeNegativeRingBuffer(geom, bufferDistance, numBuffer, bufferParameters, doDifference); } @@ -198,6 +195,7 @@ public static Geometry computeNegativeRingBuffer(Geometry geom, double bufferDis double distance = 0; if (geom instanceof Polygon) { geom = ((Polygon) geom).getExteriorRing(); + bufferParameters.setSingleSided(true); } for (int i = 0; i < numBuffer; i++) { distance += bufferDistance; diff --git a/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/processing/ST_RingSideBuffer.java b/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/processing/ST_RingSideBuffer.java index 18bfec5e14..73a3bb83bd 100644 --- a/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/processing/ST_RingSideBuffer.java +++ b/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/processing/ST_RingSideBuffer.java @@ -26,8 +26,6 @@ import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.Point; -import com.vividsolutions.jts.geom.Polygon; -import com.vividsolutions.jts.operation.buffer.BufferOp; import com.vividsolutions.jts.operation.buffer.BufferParameters; import java.sql.SQLException; import org.h2gis.h2spatialapi.DeterministicScalarFunction; diff --git a/h2spatial-ext/src/test/java/org/h2gis/h2spatialext/SpatialFunctionTest.java b/h2spatial-ext/src/test/java/org/h2gis/h2spatialext/SpatialFunctionTest.java index 4043fd114e..6e2ede6034 100644 --- a/h2spatial-ext/src/test/java/org/h2gis/h2spatialext/SpatialFunctionTest.java +++ b/h2spatial-ext/src/test/java/org/h2gis/h2spatialext/SpatialFunctionTest.java @@ -2741,6 +2741,40 @@ public void test_ST_RingBufferComplex2() throws Exception { + " (10 30, -10 30, -13.90180644032255 29.615705608064612, -17.653668647301785 28.47759065022574, -21.11140466039204 26.629392246050905, -24.14213562373095 24.14213562373095, -26.629392246050905 21.111404660392044, -28.477590650225736 17.6536686473018, -29.61570560806461 13.901806440322572, -30 10.000000000000002, -29.61570560806461 6.098193559677433, -28.477590650225736 2.346331352698207, -26.62939224605091 -1.11140466039204, -24.142135623730955 -4.142135623730949, -21.111404660392044 -6.629392246050905, -17.653668647301807 -8.477590650225729, -13.901806440322574 -9.615705608064605, -10 -10, 10 -10, 13.901806440322552 -9.615705608064612, 17.65366864730179 -8.47759065022574, 21.11140466039204 -6.629392246050905, 24.14213562373095 -4.142135623730949, 26.629392246050905 -1.1114046603920418, 28.477590650225736 2.346331352698204, 29.61570560806461 6.098193559677435, 30 10, 29.61570560806461 13.901806440322565, 28.477590650225736 17.653668647301796, 26.629392246050905 21.111404660392044, 24.14213562373095 24.14213562373095, 21.111404660392047 26.629392246050905, 17.653668647301796 28.477590650225736, 13.901806440322567 29.61570560806461, 10 30)))", rs.getObject(1)); rs.close(); } + + @Test + public void test_ST_RingBufferComplex3() throws Exception { + ResultSet rs = st.executeQuery("SELECT ST_RingBuffer('LINESTRING (-10 10, 10 10)'::GEOMETRY, -10, 3,'endcap=ROUND');"); + assertTrue(rs.next()); + assertTrue(rs.getString(1).equalsIgnoreCase("MULTIPOLYGON EMPTY")); + rs.close(); + } + + @Test + public void test_ST_RingBufferComplex4() throws Exception { + ResultSet rs = st.executeQuery("SELECT ST_RingBuffer('POLYGON ((10 20, 20 20, 20 10, 10 10, 10 20))'::GEOMETRY, 1, 3);"); + assertTrue(rs.next()); + assertGeometryBarelyEquals("MULTIPOLYGON (((9 20, 9.01921471959677 20.195090322016128, 9.076120467488714 20.38268343236509, 9.168530387697455 20.5555702330196, 9.292893218813452 20.707106781186546, 9.444429766980399 20.831469612302545, 9.61731656763491 20.923879532511286, 9.804909677983872 20.980785280403232, 10 21, 20 21, 20.195090322016128 20.980785280403232, 20.38268343236509 20.923879532511286, 20.5555702330196 20.831469612302545, 20.707106781186546 20.707106781186546, 20.831469612302545 20.5555702330196, 20.923879532511286 20.38268343236509, 20.980785280403232 20.195090322016128, 21 20, 21 10, 20.980785280403232 9.804909677983872, 20.923879532511286 9.61731656763491, 20.831469612302545 9.444429766980399, 20.707106781186546 9.292893218813452, 20.5555702330196 9.168530387697455, 20.38268343236509 9.076120467488714, 20.195090322016128 9.01921471959677, 20 9, 10 9, 9.804909677983872 9.01921471959677, 9.61731656763491 9.076120467488714, 9.444429766980399 9.168530387697455, 9.292893218813452 9.292893218813452, 9.168530387697455 9.444429766980399, 9.076120467488714 9.61731656763491, 9.01921471959677 9.804909677983872, 9 10, 9 20), (10 20, 10 10, 20 10, 20 20, 10 20)), ((8 20, 8.03842943919354 20.390180644032256, 8.152240934977426 20.76536686473018, 8.33706077539491 21.111140466039203, 8.585786437626904 21.414213562373096, 8.888859533960796 21.66293922460509, 9.23463313526982 21.847759065022572, 9.609819355967744 21.96157056080646, 10 22, 20 22, 20.390180644032256 21.96157056080646, 20.76536686473018 21.847759065022572, 21.111140466039206 21.66293922460509, 21.414213562373096 21.414213562373096, 21.66293922460509 21.111140466039203, 21.847759065022572 20.76536686473018, 21.96157056080646 20.390180644032256, 22 20, 22 10, 21.96157056080646 9.609819355967744, 21.847759065022572 9.23463313526982, 21.66293922460509 8.888859533960796, 21.414213562373096 8.585786437626904, 21.111140466039206 8.33706077539491, 20.76536686473018 8.152240934977426, 20.390180644032256 8.03842943919354, 20 8, 10 8, 9.609819355967742 8.03842943919354, 9.234633135269819 8.152240934977428, 8.888859533960796 8.33706077539491, 8.585786437626904 8.585786437626904, 8.337060775394908 8.888859533960796, 8.152240934977426 9.23463313526982, 8.03842943919354 9.609819355967744, 8 10, 8 20), (9 20, 9 10, 9.01921471959677 9.804909677983872, 9.076120467488714 9.61731656763491, 9.168530387697455 9.444429766980399, 9.292893218813452 9.292893218813452, 9.444429766980399 9.168530387697455, 9.61731656763491 9.076120467488714, 9.804909677983872 9.01921471959677, 10 9, 20 9, 20.195090322016128 9.01921471959677, 20.38268343236509 9.076120467488714, 20.5555702330196 9.168530387697455, 20.707106781186546 9.292893218813452, 20.831469612302545 9.444429766980399, 20.923879532511286 9.61731656763491, 20.980785280403232 9.804909677983872, 21 10, 21 20, 20.980785280403232 20.195090322016128, 20.923879532511286 20.38268343236509, 20.831469612302545 20.5555702330196, 20.707106781186546 20.707106781186546, 20.5555702330196 20.831469612302545, 20.38268343236509 20.923879532511286, 20.195090322016128 20.980785280403232, 20 21, 10 21, 9.804909677983872 20.980785280403232, 9.61731656763491 20.923879532511286, 9.444429766980399 20.831469612302545, 9.292893218813452 20.707106781186546, 9.168530387697455 20.5555702330196, 9.076120467488714 20.38268343236509, 9.01921471959677 20.195090322016128, 9 20)), ((7 20, 7.057644158790309 20.585270966048387, 7.22836140246614 21.14805029709527, 7.5055911630923635 21.666710699058807, 7.878679656440358 22.121320343559642, 8.333289300941194 22.494408836907635, 8.851949702904731 22.771638597533858, 9.414729033951616 22.94235584120969, 10 23, 20 23, 20.585270966048384 22.94235584120969, 21.14805029709527 22.771638597533858, 21.666710699058807 22.494408836907635, 22.121320343559642 22.121320343559642, 22.494408836907635 21.666710699058807, 22.771638597533858 21.14805029709527, 22.94235584120969 20.585270966048384, 23 20, 23 10, 22.94235584120969 9.414729033951616, 22.771638597533858 8.851949702904731, 22.494408836907635 8.333289300941193, 22.121320343559642 7.878679656440358, 21.666710699058807 7.505591163092364, 21.14805029709527 7.22836140246614, 20.585270966048384 7.057644158790309, 20 7, 10 7, 9.414729033951614 7.057644158790309, 8.85194970290473 7.22836140246614, 8.333289300941193 7.505591163092364, 7.878679656440357 7.878679656440358, 7.5055911630923635 8.333289300941194, 7.22836140246614 8.851949702904731, 7.057644158790309 9.414729033951614, 7 10, 7 20), (8 20, 8 10, 8.03842943919354 9.609819355967744, 8.152240934977426 9.23463313526982, 8.337060775394908 8.888859533960796, 8.585786437626904 8.585786437626904, 8.888859533960796 8.33706077539491, 9.234633135269819 8.152240934977428, 9.609819355967742 8.03842943919354, 10 8, 20 8, 20.390180644032256 8.03842943919354, 20.76536686473018 8.152240934977426, 21.111140466039206 8.33706077539491, 21.414213562373096 8.585786437626904, 21.66293922460509 8.888859533960796, 21.847759065022572 9.23463313526982, 21.96157056080646 9.609819355967744, 22 10, 22 20, 21.96157056080646 20.390180644032256, 21.847759065022572 20.76536686473018, 21.66293922460509 21.111140466039203, 21.414213562373096 21.414213562373096, 21.111140466039206 21.66293922460509, 20.76536686473018 21.847759065022572, 20.390180644032256 21.96157056080646, 20 22, 10 22, 9.609819355967744 21.96157056080646, 9.23463313526982 21.847759065022572, 8.888859533960796 21.66293922460509, 8.585786437626904 21.414213562373096, 8.33706077539491 21.111140466039203, 8.152240934977426 20.76536686473018, 8.03842943919354 20.390180644032256, 8 20)))", rs.getObject(1)); + rs.close(); + } + + @Test + public void test_ST_RingBufferComplex5() throws Exception { + ResultSet rs = st.executeQuery("SELECT ST_RingBuffer('POLYGON ((10 20, 20 20, 20 10, 10 10, 10 20))'::GEOMETRY, -1, 3);"); + assertTrue(rs.next()); + assertGeometryBarelyEquals("MULTIPOLYGON (((10 19, 10 20, 11 20, 20 20, 20 10, 10 10, 10 19), (11 19, 11 11, 19 11, 19 19, 11 19)), ((11 19, 19 19, 19 11, 11 11, 11 19), (12 18, 12 12, 18 12, 18 18, 12 18)), ((12 18, 18 18, 18 12, 12 12, 12 18), (13 17, 13 13, 17 13, 17 17, 13 17)))", rs.getObject(1)); + rs.close(); + } + + @Test + public void test_ST_RingBufferComplex6() throws Exception { + ResultSet rs = st.executeQuery("SELECT ST_RingBuffer('POLYGON ((10 20, 20 20, 20 10, 10 10, 10 20)," + + " (12.1 18.1, 14.1 18.1, 14.1 16, 12.1 16, 12.1 18.1)," + + " (15.6 14, 18 14, 18 11.5, 15.6 11.5, 15.6 14))'::GEOMETRY, -1, 3);"); + assertTrue(rs.next()); + assertGeometryBarelyEquals("MULTIPOLYGON (((10 19, 10 20, 11 20, 20 20, 20 10, 10 10, 10 19), (11 19, 11 11, 19 11, 19 19, 11 19)), ((11 19, 19 19, 19 11, 11 11, 11 19), (12 18, 12 12, 18 12, 18 18, 12 18)), ((12 18, 18 18, 18 12, 12 12, 12 18), (13 17, 13 13, 17 13, 17 17, 13 17)))", rs.getObject(1)); + rs.close(); + } @Test public void test_ST_MinimumDiameter1() throws Exception { @@ -3389,6 +3423,5 @@ public void test_ST_RingSideBuffer6() throws Exception { assertTrue(rs.next()); assertGeometryBarelyEquals("MULTIPOLYGON (((9 20, 9.01921471959677 20.195090322016128, 9.076120467488714 20.38268343236509, 9.168530387697455 20.5555702330196, 9.292893218813452 20.707106781186546, 9.444429766980399 20.831469612302545, 9.61731656763491 20.923879532511286, 9.804909677983872 20.980785280403232, 10 21, 20 21, 20.195090322016128 20.980785280403232, 20.38268343236509 20.923879532511286, 20.5555702330196 20.831469612302545, 20.707106781186546 20.707106781186546, 20.831469612302545 20.5555702330196, 20.923879532511286 20.38268343236509, 20.980785280403232 20.195090322016128, 21 20, 21 10, 20.980785280403232 9.804909677983872, 20.923879532511286 9.61731656763491, 20.831469612302545 9.444429766980399, 20.707106781186546 9.292893218813452, 20.5555702330196 9.168530387697455, 20.38268343236509 9.076120467488714, 20.195090322016128 9.01921471959677, 20 9, 10 9, 9.804909677983872 9.01921471959677, 9.61731656763491 9.076120467488714, 9.444429766980399 9.168530387697455, 9.292893218813452 9.292893218813452, 9.168530387697455 9.444429766980399, 9.076120467488714 9.61731656763491, 9.01921471959677 9.804909677983872, 9 10, 9 20), (10 20, 10 10, 20 10, 20 20, 10 20)), ((8 20, 8.03842943919354 20.390180644032256, 8.152240934977426 20.76536686473018, 8.33706077539491 21.111140466039203, 8.585786437626904 21.414213562373096, 8.888859533960796 21.66293922460509, 9.23463313526982 21.847759065022572, 9.609819355967744 21.96157056080646, 10 22, 20 22, 20.390180644032256 21.96157056080646, 20.76536686473018 21.847759065022572, 21.111140466039206 21.66293922460509, 21.414213562373096 21.414213562373096, 21.66293922460509 21.111140466039203, 21.847759065022572 20.76536686473018, 21.96157056080646 20.390180644032256, 22 20, 22 10, 21.96157056080646 9.609819355967744, 21.847759065022572 9.23463313526982, 21.66293922460509 8.888859533960796, 21.414213562373096 8.585786437626904, 21.111140466039206 8.33706077539491, 20.76536686473018 8.152240934977426, 20.390180644032256 8.03842943919354, 20 8, 10 8, 9.609819355967742 8.03842943919354, 9.234633135269819 8.152240934977428, 8.888859533960796 8.33706077539491, 8.585786437626904 8.585786437626904, 8.337060775394908 8.888859533960796, 8.152240934977426 9.23463313526982, 8.03842943919354 9.609819355967744, 8 10, 8 20), (9 20, 9 10, 9.01921471959677 9.804909677983872, 9.076120467488714 9.61731656763491, 9.168530387697455 9.444429766980399, 9.292893218813452 9.292893218813452, 9.444429766980399 9.168530387697455, 9.61731656763491 9.076120467488714, 9.804909677983872 9.01921471959677, 10 9, 20 9, 20.195090322016128 9.01921471959677, 20.38268343236509 9.076120467488714, 20.5555702330196 9.168530387697455, 20.707106781186546 9.292893218813452, 20.831469612302545 9.444429766980399, 20.923879532511286 9.61731656763491, 20.980785280403232 9.804909677983872, 21 10, 21 20, 20.980785280403232 20.195090322016128, 20.923879532511286 20.38268343236509, 20.831469612302545 20.5555702330196, 20.707106781186546 20.707106781186546, 20.5555702330196 20.831469612302545, 20.38268343236509 20.923879532511286, 20.195090322016128 20.980785280403232, 20 21, 10 21, 9.804909677983872 20.980785280403232, 9.61731656763491 20.923879532511286, 9.444429766980399 20.831469612302545, 9.292893218813452 20.707106781186546, 9.168530387697455 20.5555702330196, 9.076120467488714 20.38268343236509, 9.01921471959677 20.195090322016128, 9 20)), ((7 20, 7.057644158790309 20.585270966048387, 7.22836140246614 21.14805029709527, 7.5055911630923635 21.666710699058807, 7.878679656440358 22.121320343559642, 8.333289300941194 22.494408836907635, 8.851949702904731 22.771638597533858, 9.414729033951616 22.94235584120969, 10 23, 20 23, 20.585270966048384 22.94235584120969, 21.14805029709527 22.771638597533858, 21.666710699058807 22.494408836907635, 22.121320343559642 22.121320343559642, 22.494408836907635 21.666710699058807, 22.771638597533858 21.14805029709527, 22.94235584120969 20.585270966048384, 23 20, 23 10, 22.94235584120969 9.414729033951616, 22.771638597533858 8.851949702904731, 22.494408836907635 8.333289300941193, 22.121320343559642 7.878679656440358, 21.666710699058807 7.505591163092364, 21.14805029709527 7.22836140246614, 20.585270966048384 7.057644158790309, 20 7, 10 7, 9.414729033951614 7.057644158790309, 8.85194970290473 7.22836140246614, 8.333289300941193 7.505591163092364, 7.878679656440357 7.878679656440358, 7.5055911630923635 8.333289300941194, 7.22836140246614 8.851949702904731, 7.057644158790309 9.414729033951614, 7 10, 7 20), (8 20, 8 10, 8.03842943919354 9.609819355967744, 8.152240934977426 9.23463313526982, 8.337060775394908 8.888859533960796, 8.585786437626904 8.585786437626904, 8.888859533960796 8.33706077539491, 9.234633135269819 8.152240934977428, 9.609819355967742 8.03842943919354, 10 8, 20 8, 20.390180644032256 8.03842943919354, 20.76536686473018 8.152240934977426, 21.111140466039206 8.33706077539491, 21.414213562373096 8.585786437626904, 21.66293922460509 8.888859533960796, 21.847759065022572 9.23463313526982, 21.96157056080646 9.609819355967744, 22 10, 22 20, 21.96157056080646 20.390180644032256, 21.847759065022572 20.76536686473018, 21.66293922460509 21.111140466039203, 21.414213562373096 21.414213562373096, 21.111140466039206 21.66293922460509, 20.76536686473018 21.847759065022572, 20.390180644032256 21.96157056080646, 20 22, 10 22, 9.609819355967744 21.96157056080646, 9.23463313526982 21.847759065022572, 8.888859533960796 21.66293922460509, 8.585786437626904 21.414213562373096, 8.33706077539491 21.111140466039203, 8.152240934977426 20.76536686473018, 8.03842943919354 20.390180644032256, 8 20)))", rs.getObject(1)); rs.close(); - } - + } } From cba6235f587b49b556d912e66baf253e72430f66 Mon Sep 17 00:00:00 2001 From: Erwan Bocher Date: Wed, 7 Jan 2015 09:50:58 +0100 Subject: [PATCH 8/8] Improve documentation --- .../h2spatialext/function/spatial/create/ST_RingBuffer.java | 3 ++- .../function/spatial/processing/ST_RingSideBuffer.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/create/ST_RingBuffer.java b/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/create/ST_RingBuffer.java index 14c7249167..a53e1d174c 100644 --- a/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/create/ST_RingBuffer.java +++ b/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/create/ST_RingBuffer.java @@ -46,7 +46,8 @@ public ST_RingBuffer() { + " (3) the number of rings, (4) optional - the end cap style (square, round) Default is round\n" + "a list of blank-separated key=value pairs (string case) iso used t manage line style parameters.\n " + "Please read the ST_Buffer documention.\n" - + " (5) optional - createHole True if you want to keep only difference between buffers Default is true"); + + " (5) optional - createHole True if you want to keep only difference between buffers Default is true.\n" + + "Note : Holes are not supported by this function."); } @Override diff --git a/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/processing/ST_RingSideBuffer.java b/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/processing/ST_RingSideBuffer.java index 73a3bb83bd..eb8ae8e871 100644 --- a/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/processing/ST_RingSideBuffer.java +++ b/h2spatial-ext/src/main/java/org/h2gis/h2spatialext/function/spatial/processing/ST_RingSideBuffer.java @@ -47,7 +47,8 @@ public ST_RingSideBuffer(){ + "a list of blank-separated key=value pairs (string case) iso used t manage line style parameters.\n " + " The end cap style for single-sided buffers is always ignored, and forced to the equivalent of flat.\n" + "Please read the ST_Buffer documention.\n" - + " (5) optional - createHole True if you want to keep only difference between buffers Default is true"); + + " (5) optional - createHole True if you want to keep only difference between buffers Default is true.\n" + + "Note : Holes are not supported by this function."); }