mask area outside a shapefile

6 ビュー (過去 30 日間)
Sourangsu Chowdhury
Sourangsu Chowdhury 2018 年 10 月 1 日
編集済み: Vijay Sagar 2023 年 3 月 24 日

I am trying to mask data (lon,lat,data) outside a shape file, 'shp1'. I used top use arcgis for masking data but would prefer matlab for these actions.

the code below is non responsive

dx=d(:,:,1); %%%%d is a 80x80 data
lat=(0:0.5:39.5)'; %%%%lat of the data
lon=(60:0.5:99.5); %%%%lon of the data
% lony=lony';
laty=repmat(lat,1,80);
lony=repmat(lon,80,1); %%%%80x80 lon of the data
laty=flipud(laty);  %%%%80x80 lat of the data
%%%read shapefile
  shp1=shaperead('C:\shpfiles\IND_adm0.shp');
  lon1 = [shp1.X]';
  lat1 = [shp1.Y]';
  %%%mask try
  rx = shp1.X(1:end-1);
  ry = shp1.Y(1:end-1);
  mask=inpolygon(lon1,lat1,rx,ry);
  contourf(lon1,lat1,dx);
  1 件のコメント
Vijay Sagar
Vijay Sagar 2023 年 3 月 24 日
編集済み: Vijay Sagar 2023 年 3 月 24 日
Your code is correct. Just replace in the last line lon1 and lat1 with lony and laty respectevely. Or you can use insidepoly or maskregion function.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeAuthor Block Masks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by