Skip to content

Adds support for Mapzen terrain - #6024

Closed
ibesora wants to merge 18 commits into
mapbox:masterfrom
ibesora:mapzen-terrain
Closed

ibesora wants to merge 18 commits into
mapbox:masterfrom
ibesora:mapzen-terrain

Conversation

@ibesora

@ibesora ibesora commented Jan 19, 2018

Copy link
Copy Markdown
Contributor

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

Comment thread src/style-spec/reference/v8.json Outdated
"values": {
"raster-dem": {
"doc": "A raster DEM source using Mapbox Terrain RGB"
"doc": "A raster DEM source"

Copy link
Copy Markdown
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
Copy Markdown
Contributor 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

@mollymerp mollymerp left a comment •

Copy link
Copy Markdown
Contributor

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)

Comment thread src/data/dem_data.js Outdated
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
Copy Markdown
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

Comment thread src/style-spec/reference/v8.json Outdated
"doc": "Contains an attribution to be displayed when the map is shown to a user."
},
"encoding": {
"type": "string",

Copy link
Copy Markdown
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.

Comment thread src/source/raster_dem_tile_source.js Outdated
this.type = 'raster-dem';
this.maxzoom = 22;
this._options = util.extend({}, options);
this.encoding = "mapbox";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

options.encoding || "mapbox";

Comment thread src/data/dem_data.js Outdated
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
Copy Markdown
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

ibesora commented Jan 23, 2018

Copy link
Copy Markdown
Contributor Author

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

@mollymerp mollymerp left a comment

Copy link
Copy Markdown
Contributor

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!

Comment thread src/source/raster_dem_tile_source.js Outdated


class RasterDEMTileSource extends RasterTileSource implements Source {
encoding: string;

Copy link
Copy Markdown
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";

Comment thread src/data/dem_data.js Outdated
this.loaded = true;
}

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

Copy link
Copy Markdown
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]);
  }
}

Comment thread src/source/worker_source.js Outdated
coord: { z: number, x: number, y: number, w: number },
rawImageData: RGBAImage
rawImageData: RGBAImage,
encoding: string

Copy link
Copy Markdown
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)

Comment thread src/style-spec/reference/v8.json Outdated
"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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@ibesora

ibesora commented Jan 29, 2018

Copy link
Copy Markdown
Contributor Author

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

@mollymerp mollymerp left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread src/data/dem_data.js Outdated
}

loadFromImage(data: RGBAImage) {
loadFromImage(data: RGBAImage, encoding: ?string) {

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread src/data/dem_data.js Outdated
this.loaded = true;
}

unpackMapbox(r: number, g: number, b: number) {

Copy link
Copy Markdown
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
Copy Markdown
Contributor 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
Copy Markdown
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
Copy Markdown
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