4

I can plot the elevation data by this code

entity = Entity["AdministrativeDivision", {"Berlin", "Germany"}];
latlon = Transpose[GeoBounds[entity]];
elevation = Reverse[QuantityMagnitude[GeoElevationData[latlon]]];
ListPlot3D[elevation, Boxed -> False, Mesh -> None, Axes -> False, 
 Background -> Black, BoxRatios -> {1, 1, 0.3}, Lighting -> "Neutral",
  RotationAction -> "Clip"]

But as we know, the Berlin is not a rectangle shape, it is like this:

GeoGraphics[Polygon[entity]]

I hope those elevation data inside the shape keep the origin and those elevation data outside the shape become 0. Is it possible?

yode
  • 26,686
  • 4
  • 62
  • 167

1 Answers1

3

We can do this with a bit of image processing with a mask. For example, use this function to apply a mask to a data matrix:

applyMask[data_, pol_] := ImageData@ ImageApply[0 &, Image[data], Masking -> Graphics[pol, PlotRangePadding -> None]]

It basically constructs an image with the data, then apply the mask, and finally extracts the clipped data back. Now we can insert it in your elevation call:

elevation = Reverse[applyMask[QuantityMagnitude[GeoElevationData[latlon]], entity["Polygon"]]];

and use your same ListPlot3D command:

enter image description here

jose
  • 6,328
  • 1
  • 14
  • 24