how to set background of the color map with shape file/image in hand

조회 수: 22(최근 30일)
Hi every one; I want to make color map from text file which contains three columns( 1st is latitude, 2nd is longitude, 3rd is temperature). I have accessed to this code which reading and creating color map from text file(1-1000.text)
fid = fopen('1-1000.txt');
C = textscan(fid, '%f %f %f')
fclose(fid);
f = {'lat', 'long', 'temp'}
S = cell2struct(C,f,2);
N = 1000;
[Xi, Yi] = meshgrid(linspace(60,80,N),linspace(20,40,N));
Ci = griddata(S.long, S.lat, S.temp, Xi, Yi);
colormap ('hot')
imagesc(linspace(60,80,N),linspace(20,40,N),Ci);
xlabel('Longitude');
ylabel('Latitude');
colorbar
it has output
The data in text file represent region , i have shape file of that region i want to set this region as the background of this color map. I have attached with this post text data, my requried output map and shape file of the region. Please set my code so that background of the map will become region of my shapefile. Thanks in advance for assistance. Regards
  댓글 수: 15
Muhammad Usman Saleem
Muhammad Usman Saleem 2015년 7월 24일
@Walter thanks for your contributions. Please vote up if my question was interesting :)

댓글을 달려면 로그인하십시오.

채택된 답변

Amy Haskins
Amy Haskins 2015년 7월 21일
Once you've gotten your data into a regular grid of latitudes and longitudes as you've done above, the geoshow function in the Mapping Toolbox can help with the rest.
First use geoshow to get your surface plot into a map axes. If you don't already have a map open, geoshow will create a default one. If you would perfer a different projection, take a look at the doc for axesm.
h = geoshow(Yi,Xi,Ci,'DisplayType','surface');
This creates an actual surface plot, but you're after a 2D map, so let's flatten out the ZData.
h.ZData = zeros(size(h.XData));
Your shape file contains polygons. You have a couple of options here. I think it looks nice to overlay just the edge lines, but you could play with the transparency and fill in the polygons.
p = geoshow('pakistanshapefile\PAK_adm1.shp', ...
'DisplayType','polygon','FaceColor','none','EdgeColor','w')
Or
p = geoshow('pakistanshapefile\PAK_adm1.shp',...
'DisplayType','polygon','FaceAlpha',0.25)
Alternately, you could move the polygons to the bottom using uistack(p,'bottom') and change the FaceAlpha property of the surface if you really want the shape file in the background.
  댓글 수: 4
Muhammad Usman Saleem
Muhammad Usman Saleem 2015년 7월 24일
편집: Muhammad Usman Saleem 2015년 7월 24일
@Amy Haskins thank you very much for resolving this problem :) Please vote up my question

댓글을 달려면 로그인하십시오.

추가 답변(1개)

Nitin Khola
Nitin Khola 2015년 7월 21일
As per my understanding, you wish to set the background of the given colormap to a map outline imported from a shapefile. I am assuming you have a license for the MAPPING TOOLBOX and are using MATLAB R2015a. To achieve it, as per this assumption, you can use the function "shaperead":
to import the shapefile and then overlay the given colormap on a plot of data from the shapefile. The transparency of the colormap can be changed using "alpha" command so that the outline is visible. I was able to do it using the following code:
im = shaperead('PAK_adm1.shp'); % import the shapefile
plot([im.X],[im.Y],'k','LineWidth',2.0); % plot X,Y data
hold on;
fid = fopen('1-1000.txt');
C = textscan(fid, '%f %f %f');
fclose(fid);
f = {'lat', 'long', 'temp'};
S = cell2struct(C,f,2);
N = 1000;
[Xi, Yi] = meshgrid(linspace(60,80,N),linspace(20,40,N));
Ci = griddata(S.long, S.lat, S.temp, Xi, Yi);
colormap ('hot')
imagesc(linspace(60,80,N),linspace(20,40,N),Ci);
xlabel('Longitude');
ylabel('Latitude');
colorbar
alpha(0.85) % Change transparency of the colormap so that map is visible
You might want to change some of the values in the above code as per your needs.
  댓글 수: 9

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by