Polygon layer coordinate specification
The documentation for polygon layer specifies the following data format
/**
* Data format:
* [
* {
* // Simple polygon (array of coords)
* contour: [[-122.4, 37.7], [-122.4, 37.8], [-122.5, 37.8], [-122.5, 37.7], [-122.4, 37.7]],
* zipcode: 94107,
* population: 26599,
* area: 6.11
* },
* {
* // Complex polygon with holes (array of coords)
* contour: [
* [[-122.4, 37.7], [-122.4, 37.8], [-122.5, 37.8], [-122.5, 37.7], [-122.4, 37.7]],
* [[-122.45, 37.73], [-122.47, 37.76], [-122.47, 37.71], [-122.45, 37.73]]
* ],
* zipcode: 94107,
* population: 26599,
* area: 6.11
* },
* ...
* ]
*/
I've just generated an example which has coordinates in the form of
{
"geometry":{
"type":"Polygon",
"coordinates":[
[
[-162.96333331843185, 23.963333318432139,-94860.0,1.0],
[-162.89693422519478, 23.963333318432139,-95135.0,1.0]
... etc
]
]
}
}
Where the elevation is specified as the 3rd value in each coordinate array (as per GeoJSON).
Which gives

Should the documentation reflect that you can specify the elevation in the coordinate array, as well as in the getElevation prop?
And is this a valid way to supply the elevation?
Related issue from my mapdeck library
The same works for pathLayer too, where you can specify the elevation in the coordinates [ ] array
It is totally valid. Think of z values in the polygon array the "base" elevation and getElevation the amount of extrusion. This question has came up before and we should clarify it in the docs.
Excellent.
Think of z values in the polygon array the "base" elevation and getElevation the amount of extrusion.
This is a key point of clarification and would be useful in the docs.
@Pessimistress is extrusion then relative to each base vertex, so also tited at the top for a triangle? And a bit nonsensical for non triangle polygons, or does triangulation get applied implicitly?
@mdsumner I had the same question - hopefully this helps
Setting up some data (in R)
poly1<- matrix(c(0,0,0,0,1,1000,1,1,50000,1,0,25000,0,0,0), ncol = 3, byrow = T)
poly2<- matrix(c(0,0,0,0,-1,1000,-1,-1,50000,-1,0,25000,0,0,0), ncol = 3, byrow = T)
poly1 <- sf::st_sfc( sf::st_polygon( x = list( poly1 ) ) )
poly2 <- sf::st_sfc( sf::st_polygon( x = list( poly2 ) ) )
poly1 <- sf::st_sf( geometry = poly1 )
poly2 <- sf::st_sf( geometry = poly2 )
sf <- rbind( poly1, poly2 )
sf$id <- 1:2
The polygons have a Z attribute. I'm making two plots, one using the extrusion, and one without
Just using the Z attribute on the data
mapdeck() %>%
add_polygon(
data = sf
, fill_colour = "id"
)

uses getElevation to extrude the polygon from the map
mapdeck() %>%
add_polygon(
data = sf
, elevation = 100000
, fill_colour = "id"
)

So the Z is applied for each vertex. The extrusion is applied to the whole polygon, while respecting the initial Z elevation (as both the base and top surfaces are tilted)
Thanks! (nice!!!)
Those top-faces do look like implicitly triangulated quads to me, see how it's kind of saddle-looking? I bet there's an earcut triangulation going on, I'll try with more complex polys
This is a key point of clarification and would be useful in the docs.
@SymbolixAU May the documentation use the lovely example image in your original issue?
@Pessimistress of course it can. Would you like me to send a higher-res version, or are you happy grabbing the gif directly from the original post? And would you like the underlying data?
(@mdsumner - assuming this is OK with you as it's your example originally)
No problem!
Docs updated http://deck.gl/#/documentation/deckgl-api-reference/layers/polygon-layer
Most helpful comment
It is totally valid. Think of
zvalues in thepolygonarray the "base" elevation andgetElevationthe amount of extrusion. This question has came up before and we should clarify it in the docs.