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

Adds support for Mapzen terrain #6024

Closed
wants to merge 18 commits into from
Closed

Adds support for Mapzen terrain #6024

wants to merge 18 commits into from

Conversation

ibesora
Copy link

@ibesora ibesora commented Jan 19, 2018

Launch Checklist

  • briefly describe the changes in this PR
    Implements Support additional encoding formulas for RasterDEM sources #5824 and adds support for the Mapzen terrarium terrain format by adding a new encoding parameter to the raster-dem source type that selects which unpack function should be used.
    Also adds a new debug map that shows this new terrain format.
  • write tests for all new functionality
  • document any changes to public APIs
    Adds a new parameter called encoding to the raster-dem source type. Defaults to mapbox to use the mapbox terrain encoding
  • post benchmark scores
  • manually test the debug page
    Works as expected

@@ -231,7 +231,7 @@
"type": "enum",
"values": {
"raster-dem": {
"doc": "A raster DEM source using Mapbox Terrain RGB"
"doc": "A raster DEM source"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should still leave in the Terrain RGB part as it's still limited to sources of that type. For example it can't handle single band 16bit GeoTIFF tiles which are raster DEMs.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected it in the new commit.
I also expanded the declaration of the encoding parameter to explicitly tell the supported values

Copy link
Contributor

@mollymerp mollymerp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @ibesora for the contribution! We definitely want to support other encoding schemes for our raster-dem type. We have not yet discussed as a team how customizable we want our raster-dem encoding to be but this is a step in the right direction!

Due to the recent Mapzen shutdown, I think we should link to the AWS documentation and maybe call the encoding type "terrarium" since that's the only format of theirs we support: https://aws.amazon.com/public-datasets/terrain/

Also, I don't think we need a separate debug page for this – maybe you could add a toggle on the existing hillshade.html page to use the mapzen tiles instead (and remove your mapzen key and probably use the AWS endpoint)

level.set(x, y, this.scale * ((pixels[j] * 256 * 256 + pixels[j + 1] * 256.0 + pixels[j + 2]) / 10.0 - 10000.0));
}
}
this.unpackData(level, data, encoding);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs to be data.data

@@ -272,6 +272,10 @@
"type": "string",
"doc": "Contains an attribution to be displayed when the map is shown to a user."
},
"encoding": {
"type": "string",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be "type": "enum" with a values object listing the possible types.

constructor(id: string, options: RasterDEMSourceSpecification, dispatcher: Dispatcher, eventedParent: Evented) {
super(id, options, dispatcher, eventedParent);
this.type = 'raster-dem';
this.maxzoom = 22;
this._options = util.extend({}, options);
this.encoding = "mapbox";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

options.encoding || "mapbox";

for (let x = 0; x < level.dim; x++) {
const i = y * level.dim + x;
const j = i * 4;
// decoding per https://mapzen.com/documentation/terrain-tiles/formats/#types-of-terrain-tiles
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

link to AWS docs

@ibesora
Copy link
Author

ibesora commented Jan 23, 2018

Hi @mollymerp .
When looking at your fixes I saw that I had not pushed my last commit that corrected some of the things you told me :'(
I've pushed my changes, added the AWS endpoint, changed the encoding type to an enum and added a toggle to the debug page

Copy link
Contributor

@mollymerp mollymerp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the updates @ibesora – made a couple more small comments!

@@ -15,11 +15,14 @@ import type {Callback} from '../types/callback';


class RasterDEMTileSource extends RasterTileSource implements Source {
encoding: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can explicitly type this as encoding: "mapbox" | "terrarium";

@@ -95,6 +87,40 @@ class DEMData {
this.loaded = true;
}

unpackData(level: Level, pixels: Uint8Array | Uint8ClampedArray, encoding: string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to reduce code duplication, you could refactor to something like

unpackMapbox(x, y, r, g, b) {
  level.set(x, y, this.scale * ((r * 256 * 256 +g * 256.0 + b) / 10.0 - 10000.0));
}
unpackTerrarium(x, y, r, g, b) {
  level.set(x, y, this.scale * ((r * 256 + g+ b / 256) - 32768.0));
}
const unpackFunctions = {"mapbox": unpackMapbox, "terrarium": unpackTerrarium};
const unpack = unpackFunctions[encoding];
 for (let y = 0; y < level.dim; y++) {
   for (let x = 0; x < level.dim; x++) {
      const i = y * level.dim + 
      const j = i * 4;
      unpack(x, y, pixels[j], pixels[j+1], pixels[j+2]);
  }
}

@@ -28,7 +28,8 @@ export type WorkerTileParameters = TileParameters & {

export type WorkerDEMTileParameters = TileParameters & {
coord: { z: number, x: number, y: number, w: number },
rawImageData: RGBAImage
rawImageData: RGBAImage,
encoding: string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explicitly type for enum values (as above)

"doc": "Terrarium format PNG tiles. See https://aws.amazon.com/es/public-datasets/terrain/ for more info."
},
"mapbox": {
"doc": "Mapbox Terrain RGB tiles. See https://www.mapbox.com/blog/terrain-rgb/ for more info."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just found out we have official documentation for this now, so we can link to https://www.mapbox.com/help/access-elevation-data/#mapbox-terrain-rgb

@ibesora
Copy link
Author

ibesora commented Jan 29, 2018

Hi again @mollymerp I've just pushed some changes that incorporate your comments.

Copy link
Contributor

@mollymerp mollymerp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of small nits that I missed earlier, but I think this is almost ready to merge!
Sorry about the delay in following up.

@@ -57,22 +57,14 @@ class DEMData {
this.loaded = !!data;
}

loadFromImage(data: RGBAImage) {
loadFromImage(data: RGBAImage, encoding: ?string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this typing can also be "mapbox | "terrarium" – sorry I missed it earlier!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -95,6 +87,26 @@ class DEMData {
this.loaded = true;
}

unpackMapbox(r: number, g: number, b: number) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can use _unpack* for these functions to signify that they're private to the DEMData class

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@mollymerp
Copy link
Contributor

@ibesora thanks for your patience and great work here! to save you the trouble I have rebased and fixed conflicts and added some tests. I had to push to a new branch so I've made a PR for that, but I think this is good to go overall! 👉 #6110

@mollymerp
Copy link
Contributor

closing here in favor of #6110

@mollymerp mollymerp closed this Feb 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants