[ncl-talk] How can I mask regions ousider of the interest area using a .shp file

Leo Niu leo2018niu at gmail.com
Wed Mar 7 06:11:18 MST 2018


Thanks a lot. I got the right drawing. leo2018niu 邮箱:leo2018niu at gmail.com 签名由 网易邮箱大师 定制 在2018年03月07日 03:11,Mary Haley 写道: Hi Leo, When people want to mask their data, there are usually two ways this is done. I will describe a third way below. [1] One way is to use a shapefile outline and the shapefile_mask_data function, which checks the lat/lon locations of your data array against the outline in a shapefile, and sets your data array values to missing if the locations falls outside the shapefile outline.  You can then plot your data as usual without having to set any mpXXX masking resources (like mpAreaMaskingOn), because you've already done the work of masking your data. The one issue with this method is that when you plot it, you may get some blockiness near the inside edges of the shapefile outline, because your data's lat/lon points may not lie very close to the border of the outline. You can see an example of that in these images: http://www.ncl.ucar.edu/Applications/Images/shapefiles_11_lg.png http://www.ncl.ucar.edu/Applications/Images/shapefiles_16_lg.png [2] The second way, which you mentioned, is set mpAreaMaskingOn to True, and then set mpFillAreaSpecifiers and mpMaskAreaSpecifiers to the desired areas that you want to fill or mask. This method does NOT work with shapefile outlines. It only works with NCL's internal map databases. But, it does result in smooth contouring at the boundaries: http://www.ncl.ucar.edu/Applications/Images/mask_4_lg.png [3] The third way is if you want to use the shapefile outline for masking, but you don't like the blockiness that you're getting with the shapefile_mask_data function. You draw the contours as usual, and then fill in the areas you don't want to see by using a function that draws polygons by name, given a shapefile and the name of the shapefile that contains the areas you want to fill.   For example, let's say you didn't want to see contours over New Mexico or Colorado. You can use the USA_adm1.shp shapefile, which contains all the outlines for the US States in a variable called "NAME_1", and then pass this information to a function (that is part of the shapefiles_21.ncl example):   shp_fname = ​"USA_adm1.shp"   shp_name  = "NAME_1"   shp_areas = (/ "Colorado","New Mexico, ​"/)  opt = True   opt at polytype    = "polygon"   opt at gsFillColor = "gray" ​  ​add_shapefile_primitives_by_name(wks,plot, ​shp_f​name,shp_vname,shp_areas,popt) shapefiles_21.ncl and the images can be seen here: http://www.ncl.ucar.edu/Applications/shapefiles.shtml#ex21 The third frame is the one you want to look at. --Mary ​ On Mon, Mar 5, 2018 at 7:16 PM, Guido Cioni <guidocioni at gmail.com> wrote: Remember to include ncl-talk in all replies. I believe you can do that easily with the examples that I suggested to you. When you have masked the data using the example you can already plot it and it will look like that, provided that you turn off the normal map outline with mpOutlineOn=False. If you want the outline you just need to plot the shapefile with the desired region using one of the common  functions.  Il 6 mar 2018 12:21 PM, "Leo Niu" <leo2018niu at gmail.com> ha scritto: Thanks for all your response. I have a polygon shapefile of the blue area.And I want to mask outside of this area. Just the blue area is remained.I know the maps sources, like @mpAreaMaskongOn、@mpAreaNames etc. But I don’t want to use Ncarg4_0 database,even seting @mpDataBaseVersion to be “HighRes” . because boundaries in the database can’t match it in my shapefile. Polylines and polygons in my shapefile are more detailed. Finally, I’m willing to get a plot like this: Is that clear? 2018-03-05 21:12 GMT+08:00 Guido Cioni <guidocioni at gmail.com>: It looks to me that example 11 in this page https://www.ncl.ucar.edu/Applications/shapefiles.shtml does exactly what you want to do, specifically read a shapefile, select an area to mask, save the mask to a netcdf file and then use this variable to mask the original data (i advise you to create the netcdf at first otherwise it will take so much to use the shapefile every time). Otherwise you have to explain better what you want to do ;-) Il 5 mar 2018 11:22 PM, "Leo Niu" <leo2018niu at gmail.com> ha scritto: I'm ploting a contour of an area. But boundries of the interest area in Ncarg4_0 database can't match with my shapefile. I have searched for ploting an area and masking outside using a polyline or polygon shapefile on www.ncl.ucar.edu.But I haven't found a method dealing with this. Is there some ways that can help in ploting contour of an area only inside of a geocoded polygon? Thanks a lot. leo2018niu 邮箱:leo2018niu at gmail.com 签名由 网易邮箱大师 定制 _______________________________________________ ncl-talk mailing list ncl-talk at ucar.edu List instructions, subscriber options, unsubscribe: http://mailman.ucar.edu/mailman/listinfo/ncl-talk _______________________________________________ ncl-talk mailing list ncl-talk at ucar.edu List instructions, subscriber options, unsubscribe: http://mailman.ucar.edu/mailman/listinfo/ncl-talk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180307/783880ff/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 12561 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180307/783880ff/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 12231 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180307/783880ff/attachment-0001.png>


More information about the ncl-talk mailing list