How to create a map mask using coordinates
古いコメントを表示
Hello,
I have data (temperature) and their coordinates associated. I have two vectors with latitude and longitude defining an area, let say it's a square for easiness (in fact I have thousands of coordinates) having the coordinates :
latX = [10.7; 10.7; 20.2; 20.2];
lonX = [-15.3; -5.1; -5.1; -15.3];
And X represents some data I have access to for the whole area.
My coordinates have the from :
lat_t = 0:1:30;
lon_t = -20:1:0;
[lon,lat]=meshgrid(lon_t,lat_t);
Then I apply the poly2mask to return a logical value of 1 for points inside the square:
bw = poly2mask(latX,lonX,size(lat,1),size(lat,2));
It doesn't work because I have negative coordinates, so it can not use the indexs. What could the solution be ? Is there a poly2mask method dedicated to coordinates ?
採用された回答
その他の回答 (1 件)
Sean de Wolski
2021 年 8 月 6 日
0 投票
What is your end goal?
You need to project lat and lon into cartesian coordinates. From there, you can use poly2mask. The resulting mask will still be in projected coordinates. You can then inverse-project it back to lat/lon.
Look at projfwd, projinv - you'll need to find an appropriate projection based on your goal (equal area, etc.)
4 件のコメント
Sean de Wolski
2021 年 8 月 9 日
編集済み: Sean de Wolski
2021 年 8 月 9 日
it's important because latitude and longitude are on the surface of a sphere, not on a flat cartesian coordinate system. Thus 1 latitude does not equal one longtitude and 1 latitude does not even equal 1 latitude if it's somewhere else. Thus you need to "flatten" it so that you can use cartesian things like poly2mask which assumes that pixels are square (a lat/lon cell is not square!)
MaHa
2021 年 8 月 10 日
Sean de Wolski
2021 年 8 月 10 日
編集済み: Sean de Wolski
2021 年 8 月 10 日
The projection relies on where on the earth you are and the size of the area. For example, if working with Massachusetts data (MathWorks' headquarters location) I'd use the Massachusetts State Plane projection which is optimized for MA. Find it by web search literally: massachusetts state plane projection code - Bing
prj = projcrs(26986)
For Alaska, there are a bunch of them, so you'll have to pick one: Spatial Reference List -- Spatial Reference. Search as necessary for wherever in the world you are!
projcrs(3474)
カテゴリ
ヘルプ センター および File Exchange で Coordinate Reference Systems についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!