Creating a map using x/y data

22 次查看(过去 30 天)
Louise Wilson
Louise Wilson 2022-4-4
回答: Harshit 2023-9-15
I have X, Y, Z data where X and Y are lon and lat coordinates and Z is value of interest. All variables are 12500*1800 (too large to attach here).
I would like to plot these variables on map axes so I can add shape files with additional info., aswell as a scale bar.
clf
axesm('MapProjection','mercator') %define axis
surfm(y,x,z) % plot X/Y data
S = shaperead('study_site.shp','UseGeoCoords',true); %add shapefile on top of X/Y data
info = shapeinfo('study_site.shp');
crs = info.CoordinateReferenceSystem
geoshow(S,'FaceColor','white');
Apart from needing to adjust the axes limits, this looks good. But, I am struggling to add a scale bar. When I try to do this, the plot is just replaced with a scale bar:
hold on
scaleruler on
How do I do this properly?
Also, how do I add lat and lon information to the frame?

回答(1 个)

Harshit
Harshit 2023-9-15
Hi,
I understand that you want to plot the latitudes and longitudes onto the map axes.
For such large variables of "X", "Y", and "Z", I suggest creating a meshgrid of lon and lat coordinates first. Then, you can use the "pcolorm" function to plot the "Z" variable on the map.
Additionally, you use the "scaleruler" function to add a scale bar to the frame.
Here's an updated version of your code incorporating the above suggestions:
clf
axesm('MapProjection', 'mercator')
% Create a meshgrid of lon and lat coordinates
[lon_grid, lat_grid] = meshgrid(x, y);
% Plot the Z variable using pcolorm
pcolorm(lat_grid, lon_grid, z);
S = shaperead('study_site.shp', 'UseGeoCoords', true);
info = shapeinfo('study_site.shp');
crs = info.CoordinateReferenceSystem;
geoshow(S, 'FaceColor', 'white');
% Adjust axes limits if needed
% xlim([lon_min, lon_max]);
% ylim([lat_min, lat_max]);
% Add scale bar
scaleruler('RulerStyle', 'patches', 'Units', 'km', 'FontSize', 10);
% Add latitude and longitude information to the frame
framem on;
gridm on;
mlabel on;
plabel on;
To find more about the functions used here, kindly refer to the following documentation pages:
Hope the above information resolves your issue.
Regards,
Harshit

类别

Help CenterFile Exchange 中查找有关 Mapping Toolbox 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by