Skip to content

Commit

Permalink
Merge pull request #53 from sheinbergon/simplify-25.0
Browse files Browse the repository at this point in the history
Simplify 25.0
  • Loading branch information
sheinbergon authored Aug 23, 2024
2 parents 09a296d + 7eb46cc commit cd21b8e
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 25 deletions.
40 changes: 24 additions & 16 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,30 @@ Enjoying my work? A show of support would be much obliged :grin:
- Restart your Dremio server(s)
- Rejoice! (and see the [WIKI](https://github.com/sheinbergon/dremio-udf-gis/wiki) for detailed usage instructions)

#### Version Compatbility

| Library Version | Dremio Version | Status |
|-----------------|----------------|------------|
| 0.2.x | 20.1.x | Legacy |
| 0.3.x | 21.1.x | Legacy |
| 0.4.x | 21.2.x | Legacy |
| 0.5.x | 22.0.x | Legacy |
| 0.6.x | 22.1.x | Legacy |
| 0.7.x | 23.0.x | Legacy |
| 0.8.x | 23.1.x | Legacy |
| 0.9.x | 24.0.x | Legacy |
| 0.10.x | 24.1.x | Legacy |
| 0.11.x | 24.2.x | Legacy |
| 0.12.x | 24.3.x | Maintained |
| 0.13.x | 25.0.x | Maintained |
#### Version Compatibility

##### Actively Maintained

| Library Version | Dremio Version |
|-----------------|----------------|
| 0.12.x | 24.3.x |
| 0.14.x | 25.0.0 |

##### Legacy

| Library Version | Dremio Version |
|-----------------|----------------|
| 0.2.x | 20.1.x |
| 0.3.x | 21.1.x |
| 0.4.x | 21.2.x |
| 0.5.x | 22.0.x |
| 0.6.x | 22.1.x |
| 0.7.x | 23.0.x |
| 0.8.x | 23.1.x |
| 0.9.x | 24.0.x |
| 0.10.x | 24.1.x |
| 0.11.x | 24.2.x |
| 0.12.x | 24.3.0 |

### Usage Notes

Expand Down
5 changes: 2 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
<groupId>org.sheinbergon</groupId>
<artifactId>dremio-udf-gis</artifactId>
<properties>

<checkstyle.version>9.3</checkstyle.version>
<checkstyle.version>10.15.0</checkstyle.version>
<dremio.version>25.0.0-202404051521110861-ed9515a8</dremio.version>
<dremio-arrow.version>14.0.2-20240131150813-452ae43b2e-dremio</dremio-arrow.version>
<proj4j.version>1.3.0</proj4j.version>
Expand All @@ -23,7 +22,7 @@
<carrotsearch.version>0.7.0</carrotsearch.version>
<arrow-memory-netty.version>14.0.2</arrow-memory-netty.version>
</properties>
<version>0.14.0-SNAPSHOT</version>
<version>0.14.2-SNAPSHOT</version>
<name>dremio-udf-gis</name>
<description>GIS UDF extensions for Dremio</description>
<url>https://github.com/sheinbergon/dremio-udf-gis</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void setup() {
public void eval() {
if (org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.isHolderSet(binaryInput)) {
org.locationtech.jts.geom.Geometry geom = org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.toGeometry(binaryInput);
boolean result = geom.isSimple();
boolean result = org.locationtech.jts.operation.valid.IsSimpleOp.isSimple(geom);
org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.setBooleanValue(output, result);
} else {
org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.markHolderNotSet(output);
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/org/sheinbergon/dremio/udf/gis/STSimplify.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.dremio.exec.expr.annotations.FunctionTemplate;
import com.dremio.exec.expr.annotations.Output;
import com.dremio.exec.expr.annotations.Param;
import org.apache.arrow.memory.ArrowBuf;

import javax.inject.Inject;

Expand All @@ -31,25 +30,29 @@
nulls = FunctionTemplate.NullHandling.INTERNAL,
costCategory = FunctionTemplate.FunctionCostCategory.COMPLEX)
public class STSimplify implements SimpleFunction {

@Param
org.apache.arrow.vector.holders.NullableVarBinaryHolder binaryInput;

@Param(constant = true)
@Param
org.apache.arrow.vector.holders.Float8Holder toleranceInput;

@Output
org.apache.arrow.vector.holders.NullableVarBinaryHolder binaryOutput;

@Inject
ArrowBuf buffer;
org.apache.arrow.memory.ArrowBuf buffer;

public void setup() {
}

public void eval() {
if (org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.isHolderSet(binaryInput)) {
double tolerance = toleranceInput.value;
org.locationtech.jts.geom.Geometry geom = org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.toGeometry(binaryInput);
org.locationtech.jts.geom.Geometry simplified = org.locationtech.jts.simplify.DouglasPeuckerSimplifier.simplify(geom, toleranceInput.value);
org.locationtech.jts.simplify.DouglasPeuckerSimplifier simplifier = new org.locationtech.jts.simplify.DouglasPeuckerSimplifier(geom);
simplifier.setDistanceTolerance(tolerance);
org.locationtech.jts.geom.Geometry simplified = simplifier.getResultGeometry();
simplified.setSRID(geom.getSRID());
byte[] bytes = org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.toEWKB(simplified);
buffer = buffer.reallocIfNeeded(bytes.length);
Expand All @@ -58,4 +61,4 @@ public void eval() {
org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.markHolderNotSet(binaryOutput);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.sheinbergon.dremio.udf.gis;

import com.dremio.exec.expr.SimpleFunction;
import com.dremio.exec.expr.annotations.FunctionTemplate;
import com.dremio.exec.expr.annotations.Output;
import com.dremio.exec.expr.annotations.Param;

import javax.inject.Inject;

@FunctionTemplate(
name = "ST_SimplifyPreserveTopology",
scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls = FunctionTemplate.NullHandling.INTERNAL,
costCategory = FunctionTemplate.FunctionCostCategory.COMPLEX)
public class STSimplifyPreserveTopology implements SimpleFunction {

@Param
org.apache.arrow.vector.holders.NullableVarBinaryHolder binaryInput;

@Param
org.apache.arrow.vector.holders.Float8Holder toleranceInput;

@Output
org.apache.arrow.vector.holders.NullableVarBinaryHolder binaryOutput;

@Inject
org.apache.arrow.memory.ArrowBuf buffer;

public void setup() {
}

public void eval() {
if (org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.isHolderSet(binaryInput)) {
double tolerance = toleranceInput.value;
org.locationtech.jts.geom.Geometry geom = org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.toGeometry(binaryInput);
org.locationtech.jts.simplify.TopologyPreservingSimplifier simplifier = new org.locationtech.jts.simplify.TopologyPreservingSimplifier(geom);
simplifier.setDistanceTolerance(tolerance);
org.locationtech.jts.geom.Geometry result = simplifier.getResultGeometry();
byte[] bytes = org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.toEWKB(result);
buffer = buffer.reallocIfNeeded(bytes.length);
org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.populate(bytes, buffer, binaryOutput);
} else {
org.sheinbergon.dremio.udf.gis.util.GeometryHelpers.markHolderNotSet(binaryOutput);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.sheinbergon.dremio.udf.gis

import org.apache.arrow.vector.holders.Float8Holder
import org.apache.arrow.vector.holders.NullableVarBinaryHolder
import org.sheinbergon.dremio.udf.gis.spec.GeometryProcessingFunSpec
import org.sheinbergon.dremio.udf.gis.util.allocateBuffer
import org.sheinbergon.dremio.udf.gis.util.reset

internal class STSimplifyPreserveTopologyTests : GeometryProcessingFunSpec<STSimplifyPreserveTopology>() {

init {

beforeEach {
function.toleranceInput.reset()
}

testGeometryProcessing(
name = "Calling ST_SimplifyPreserveTopology on a MULTILINESTRING with a tolerance of 40.0",
wkt = """
MULTILINESTRING (
(20 180, 20 150, 50 150, 50 100, 110 150, 150 140, 170 120),
(20 10, 80 30, 90 120),
(90 120, 130 130),
(130 130, 130 70, 160 40, 180 60, 180 90, 140 80),
(50 40, 70 40, 80 70, 70 60, 60 60, 50 50, 50 40)
)""".trimIndent(),
expected = """
MULTILINESTRING(
(20 180,50 100,110 150,170 120),
(20 10,90 120),
(90 120,130 130),
(130 130,130 70,160 40,180 90,140 80),
(50 40,70 40,80 70,60 60,50 40)
)""".trimIndent()
) { function.toleranceInput.value = 40.0 }

testNullGeometryProcessing(
"Calling ST_SimplifyPreserveTopology on a NULL input"
)
}

override val function = STSimplifyPreserveTopology().apply {
binaryInput = NullableVarBinaryHolder()
toleranceInput = Float8Holder()
binaryOutput = NullableVarBinaryHolder()
buffer = allocateBuffer()
}

override val STSimplifyPreserveTopology.wkbInput: NullableVarBinaryHolder get() = function.binaryInput
override val STSimplifyPreserveTopology.wkbOutput: NullableVarBinaryHolder get() = function.binaryOutput
}

0 comments on commit cd21b8e

Please sign in to comment.