Skip to content

Commit

Permalink
TileClip构造方法输入改为bbox
Browse files Browse the repository at this point in the history
  • Loading branch information
codingmiao committed Jul 29, 2022
1 parent 6d05c1a commit 3dee8c5
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);


Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
);
Expand Down

0 comments on commit 3dee8c5

Please sign in to comment.