How to plot a fit surface above a map?
3 views (last 30 days)
Show older comments

I have made a surface fit of data incorporating latitude, longitude, and altitude, using the "curve fitting" option under the Apps tab. I'd like to show the surface thus created over a map of the earth at the same location, instead of over the blank grid shown in the picture above. I'm running version R2019a.
EDITED: Now including the software version in the question, since answering the "software version" drop-down in the "ask a question" form does not populate that info for viewers of the question. Mathworks, are you listening?
1 Comment
Jack
on 12 Mar 2024
In version R2019a, the code that does the plotting should work the exact same. You might just need to change the way the data is read in and formatted prior to calling "surfm".
What is your overall workflow at the moment and what would you like more help on?
Answers (1)
Jack
on 12 Mar 2024
surfm seems to be what you are looking for. In particular, the Display Surface in 3-D example shows how you can plot a slice of Earth's terrain that is read from a Digital Terrain Elevation Data Level 1 file. You can use a similar method if you would like to use terrain that you load in from a data file. If you follow this, you can then plot the terrain surface using "surfm" and then plot the surface fit on the same figure by also using the "surfm" command.
The code might look something like this:
%% From the example
% Read in data file
[Z,R] = readgeoraster("n39_w106_3arc_v2.dt1","OutputType","double");
[Z,R] = geocrop(Z,R,[39.5 39.7],[-105.9 -105.7]);
[lat,lon] = geographicGrid(R);
% Crop the area of the terrain we want to visualize
[latlim,lonlim] = geoquadline(lat,lon);
usamap(latlim,lonlim)
surfm(lat,lon,Z,Z)
demcmap(Z)
%% New: Plotting a different surface on the same axes
% Create and plot a surface on the same axes
hold on
surfLat = linspace(39.5, 39.7, 100);
surfLon = linspace(-105.9, -105.7, 100);
[surfX, surfY] = meshgrid(surfLat, surfLon);
surfHeight = reshape(linspace(5000, 7000, 100*100), 100, 100);
surfm(surfX, surfY, surfHeight, surfHeight);
hold off
% View the region in 3-D
view(3)
If you do not have a data file and would still like to be able to go from latitude and longitude coordinates to terrain height, there are some utilities for that which are available on File Exchange. Similarly, if you would like a different colormap for the terrain vs. the other surface that you draw, then there are File Exchange submissions that can help with that as well.
0 Comments
See Also
Categories
Find more on Data Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!