Skip to content

Commit

Permalink
Was still truncating instead of rounding in projection
Browse files Browse the repository at this point in the history
  • Loading branch information
e-n-f committed Jul 27, 2023
1 parent e9f4cbd commit 644a9ce
Show file tree
Hide file tree
Showing 71 changed files with 4,503 additions and 4,465 deletions.
8 changes: 4 additions & 4 deletions projection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ void lonlat2tile(double lon, double lat, int zoom, long long *x, long long *y) {
double lat_rad = lat * M_PI / 180;
unsigned long long n = 1LL << zoom;

long long llx = n * ((lon + 180) / 360);
long long lly = n * (1 - (log(tan(lat_rad) + 1 / cos(lat_rad)) / M_PI)) / 2;
long long llx = std::round(n * ((lon + 180) / 360));
long long lly = std::round(n * (1 - (log(tan(lat_rad) + 1 / cos(lat_rad)) / M_PI)) / 2);

*x = llx;
*y = lly;
Expand All @@ -84,8 +84,8 @@ void epsg3857totile(double ix, double iy, int zoom, long long *x, long long *y)
ix = 40000000.0;
}

*x = ix * (1LL << 31) / 6378137.0 / M_PI + (1LL << 31);
*y = ((1LL << 32) - 1) - (iy * (1LL << 31) / 6378137.0 / M_PI + (1LL << 31));
*x = std::round(ix * (1LL << 31) / 6378137.0 / M_PI + (1LL << 31));
*y = std::round(((1LL << 32) - 1) - (iy * (1LL << 31) / 6378137.0 / M_PI + (1LL << 31)));

if (zoom != 0) {
*x = std::round((double) *x / (1LL << (32 - zoom)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5337,7 +5337,7 @@
,
{ "type": "FeatureCollection", "properties": { "zoom": 13, "x": 1275, "y": 7544 }, "features": [
{ "type": "FeatureCollection", "properties": { "layer": "in", "version": 2, "extent": 4096 }, "features": [
{ "type": "Feature", "properties": { "thesum": 100, "themax": 100, "themin": 100, "theproduct": 100, "themean": 100, "theconcat": 100, "thecomma": "NEWVALUE" }, "geometry": { "type": "Point", "coordinates": [ -123.948516, -81.873970 ] } }
{ "type": "Feature", "properties": { "thesum": 100, "themax": 100, "themin": 100, "theproduct": 100, "themean": 100, "theconcat": 100, "thecomma": "NEWVALUE" }, "geometry": { "type": "Point", "coordinates": [ -123.948505, -81.873970 ] } }
] }
] }
,
Expand Down Expand Up @@ -5481,7 +5481,7 @@
,
{ "type": "FeatureCollection", "properties": { "zoom": 13, "x": 4245, "y": 5238 }, "features": [
{ "type": "FeatureCollection", "properties": { "layer": "in", "version": 2, "extent": 4096 }, "features": [
{ "type": "Feature", "properties": { "thesum": 18, "themax": 18, "themin": 18, "theproduct": 18, "themean": 18, "theconcat": 18, "thecomma": "NEWVALUE" }, "geometry": { "type": "Point", "coordinates": [ 6.564438, -44.802834 ] } }
{ "type": "Feature", "properties": { "thesum": 18, "themax": 18, "themin": 18, "theproduct": 18, "themean": 18, "theconcat": 18, "thecomma": "NEWVALUE" }, "geometry": { "type": "Point", "coordinates": [ 6.564438, -44.802842 ] } }
] }
] }
,
Expand Down Expand Up @@ -5889,7 +5889,7 @@
,
{ "type": "FeatureCollection", "properties": { "zoom": 14, "x": 2550, "y": 15088 }, "features": [
{ "type": "FeatureCollection", "properties": { "layer": "in", "version": 2, "extent": 4096 }, "features": [
{ "type": "Feature", "properties": { "thesum": 100, "themax": 100, "themin": 100, "theproduct": 100, "themean": 100, "theconcat": 100, "thecomma": "NEWVALUE" }, "geometry": { "type": "Point", "coordinates": [ -123.948516, -81.873970 ] } }
{ "type": "Feature", "properties": { "thesum": 100, "themax": 100, "themin": 100, "theproduct": 100, "themean": 100, "theconcat": 100, "thecomma": "NEWVALUE" }, "geometry": { "type": "Point", "coordinates": [ -123.948510, -81.873970 ] } }
] }
] }
,
Expand Down Expand Up @@ -6045,7 +6045,7 @@
,
{ "type": "FeatureCollection", "properties": { "zoom": 14, "x": 8490, "y": 10477 }, "features": [
{ "type": "FeatureCollection", "properties": { "layer": "in", "version": 2, "extent": 4096 }, "features": [
{ "type": "Feature", "properties": { "thesum": 18, "themax": 18, "themin": 18, "theproduct": 18, "themean": 18, "theconcat": 18, "thecomma": "NEWVALUE" }, "geometry": { "type": "Point", "coordinates": [ 6.564433, -44.802834 ] } }
{ "type": "Feature", "properties": { "thesum": 18, "themax": 18, "themin": 18, "theproduct": 18, "themean": 18, "theconcat": 18, "thecomma": "NEWVALUE" }, "geometry": { "type": "Point", "coordinates": [ 6.564433, -44.802838 ] } }
] }
] }
,
Expand Down
256 changes: 128 additions & 128 deletions tests/allow-existing/both.mbtiles.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/csv/out-null.mbtiles.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{ "type": "FeatureCollection", "properties": {
"antimeridian_adjusted_bounds": "-175.220565,-41.299988,179.216647,64.150024",
"antimeridian_adjusted_bounds": "-175.220564,-41.299988,179.216647,64.150024",
"bounds": "-180.000000,-41.299988,180.000000,85.051129",
"center": "0.000000,0.000000,0",
"description": "tests/csv/out-null.mbtiles",
Expand Down
2 changes: 1 addition & 1 deletion tests/csv/out.mbtiles.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{ "type": "FeatureCollection", "properties": {
"antimeridian_adjusted_bounds": "-175.220565,-41.299988,179.216647,64.150024",
"antimeridian_adjusted_bounds": "-175.220564,-41.299988,179.216647,64.150024",
"bounds": "-180.000000,-41.299988,180.000000,85.051129",
"center": "0.000000,0.000000,0",
"description": "tests/csv/out.mbtiles",
Expand Down
4 changes: 2 additions & 2 deletions tests/epsg-3857/out/-yNAME_-z5_-sEPSG%3a3857.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ "type": "FeatureCollection", "properties": {
"antimeridian_adjusted_bounds": "-175.220565,-41.299974,179.216647,64.150024",
"bounds": "-175.220565,-41.299974,179.216647,64.150024",
"antimeridian_adjusted_bounds": "-175.220564,-41.299974,179.216647,64.150024",
"bounds": "-175.220564,-41.299974,179.216647,64.150024",
"center": "16.875000,44.951199,5",
"description": "tests/epsg-3857/out/-yNAME_-z5_-sEPSG%3a3857.json.check.mbtiles",
"format": "pbf",
Expand Down
42 changes: 21 additions & 21 deletions tests/id/out/-Z11.json

Large diffs are not rendered by default.

Loading

0 comments on commit 644a9ce

Please sign in to comment.