Clear Filters
Clear Filters

how to make a geographic map from text files data

7 views (last 30 days)
Hi every one;
I have data in text file which has three columns , first column is latitude , second is long and third column is related to air temperature. Header is removed from the file so that it only contains the values in text file.
I have such data for every month. Like in April folder i have make three text files
  • 1-1000 % this text file contains values of temperature at given lat, long with in 1-1000m height
  • 1000-2000 % This text file contains temperature values at given lat, long with 1000-2000m height
  • 2000-3000 % ....................................................................2000-3000m.......
  • above 3000 % ...................................................................above 3000m......
I want to make a code which read this text files makes the title "0-1000 Temperature variations" , also lable x,y axises as latitude or longitude. This map shows variations in temperature with height. Color variations in maps shows by scale.
For the shake , i have mentioned below some output of my map which i want. I am also sharing with you people text file of 1-1000m. I have no idea how to make such map in matlab or any other.Please help me i shall be very thankful to you on this kind favor.

Accepted Answer

bio lim
bio lim on 13 Jul 2015
Hi, Muhammad. This is not an exact solution to your problem, but this is how you can do it. Firstly, I would create a structures that contains your data given in your text files.
For example, using your file ' 1-1000.txt ',
fid = fopen('1-1000.txt');
C = textscan(fid, '%f %f %f')
fclose(fid);
f = {'lat', 'long', 'temp'}
S = cell2struct(C,f,2);
Now I have a structure S that has three fields, .lat, .long and .temp.
Now we need two things. The first one is you need the map that is given in the back of your plots. Assuming that you have it, you can just load the map by
load(map.mat)
Then we need to change your decimal degrees (long and lat) to meters. There are many methods available, even mercator.m files available on the File Exchange. Generally, it should look something like this.
radian = degree * pi/180; % Since your S.long and S.lat are given in decimal degrees.
earth_radius = 6378.137;
lng = (x * radian - 135/180*pi) * earth_radius; %[km]
lat = atanh(sin(y)) * earth_radius; %[km]
Since you have a structures, it is better to write function mercator that your data can easily be implemented.
Finally, for the color variated map, you can use imagesc.
N = 1000;
[Xi, Yi] = meshgrid(linspace(37,42,N),linspace(-6.9,2.5,N));
Ci = griddata(A(:,2), A(:,1), A(:,3), Xi, Yi);
colormap ('hot')
imagesc(linspace(37,42,N),linspace(-6.9,2.5,N),Ci);
xlabel('Longitude');
ylabel('Latitude');
colorbar
Now, this will not instantly work. It will take quiet some time for you to search each function and implement it appropriately to your own data. The codes provided above might be confusing, but I wrote them merely to show you how they could be implemented.
  19 Comments
Muhammad Usman Saleem
Muhammad Usman Saleem on 20 Jul 2015
@Coffee thanks for your contributions. I have a link http://www.peteryu.ca/tutorials/matlab/plot_over_image_background which tell us about how to set back ground in matlab. This link use an image and use plot function to plot on the background. Please see we can use another approach to resolve the problem. Is this possible we make plot of griddata and then show this grid data on the image?? I am sharing with this comment image of the back ground which i want to set as back ground of the color map? Regards
Muhammad Usman Saleem
Muhammad Usman Saleem on 24 Jul 2015
@Coffee thanks for your contribution to this problem. Please vote up my question if you like it :)

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!