visgl / deck.gl

WebGL2 powered visualization framework
https://deck.gl
MIT License
12.05k stars 2.08k forks source link

Polygon Layer documentation - coordinate specification #2435

Closed SymbolixAU closed 5 years ago

SymbolixAU commented 5 years ago

Background

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

quadmesh

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

Update

The same works for pathLayer too, where you can specify the elevation in the coordinates [ ] array


To Do List

Pessimistress commented 5 years ago

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.

SymbolixAU commented 5 years ago

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.

mdsumner commented 5 years ago

@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?

SymbolixAU commented 5 years ago

@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

Non-extruded

Just using the Z attribute on the data

mapdeck() %>%
    add_polygon(
        data = sf
        , fill_colour = "id"
    )

polygon_non_extruded

Extruded

uses getElevation to extrude the polygon from the map

mapdeck() %>%
    add_polygon(
        data = sf
        , elevation = 100000
        , fill_colour = "id"
    )

polygon_extruded

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)

mdsumner commented 5 years ago

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

Pessimistress commented 5 years ago

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?

SymbolixAU commented 5 years ago

@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)

mdsumner commented 5 years ago

No problem!

Pessimistress commented 5 years ago

Docs updated http://deck.gl/#/documentation/deckgl-api-reference/layers/polygon-layer