Contours on Geoaxe with addCustomBasemap

9 Ansichten (letzte 30 Tage)
Asaf Schuldenfrei
Asaf Schuldenfrei am 2 Okt. 2023
Kommentiert: Yair Dayan am 16 Mai 2024
Hi,
I Plan on using a High Resolution map data (OpenStreet & Sat Images) for a project and draw on them contours of heights or population density or other GIS information.
For the maps the best solution is using addCustomBasemap to draw the map tiles from a map server (as the data is too huge to load into a mapaxe with mapshow or other method).
But then I can't draw the contours (lines and fills & lines labels) on that map as counturem or contourfm cant be a chiled of Geoaxe.
Is there a method to do it? If not, is there a schedule to add this functionality to a later release of MATLAB?
Thanks
Asaf Schuldenfrei

Antworten (2)

Kevin Holly
Kevin Holly am 9 Okt. 2023
You can use the getContourLineCoordinates function from the File Exchange.
Create contours with contourf
[X,Y,Z] = peaks;
[M, h] = contourf(X,Y,Z,20);
Custom Basemap:
figure
ax = geoaxes;
name = 'googleSat'; url = 'https://mt1.google.com/vt/lyrs=s&x={x}&y={y}&z={z}';
addCustomBasemap(name,url)
geobasemap(ax,name)
Use getContourLineCoordinates
hold(ax,"on")
cTbl = getContourLineCoordinates(M);
nContours = max(cTbl.Group);
colors = autumn(nContours);
for i = 1:nContours
gidx = cTbl.Group == i;
geoplot(ax, cTbl.Y(gidx), cTbl.X(gidx), ... % note: x & y switched
'LineWidth', 2, 'Color', colors(i,:))
end
  1 Kommentar
Yair Dayan
Yair Dayan am 16 Mai 2024
Thanks,
In both answers you lose the smart labeling option within contour function.
How can I create labels that are visually like the ones contour function creates?

Melden Sie sich an, um zu kommentieren.


Alan Garger
Alan Garger am 24 Dez. 2023
I had a very similar issue for one of my own projects, and I utilized a similar method to the one above. But instead of just plotting the contour lines, I also included a part to plot each layer region so that I could see the filled contour plot.
[X,Y,Z] = peaks;
figure()
ax = geoaxes();
geobasemap('satellite')
hold on
contdata = contourc(X,Y,Z,25);
cTbl = getContourLineCoordinates(contdata); % from the file exchange
hold(ax,'on')
nContours = max(cTbl.Group);
%finding every unique level
ltable=cTbl.Level;
levs=unique(ltable);
gpart=[];
%for loop that splits countour data into groups and adds a NaN after every
%group, then recombines the data. NaNs are added to be able to plot shapes
%with holes
for i=1:nContours
temp=cTbl(cTbl.Group==i,[1,3,4]);
temp=temp{:,:};
temp=[temp;temp(1,1),NaN,NaN];
gpart=[gpart;temp];
end
%converts the data into a table for a comparison in the next for loop
gpart=array2table(gpart,'VariableNames',["Level","Long","Lat"]);
%creates a cell array that will be useful later
lpart=cell(length(levs),1);
%for loop that separates groups by their layer, ie, its value for the
%"Z" axis
for i=1:length(levs)
temp=gpart(gpart.Level==levs(i),:);
temp=temp{:,:};
lpart(i)=mat2cell(temp,height(temp),3);
end
%color array that will be used to color the contour. Change "autumn" to
%change color gradient
colors = autumn(length(lpart));
%for loop to actually plot the contour
for i=1:length(lpart)
%coordinates of the ith layer
shapemat1=cell2mat(lpart(i));
%coordinates of the next layer up, if statement for if there is no next
%layer
if i==length(lpart)
shapemat2=[];
else
shapemat2=cell2mat(lpart(i+1));
end
%combines this layer with the next layer
shapemat=[shapemat1;shapemat2];
%plots the shape from above. By combining the ith layer with the i+1
%layer, the ith layer get plotted and then the i+1 layer is then taken
%out. This is why I did the NaN stuff from before, to split the data up
%into something geopolyshape can recognize.
cshape=geopolyshape(shapemat(:,3),shapemat(:,2));
%actually plots the shape onto the map. alpha values are transparency
geoplot(cshape,'FaceColor',colors(i,:),'FaceAlpha',.25,'EdgeAlpha',.5)
end
geolimits([40.4,41], [-75.9,-75]);
% Add colorbar
colormap("autumn")
colorbar(ax)
This solution is likely very inefficient, but I got it to run in my own code. Note that I also use the getContourLineCoordinates function
  1 Kommentar
Yair Dayan
Yair Dayan am 16 Mai 2024
Thanks,
In both answers you lose the smart labeling option within contour function.
How can I create labels that are visually like the ones contour function creates?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Geographic Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by