Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tiling: shrink tile (top,right) #1127

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ public void testReadingFeatureByHereTileId() {
accept(APPLICATION_GEO_JSON).
headers(getAuthHeaders(AuthProfile.ACCESS_OWNER_1_ADMIN)).
when().
get(getSpacesPath() + "/x-psql-test/tile/here/5148795631.geojson").
get(getSpacesPath() + "/x-psql-test/tile/here/5148795642.geojson").
then().
statusCode(OK.code()).
body("features.size()", equalTo(1)).
Expand All @@ -453,12 +453,13 @@ public void testReadingFeatureByHereTileIdFalse() {
accept(APPLICATION_GEO_JSON).
headers(getAuthHeaders(AuthProfile.ACCESS_OWNER_1_ADMIN)).
when().
get(getSpacesPath() + "/x-psql-test/tile/here/5148795642.geojson").
get(getSpacesPath() + "/x-psql-test/tile/here/5148795631.geojson").
then().
statusCode(OK.code()).
body("features.size()", equalTo(1)).
body("features[0].id", equalTo("Q2390739")).
body("features[0].properties.name", equalTo("John F. Kennedy Stadium"));
body("features.size()", equalTo(0));
// .body("features.size()", equalTo(1))
// .body("features[0].id", equalTo("Q2390739")).
// .body("features[0].properties.name", equalTo("John F. Kennedy Stadium"));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public void testGetTileWithVersion() {
given()
.headers(getAuthHeaders(AuthProfile.ACCESS_ALL))
.when()
.get(getSpacesPath() + "/" + SPACE_ID + "/tile/quadkey/03333?version=1")
.get(getSpacesPath() + "/" + SPACE_ID + "/tile/quadkey/12222?version=1")
.then()
.statusCode(OK.code())
.body("features.size()", equalTo(1))
Expand All @@ -130,7 +130,7 @@ public void testGetTileWithVersion() {
given()
.headers(getAuthHeaders(AuthProfile.ACCESS_ALL))
.when()
.get(getSpacesPath() + "/" + SPACE_ID + "/tile/quadkey/03333?version=2")
.get(getSpacesPath() + "/" + SPACE_ID + "/tile/quadkey/12222?version=2")
.then()
.statusCode(OK.code())
.body("features.size()", equalTo(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ private void validate() {
throw new IllegalArgumentException("Quadkey '"+quadkey+"' is invalid!");
}


public BBox getBoundingBox() {
private BBox _getBoundingBox() {
double width = 360.0 / (1L << level);
double heigth = level == 0 ? 180 : 360.0 / (1L << level);

Expand All @@ -108,6 +107,10 @@ public BBox getBoundingBox() {
return new BBox(west, south, east, north);
}

public BBox getBoundingBox() {
return BBox.tile_shrink( _getBoundingBox() );
}


@Override
public String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ public BBox getBBox(boolean clone) {
double minLat = 90.0 - 360.0 * Math.atan(Math.exp(-y1 * 2.0 * Math.PI)) / Math.PI;
double maxLon = 360.0 * x1;

bbox = new BBox(minLon, minLat, maxLon, maxLat);
bbox = BBox.tile_shrink( new BBox(minLon, minLat, maxLon, maxLat) );
}
if (clone) {
return new BBox(bbox.minLon(), bbox.minLat(), bbox.maxLon(), bbox.maxLat());
Expand Down Expand Up @@ -551,7 +551,7 @@ public BBox getExtendedBBox(int buffer) {
double maxLon = 360.0 * x1;

eBuffer = buffer;
eBbox = new BBox(minLon, minLat, maxLon, maxLat);
eBbox = BBox.tile_shrink(new BBox(minLon, minLat, maxLon, maxLat) );
return eBbox;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,14 @@ public double heightInDegree() {
// Must not be, but lets fix it anyway:
return (min + 90d) - (max + 90d);
}

public static BBox tile_shrink(BBox bbox)
{ double delta = 0.000000001f;
return new BBox( bbox.getWest(),
bbox.getSouth(),
bbox.getEast() < 180.0 ? bbox.getEast() - delta : bbox.getEast(),
bbox.getNorth() < 90.0 ? bbox.getNorth() - delta : bbox.getNorth()
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import static org.junit.Assert.assertEquals;

public class HQuadTest {
BBox bbox = new BBox().withEast(13.38134765625).withNorth(52.53662109375).withWest(13.359375).withSouth(52.5146484375);
BBox bbox = BBox.tile_shrink( new BBox().withEast(13.38134765625).withNorth(52.53662109375).withWest(13.359375).withSouth(52.5146484375) );
String base4QK = "12201203120220";
String base10QK = "377894440";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,14 @@ public SQLQuery buildQuadbinClusteringQuery(GetFeaturesByBBoxEvent event)
boolean isTileRequest = (event instanceof GetFeaturesByTileEvent) && ((GetFeaturesByTileEvent) event).getMargin() == 0,
clippedOnBbox = (!isTileRequest && event.getClip());

final WebMercatorTile tile = getTileFromBbox(bbox);
final WebMercatorTile tile;

if( isTileRequest )
{ GetFeaturesByTileEvent tevnt = (GetFeaturesByTileEvent) event;
tile = WebMercatorTile.forWeb(tevnt.getLevel(),tevnt.getX(),tevnt.getY());
}
else
tile = getTileFromBbox(bbox);

if( (absResolution - tile.level) >= 0 ) // case of valid absResolution convert it to a relative resolution and add both resolutions
relResolution = Math.min( relResolution + (absResolution - tile.level), 5);
Expand Down
28 changes: 26 additions & 2 deletions xyz-psql-connector/src/main/resources/xyz_ext.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2747,12 +2747,29 @@ END;
$$ LANGUAGE plpgsql IMMUTABLE;
------------------------------------------------
------------------------------------------------
CREATE OR REPLACE FUNCTION xyz_qk_lrc2bbox(rowY integer, colX integer, level integer)
CREATE OR REPLACE FUNCTION _xyz_qk_lrc2bbox(rowY integer, colX integer, level integer)
RETURNS geometry AS
$$
select st_transform(ST_TileEnvelope(level, colX, rowY), 4326)
$$
LANGUAGE sql IMMUTABLE;

create or replace function htile_shrink( tile geometry ) returns geometry
language sql immutable strict
as $$
select ST_MakeEnvelope( st_xmin( tile ), st_ymin( tile ),
case st_xmax(tile) < 180.0 when true then st_xmax(tile) - 0.000000001 else 180.0 end,
case st_ymax(tile) < 90.0 when true then st_ymax(tile) - 0.000000001 else 90.0 end,
4326)
$$;

CREATE OR REPLACE FUNCTION xyz_qk_lrc2bbox(rowY integer, colX integer, level integer)
RETURNS geometry AS
$$
select htile_shrink( _xyz_qk_lrc2bbox(rowY, colX, level) )
$$
LANGUAGE sql IMMUTABLE;

------------------------------------------------
------------------------------------------------
CREATE OR REPLACE FUNCTION xyz_qk_qk2bbox( qid text )
Expand Down Expand Up @@ -3363,7 +3380,7 @@ end
$$;
------------------------------------------------
------------------------------------------------
CREATE OR REPLACE FUNCTION htile_bbox(rowy integer, colx integer, lev integer) RETURNS public.geometry
CREATE OR REPLACE FUNCTION _htile_bbox(rowy integer, colx integer, lev integer) RETURNS geometry
LANGUAGE plpgsql IMMUTABLE STRICT
AS $$
declare
Expand All @@ -3390,6 +3407,13 @@ begin
return st_setsrid(ST_MakeEnvelope( minX, minY, maxX, maxY ),4326);
end
$$;

create or replace function htile_bbox(rowy integer, colx integer, lev integer) returns geometry
language sql immutable strict
as $$
select htile_shrink( _htile_bbox( rowy, colx, lev ) )
$$;

------------------------------------------------
------------------------------------------------
CREATE OR REPLACE FUNCTION htile_number_to_base(num bigint, base integer) RETURNS text
Expand Down
Loading