Skip to content

Commit cd21b8e

Browse files
authored
Merge pull request #53 from sheinbergon/simplify-25.0
Simplify 25.0
2 parents 09a296d + 7eb46cc commit cd21b8e

File tree

6 files changed

+149
-25
lines changed

6 files changed

+149
-25
lines changed

README.MD

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,30 @@ Enjoying my work? A show of support would be much obliged :grin:
3232
- Restart your Dremio server(s)
3333
- Rejoice! (and see the [WIKI](https://github.com/sheinbergon/dremio-udf-gis/wiki) for detailed usage instructions)
3434

35-
#### Version Compatbility
36-
37-
| Library Version | Dremio Version | Status |
38-
|-----------------|----------------|------------|
39-
| 0.2.x | 20.1.x | Legacy |
40-
| 0.3.x | 21.1.x | Legacy |
41-
| 0.4.x | 21.2.x | Legacy |
42-
| 0.5.x | 22.0.x | Legacy |
43-
| 0.6.x | 22.1.x | Legacy |
44-
| 0.7.x | 23.0.x | Legacy |
45-
| 0.8.x | 23.1.x | Legacy |
46-
| 0.9.x | 24.0.x | Legacy |
47-
| 0.10.x | 24.1.x | Legacy |
48-
| 0.11.x | 24.2.x | Legacy |
49-
| 0.12.x | 24.3.x | Maintained |
50-
| 0.13.x | 25.0.x | Maintained |
35+
#### Version Compatibility
36+
37+
##### Actively Maintained
38+
39+
| Library Version | Dremio Version |
40+
|-----------------|----------------|
41+
| 0.12.x | 24.3.x |
42+
| 0.14.x | 25.0.0 |
43+
44+
##### Legacy
45+
46+
| Library Version | Dremio Version |
47+
|-----------------|----------------|
48+
| 0.2.x | 20.1.x |
49+
| 0.3.x | 21.1.x |
50+
| 0.4.x | 21.2.x |
51+
| 0.5.x | 22.0.x |
52+
| 0.6.x | 22.1.x |
53+
| 0.7.x | 23.0.x |
54+
| 0.8.x | 23.1.x |
55+
| 0.9.x | 24.0.x |
56+
| 0.10.x | 24.1.x |
57+
| 0.11.x | 24.2.x |
58+
| 0.12.x | 24.3.0 |
5159

5260
### Usage Notes
5361

pom.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
<groupId>org.sheinbergon</groupId>
66
<artifactId>dremio-udf-gis</artifactId>
77
<properties>
8-
9-
<checkstyle.version>9.3</checkstyle.version>
8+
<checkstyle.version>10.15.0</checkstyle.version>
109
<dremio.version>25.0.0-202404051521110861-ed9515a8</dremio.version>
1110
<dremio-arrow.version>14.0.2-20240131150813-452ae43b2e-dremio</dremio-arrow.version>
1211
<proj4j.version>1.3.0</proj4j.version>
@@ -23,7 +22,7 @@
2322
<carrotsearch.version>0.7.0</carrotsearch.version>
2423
<arrow-memory-netty.version>14.0.2</arrow-memory-netty.version>
2524
</properties>
26-
<version>0.14.0-SNAPSHOT</version>
25+
<version>0.14.2-SNAPSHOT</version>
2726
<name>dremio-udf-gis</name>
2827
<description>GIS UDF extensions for Dremio</description>
2928
<url>https://github.com/sheinbergon/dremio-udf-gis</url>

src/main/java/org/sheinbergon/dremio/udf/gis/STIsSimple.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void setup() {
3939
public void eval() {
4040
if (org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.isHolderSet(binaryInput)) {
4141
org.locationtech.jts.geom.Geometry geom = org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.toGeometry(binaryInput);
42-
boolean result = geom.isSimple();
42+
boolean result = org.locationtech.jts.operation.valid.IsSimpleOp.isSimple(geom);
4343
org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.setBooleanValue(output, result);
4444
} else {
4545
org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.markHolderNotSet(output);

src/main/java/org/sheinbergon/dremio/udf/gis/STSimplify.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import com.dremio.exec.expr.annotations.FunctionTemplate;
2222
import com.dremio.exec.expr.annotations.Output;
2323
import com.dremio.exec.expr.annotations.Param;
24-
import org.apache.arrow.memory.ArrowBuf;
2524

2625
import javax.inject.Inject;
2726

@@ -31,25 +30,29 @@
3130
nulls = FunctionTemplate.NullHandling.INTERNAL,
3231
costCategory = FunctionTemplate.FunctionCostCategory.COMPLEX)
3332
public class STSimplify implements SimpleFunction {
33+
3434
@Param
3535
org.apache.arrow.vector.holders.NullableVarBinaryHolder binaryInput;
3636

37-
@Param(constant = true)
37+
@Param
3838
org.apache.arrow.vector.holders.Float8Holder toleranceInput;
3939

4040
@Output
4141
org.apache.arrow.vector.holders.NullableVarBinaryHolder binaryOutput;
4242

4343
@Inject
44-
ArrowBuf buffer;
44+
org.apache.arrow.memory.ArrowBuf buffer;
4545

4646
public void setup() {
4747
}
4848

4949
public void eval() {
5050
if (org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.isHolderSet(binaryInput)) {
51+
double tolerance = toleranceInput.value;
5152
org.locationtech.jts.geom.Geometry geom = org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.toGeometry(binaryInput);
52-
org.locationtech.jts.geom.Geometry simplified = org.locationtech.jts.simplify.DouglasPeuckerSimplifier.simplify(geom, toleranceInput.value);
53+
org.locationtech.jts.simplify.DouglasPeuckerSimplifier simplifier = new org.locationtech.jts.simplify.DouglasPeuckerSimplifier(geom);
54+
simplifier.setDistanceTolerance(tolerance);
55+
org.locationtech.jts.geom.Geometry simplified = simplifier.getResultGeometry();
5356
simplified.setSRID(geom.getSRID());
5457
byte[] bytes = org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.toEWKB(simplified);
5558
buffer = buffer.reallocIfNeeded(bytes.length);
@@ -58,4 +61,4 @@ public void eval() {
5861
org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.markHolderNotSet(binaryOutput);
5962
}
6063
}
61-
}
64+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
* <p>
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
* <p>
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.sheinbergon.dremio.udf.gis;
19+
20+
import com.dremio.exec.expr.SimpleFunction;
21+
import com.dremio.exec.expr.annotations.FunctionTemplate;
22+
import com.dremio.exec.expr.annotations.Output;
23+
import com.dremio.exec.expr.annotations.Param;
24+
25+
import javax.inject.Inject;
26+
27+
@FunctionTemplate(
28+
name = "ST_SimplifyPreserveTopology",
29+
scope = FunctionTemplate.FunctionScope.SIMPLE,
30+
nulls = FunctionTemplate.NullHandling.INTERNAL,
31+
costCategory = FunctionTemplate.FunctionCostCategory.COMPLEX)
32+
public class STSimplifyPreserveTopology implements SimpleFunction {
33+
34+
@Param
35+
org.apache.arrow.vector.holders.NullableVarBinaryHolder binaryInput;
36+
37+
@Param
38+
org.apache.arrow.vector.holders.Float8Holder toleranceInput;
39+
40+
@Output
41+
org.apache.arrow.vector.holders.NullableVarBinaryHolder binaryOutput;
42+
43+
@Inject
44+
org.apache.arrow.memory.ArrowBuf buffer;
45+
46+
public void setup() {
47+
}
48+
49+
public void eval() {
50+
if (org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.isHolderSet(binaryInput)) {
51+
double tolerance = toleranceInput.value;
52+
org.locationtech.jts.geom.Geometry geom = org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.toGeometry(binaryInput);
53+
org.locationtech.jts.simplify.TopologyPreservingSimplifier simplifier = new org.locationtech.jts.simplify.TopologyPreservingSimplifier(geom);
54+
simplifier.setDistanceTolerance(tolerance);
55+
org.locationtech.jts.geom.Geometry result = simplifier.getResultGeometry();
56+
byte[] bytes = org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.toEWKB(result);
57+
buffer = buffer.reallocIfNeeded(bytes.length);
58+
org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.populate(bytes, buffer, binaryOutput);
59+
} else {
60+
org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.markHolderNotSet(binaryOutput);
61+
}
62+
}
63+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package org.sheinbergon.dremio.udf.gis
2+
3+
import org.apache.arrow.vector.holders.Float8Holder
4+
import org.apache.arrow.vector.holders.NullableVarBinaryHolder
5+
import org.sheinbergon.dremio.udf.gis.spec.GeometryProcessingFunSpec
6+
import org.sheinbergon.dremio.udf.gis.util.allocateBuffer
7+
import org.sheinbergon.dremio.udf.gis.util.reset
8+
9+
internal class STSimplifyPreserveTopologyTests : GeometryProcessingFunSpec<STSimplifyPreserveTopology>() {
10+
11+
init {
12+
13+
beforeEach {
14+
function.toleranceInput.reset()
15+
}
16+
17+
testGeometryProcessing(
18+
name = "Calling ST_SimplifyPreserveTopology on a MULTILINESTRING with a tolerance of 40.0",
19+
wkt = """
20+
MULTILINESTRING (
21+
(20 180, 20 150, 50 150, 50 100, 110 150, 150 140, 170 120),
22+
(20 10, 80 30, 90 120),
23+
(90 120, 130 130),
24+
(130 130, 130 70, 160 40, 180 60, 180 90, 140 80),
25+
(50 40, 70 40, 80 70, 70 60, 60 60, 50 50, 50 40)
26+
)""".trimIndent(),
27+
expected = """
28+
MULTILINESTRING(
29+
(20 180,50 100,110 150,170 120),
30+
(20 10,90 120),
31+
(90 120,130 130),
32+
(130 130,130 70,160 40,180 90,140 80),
33+
(50 40,70 40,80 70,60 60,50 40)
34+
)""".trimIndent()
35+
) { function.toleranceInput.value = 40.0 }
36+
37+
testNullGeometryProcessing(
38+
"Calling ST_SimplifyPreserveTopology on a NULL input"
39+
)
40+
}
41+
42+
override val function = STSimplifyPreserveTopology().apply {
43+
binaryInput = NullableVarBinaryHolder()
44+
toleranceInput = Float8Holder()
45+
binaryOutput = NullableVarBinaryHolder()
46+
buffer = allocateBuffer()
47+
}
48+
49+
override val STSimplifyPreserveTopology.wkbInput: NullableVarBinaryHolder get() = function.binaryInput
50+
override val STSimplifyPreserveTopology.wkbOutput: NullableVarBinaryHolder get() = function.binaryOutput
51+
}

0 commit comments

Comments
 (0)