1. 提取站点
1. %读取省界shp文件
region=shaperead('E:\全国各省矢量图\anhui.shp');
plot(region.X,region.Y);hold on;grid on;
2. % %判断
sx=[113 115];
sy=[26 29];
hbs=inpolygon(sx,sy,region.X,region.Y);
输入需要判断的经纬度,返回逻辑变量。
3. %%找出范围内的点,并重新对数据赋值
index_anhui=find(hbs==1);
Data_anhui=data(P,:);
2. 提取格点
做排放源敏感性实验时有关闭一个省排放源的需求
利用shp文件,对nc文件中经纬度进行判断,提取出位于研究区域内的格点数
example:提取湖南省和湖北省的格点输出至变量d01_del和d02_del
clear;clc;
% read hubei shp
region_1=shaperead('I:\两湖地区\domian\全国各省矢量图(全)\hubei.shp');
plot(region_1.X,region_1.Y,'Color','black','LineWidth',2);hold on; %画出行政边界看看
datadir1='I:\两湖地区\地形图测试\'; %指定批量数据所在的文件夹
filelist1=dir([datadir1,'wrfchemi_00z_d01']); %指定批量数据的类型
filename1=[datadir1,filelist1.name];
ncid1=netcdf.open(filename1,'NC_NOWRITE'); %打开nc文件
filename2=[datadir1,filelist2.name];
ncid2=netcdf.open(filename2,'NC_NOWRITE');
lat_d01=ncread(filename1,'XLAT'); %读入变量lat
lon_d01=ncread(filename1,'XLONG'); %读入变量lon
lat_d02=ncread(filename2,'XLAT'); %读入变量lat
lon_d02=ncread(filename2,'XLONG'); %读入变量lon
netcdf.close(ncid1); %关闭nc文件
netcdf.close(ncid2);
hbs_1=inpolygon(lon_d01(:,:,1),lat_d01(:,:,1),region_1.X,region_1.Y);%判断经纬度是否在范围内返回逻辑型
hbs_2=inpolygon(lon_d01(:,:,1),lat_d01(:,:,1),region_2.X,region_2.Y);
m=1;
[mlon mlat]=size(hbs_1);
for ilon=1:mlon
for ilat=1:mlat
if hbs_1(ilon,ilat)|hbs_2(ilon,ilat)
d01_del(m,1)=ilon;
d01_del(m,2)=ilat;
m=m+1;
end
end
end
hbs_1=inpolygon(lon_d02(:,:,1),lat_d02(:,:,1),region_1.X,region_1.Y);
hbs_2=inpolygon(lon_d02(:,:,1),lat_d02(:,:,1),region_2.X,region_2.Y);
m=1;
[mlon mlat]=size(hbs_1);
for ilon=1:mlon
for ilat=1:mlat
if hbs_1(ilon,ilat)|hbs_2(ilon,ilat)
d02_del(m,1)=ilon;
d02_del(m,2)=ilat;
m=m+1;
end
end
end