MATLAB Answers

How to plot a shapefile on top of digital elevation model using mapshow (or other)

104 views (last 30 days)
Hi,
I have read in a digital elevation model(dem) using;
[dem, Rdem] = arcgridread('pathtodem');
I have read in a polyline type shapefile:
streams = shaperead('pathtoshapefile');
Now I want to plot the shapefile on top of the dem.
mapshow(dem,Rdem,'DisplayType','surface'); hold on;
mapshow(streams)
All I get is the dem. The streams layer does not display.
The stream layer on it's own displays fine
mapshow(streams)
Any help elucidating how to plot shapefiles on top of raster data would be greatly appreciated. I know that it has something to do with plotting a 2d shapefile on top of a 3d matrix but so far I can't figure this out on my own. Thank you very much!

  0 Comments

Sign in to comment.

Accepted Answer

Rob Comer
Rob Comer on 16 Sep 2014
If you only wish to view your map in 2-D, you can plot the terrain raster in the z == 0 plane, like this:
mapshow(zeros(size(dem)),Rdem,'CData',dem,'DisplayType','surface')
(Type help mapshow and see Example 8 for something similar.) Alternatively, you could increase the ZData of your lines, which is zero by default.

  2 Comments

Matthew Cooper
Matthew Cooper on 16 Sep 2014
Rob - Thank you! That worked. Funny, I thought I explored all the examples in the help document but the answer was right there in #8. Thanks again.
Matt
Anna Paulson
Anna Paulson on 9 Jul 2019
Hi Rob,
I'm about to open a support ticket, but thought I'd try this first. What if I want to look at the shapes with their elevation information intact or on a 3D plot? Here's some of the code I'm trying to use...
[Z, R] = arcgridread('/Users/user/Downloads/USGS_NED_13_n41w106_GridFloat/usgs_ned_13_n41w106_gridfloat.flt')
Z = demcmap(Z) %recolors the map to fit DEM coloring standards
%trim it down
[Z_trimmed, R_trimmed] = maptrims(Z,R,[40.07 40.08],[-105.16 -105.15])
demcmap(Z_trimmed)
...
figure
geoshow(Z_trimmed, R_trimmed, 'DisplayType', 'surface')
hold on
geoshow(Xmarker, 'DisplayType', 'Point','Marker','x','MarkerEdgeColor','magenta', 'MarkerSize', 10)
Ideally, I'd like to plot some markers (like the Xmarker), covariance/error ellipses, and KML tracks on a USGS-sourced map or terrain file. I thought the ARCGrid file type would be best for looking at markers in elevation, but that file type isn't a strict requirement, i.e. if you have another type in mind or if I need to convert to a geotiff, let me know.
Like the user above mentioned, if I try to use the code as posted above, I can see the terrain markers under the map/surface. I'd like to see them as they sit on the terrain.
Thanks!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!