how to make a geographic map from text files data
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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.

채택된 답변
bio lim
2015년 7월 13일
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
Muhammad Usman Saleem
2015년 7월 13일
편집: Muhammad Usman Saleem
2015년 7월 13일
@Coffee thanks for contributions. why you are converting lat , long to meters . In map i required geographic coordinates.In the above provide data these are the coordinates of Pakistan . In your load(map.mat) what is meant here??
No guideline yet??
Regarding the map, this is what it looks like if you load the map. (Basically, it is visually more pleasing for the viewer for exact location.)

I was assuming that your coordinates are in decimal degrees. If you want to apply mercator projection , I believe you need to convert your data in decimal degrees to meters.
@Coffee thanks for your contributions. I do not want to convert my coordinates in meters. I want to use them in decimal degrees. Please your code is running fine.As i have told you the coordinates in my text files are of Pakistan. Then please correct your code according to Pakistan( see my data, lat and long are available in it.)
If you are not looking for conversion, then.
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

The bright spot is 34.5 67.5 3386.3 in your text file. If you assume this point was an irregularity in your data, by excluding it, you get

Thanks @Coffee for contributions. Please take notice, geographic map is not shown below i required this to be shown below the temperature variations. Correct the code for that please
@Coffee Thanks for your kind contributions. Please set the scale of variations from start from 1000 and end till 1000 or above its. Please set the scale interval of 250 in the map. I shall be very thankful to you on this kind favor.
Muhammad,
As I mentioned first, this is a mere guideline and not an exact solution. What you have asked for is also a guideline. This whole community exists to help and guide people with their problems, and in some cases solutions depending on the volunteers. Small changes could be easily implemented by you if you take time and search for yourself with my provided code as a reference and general guideline.
As for your above question, I believe it is not possible to insert the geographic map with the information you have provided. At first, could you insert your attached figure again with better quality?
@Coffee please wait , i am sharing with you shapefile of Pakistan (my data set in text file contain lat,lon of Pakistan) now we add this shape file and makes map of temperature variations over this regions. Thanks in advance
Muhammad Usman Saleem
2015년 7월 14일
편집: Muhammad Usman Saleem
2015년 7월 14일
Shape files format is not attaching. Please share your mail id so that i can forward you shape file of my dataset. This will be better than placing an image. You can also suppose we have a shape file in the place of image and over which we show temperature variations.Thanks in advance for your kind assistance
Muhammad, right now I cannot deal with shape files format. You may upload it here as a jpg format, or in different image uploading sites and I can look over it. I also cannot guarantee you that I can help you any further provided that the problem is beyond my capabilities. However, the information I have provided here is enough for reference and you should be able to proceed from here on your own.
See the jpeg format of shape file. Below is my idea which i am going to share with you. use the following codes to read shape file(create a structure) and then display it
S = shaperead('pakistan.shp');
mapshow(S);
when you show this shape file , such map of pakistan will be open

See this image lat, lon has ready mentioned here.Please use my codes in your codes. @Coffee thanks you , for your kind assistance. I hope you learn a lot from my thread.
@Coffee i have 100% sure you can resolve this problem.Please i am going for your kind assistance.
Alright, now it makes sense that you did not wanted to convert your longitude and latitude in the first place. If you share your pakistan.shp file on file uploading websites, I can download it and look through it.
@Coffee i am sharing with you shape file of Pakistan. Download it and unzip it. Please note when i run your above mentioned code i am getting an error
C =
[0x1 double] [0x1 double] [0x1 double]
f =
'lat' 'long' 'temp'
??? Error using ==> griddata at 83
Not enough unique sample-points specified.
And also please note that in the above maps you show latitude starts from top of y-axis. I required these start from bottom of y-axis.
Some one else on this form help me please? Thanks in advance for this kind assistance.
I have tried it in several different ways, sadly with no positive results. I also lack several necessary toolboxes including the mapping toolbox. Since you have already asked in different question, I hope the other volunteers will be able to help.
P.S. S is your structure not C.
@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

@Coffee thanks for your contribution to this problem. Please vote up my question if you like it :)
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Geographic Plots에 대해 자세히 알아보기
제품
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
