From 3dee8c5aa0db40d8f5a3896b62c97e02daddc5b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E9=9B=A8?= Date: Fri, 29 Jul 2022 10:55:45 +0800 Subject: [PATCH] =?UTF-8?q?TileClip=E6=9E=84=E9=80=A0=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E8=BE=93=E5=85=A5=E6=94=B9=E4=B8=BAbbox?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../spatial/BboxIntersection.java | 2 +- .../giscat/vector/mvt/MvtBuilder.java | 15 +----------- .../giscat/util/analyse/TileClip.java | 23 +++++++++++-------- .../giscat/util/analyse/TileClipJmhTest.java | 2 +- .../giscat/util/analyse/TileClipTest.java | 2 +- 5 files changed, 17 insertions(+), 27 deletions(-) diff --git a/giscat-vector/giscat-vector-mbexpression/src/main/java/org/wowtools/giscat/vector/mbexpression/spatial/BboxIntersection.java b/giscat-vector/giscat-vector-mbexpression/src/main/java/org/wowtools/giscat/vector/mbexpression/spatial/BboxIntersection.java index 078db94..c422042 100644 --- a/giscat-vector/giscat-vector-mbexpression/src/main/java/org/wowtools/giscat/vector/mbexpression/spatial/BboxIntersection.java +++ b/giscat-vector/giscat-vector-mbexpression/src/main/java/org/wowtools/giscat/vector/mbexpression/spatial/BboxIntersection.java @@ -65,7 +65,7 @@ public Feature getValue(Feature feature, ExpressionParams expressionParams) { if (null == bbox) { tileClip = null; } else { - tileClip = new TileClip(bbox.toPolygon(gf), gf); + tileClip = new TileClip(bbox.xmin, bbox.ymin, bbox.xmax, bbox.ymax, gf); } expressionParams.putCache(this, tileClip); } else { diff --git a/giscat-vector/giscat-vector-mvt/src/main/java/org/wowtools/giscat/vector/mvt/MvtBuilder.java b/giscat-vector/giscat-vector-mvt/src/main/java/org/wowtools/giscat/vector/mvt/MvtBuilder.java index a97162a..3233582 100644 --- a/giscat-vector/giscat-vector-mvt/src/main/java/org/wowtools/giscat/vector/mvt/MvtBuilder.java +++ b/giscat-vector/giscat-vector-mvt/src/main/java/org/wowtools/giscat/vector/mvt/MvtBuilder.java @@ -69,8 +69,7 @@ public MvtBuilder(int z, int x, int y, GeometryFactory geometryFactory) { public MvtBuilder(int z, int x, int y, int extent, int clipBuffer, GeometryFactory geometryFactory) { this.extent = extent; bbox = createTileBbox(z, x, y, extent, clipBuffer); - Geometry clipGeometry = createTileEnvelope(); - tileClip = new TileClip(clipGeometry, geometryFactory); + tileClip = new TileClip(bbox.xmin, bbox.ymin, bbox.xmax, bbox.ymax, geometryFactory); mvtCoordinateConvertor = new MvtCoordinateConvertor(z, x, y); @@ -131,18 +130,6 @@ private static Bbox createTileBbox(int z, int tileX, int tileY, int extent, int return new Bbox(x0, y1, x1, y0); } - private Geometry createTileEnvelope() { - - Coordinate[] coords = new Coordinate[]{ - new Coordinate(bbox.xmin, bbox.ymin), - new Coordinate(bbox.xmax, bbox.ymin), - new Coordinate(bbox.xmax, bbox.ymax), - new Coordinate(bbox.xmin, bbox.ymax), - new Coordinate(bbox.xmin, bbox.ymin) - }; - return new GeometryFactory().createPolygon(coords); - } - public Bbox getBbox() { return bbox; diff --git a/giscat-vector/giscat-vector-util/src/main/java/org/wowtools/giscat/util/analyse/TileClip.java b/giscat-vector/giscat-vector-util/src/main/java/org/wowtools/giscat/util/analyse/TileClip.java index d40ced6..82ab7bc 100644 --- a/giscat-vector/giscat-vector-util/src/main/java/org/wowtools/giscat/util/analyse/TileClip.java +++ b/giscat-vector/giscat-vector-util/src/main/java/org/wowtools/giscat/util/analyse/TileClip.java @@ -41,17 +41,20 @@ public class TileClip { private final double ymin; private final double xmax; private final double ymax; - - public TileClip(Geometry clipGeometry, GeometryFactory gf) { + public TileClip(double xmin, double ymin, double xmax, double ymax, GeometryFactory gf) { this.gf = gf; - this.clipGeometry = clipGeometry; - Coordinate[] coords = clipGeometry.getEnvelope().getCoordinates(); - Coordinate low = coords[0]; - Coordinate up = coords[2]; - xmin = low.x; - ymin = low.y; - xmax = up.x; - ymax = up.y; + this.xmin = xmin; + this.ymin = ymin; + this.xmax = xmax; + this.ymax = ymax; + Coordinate[] coords = new Coordinate[]{ + new Coordinate(xmin, ymin), + new Coordinate(xmax, ymin), + new Coordinate(xmax, ymax), + new Coordinate(xmin, ymax), + new Coordinate(xmin, ymin) + }; + clipGeometry = gf.createPolygon(coords); } /** diff --git a/giscat-vector/giscat-vector-util/src/test/java/org/wowtools/giscat/util/analyse/TileClipJmhTest.java b/giscat-vector/giscat-vector-util/src/test/java/org/wowtools/giscat/util/analyse/TileClipJmhTest.java index a93a67f..ef784dd 100644 --- a/giscat-vector/giscat-vector-util/src/test/java/org/wowtools/giscat/util/analyse/TileClipJmhTest.java +++ b/giscat-vector/giscat-vector-util/src/test/java/org/wowtools/giscat/util/analyse/TileClipJmhTest.java @@ -37,7 +37,7 @@ public class TileClipJmhTest { new Coordinate(0.2, 0.8), new Coordinate(0.2, 0.2) }); - tileClip = new TileClip(clipGeometry, geometryFactory); + tileClip = new TileClip(0.2, 0.2, 0.8, 0.8, geometryFactory); Random random = new Random(233); int n = 100; lines = new LineString[n]; diff --git a/giscat-vector/giscat-vector-util/src/test/java/org/wowtools/giscat/util/analyse/TileClipTest.java b/giscat-vector/giscat-vector-util/src/test/java/org/wowtools/giscat/util/analyse/TileClipTest.java index c5099b3..3a5069f 100644 --- a/giscat-vector/giscat-vector-util/src/test/java/org/wowtools/giscat/util/analyse/TileClipTest.java +++ b/giscat-vector/giscat-vector-util/src/test/java/org/wowtools/giscat/util/analyse/TileClipTest.java @@ -19,7 +19,7 @@ public void test() throws ParseException { new Coordinate(20, 80), new Coordinate(20, 20) }); - TileClip tileClip = new TileClip(clipGeometry, geometryFactory); + TileClip tileClip = new TileClip(20, 20, 80, 80, geometryFactory); testGeo(clipGeometry, tileClip, (LineString) new WKTReader().read("LINESTRING (37 51, 5 17, 21 34)") );