[ncl-talk] ncl and shape
Mary Haley
haley at ucar.edu
Wed Nov 26 09:46:06 MST 2014
Frank,
I'm not sure if this is the best solution, but I modified
shapefile_mask_data to mask both on whether the grid point falls inside the
shapefile area (using gc_inout as before) *and* whether it is within a
certain kilometer distance from the shapefile border (using gc_latlon).
gc_latlon returns the great circle distance between a series of lat/lon
points, and you can use it to return the distance in meters, kilometers,
degrees, or radians. I used option 4 (kilometers).
http://www.ncl.ucar.edu/Document/Functions/Built-in/gc_latlon.shtml
See the attached example script, and try running it with different values
for "delta_kilometers".
delta_kilometers = 300
Note that this script can take awhile to run if you have a lot of data
points, or a lot of shapefile areas to check against.
It is possible to make this script much more efficient by limiting the area
that is actually checked. For example, inside the big "do n=0,natlon1d-1"
loop in the shapefile_mask_data" function, you could add a "if" check for
lat1d or lon1d being less than/greater than some min/max lat/lon box, and
then "break" out of that loop if the condition is not met. This way, you
don't get into the tedious checking with gc_inout and/or gc_latlon.
The original "shapefile_mask_data" actually does this kind of checking, so
you can look at that for more informatioin.
I've attached the modified function, and example script (based on
shapefiles_16.ncl), with PNGs showing the results with 100, 200, and 300 km.
I also attached a PNG showing the original results where you just mask
based on the shapefile area.
--Mary
On Mon, Nov 24, 2014 at 10:54 PM, Kreienkamp Frank <Frank.Kreienkamp at dwd.de>
wrote:
> Hello,
>
>
>
> i have two questions about the interaction of ncl and shape files.
>
>
>
> 1)
>
> Using ‘shapefile_mask_data’ I can mask out grid points lying inside a
> shape file. One result is shown in the attached png-file. Is it possible
> to define an extention, that I get all grid point inside and additional the
> grid point which are close ( xx km) to the shape-polygon-border?
>
>
>
> 2)
>
> I am looking for a function which cuts out and draws the complete region.
> In the shown example i have white areas based along the
> shape-polygon-border. But I want to have the complete area inside the
> shape-polygon-border colored.
>
>
>
> Thanks in advance
>
> Frank
>
>
>
> _______________________________________________
> ncl-talk mailing list
> 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/20141126/c0566db4/attachment-0001.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: shapefile_mask_data.ncl
Type: application/octet-stream
Size: 9760 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20141126/c0566db4/attachment-0002.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: shapefiles_16.ncl
Type: application/octet-stream
Size: 3885 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20141126/c0566db4/attachment-0003.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: shapefiles_300_km.png
Type: image/png
Size: 282826 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20141126/c0566db4/attachment-0004.png
-------------- next part --------------
A non-text attachment was scrubbed...
Name: shapefiles_100_km.png
Type: image/png
Size: 280939 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20141126/c0566db4/attachment-0005.png
-------------- next part --------------
A non-text attachment was scrubbed...
Name: shapefiles_200_km.png
Type: image/png
Size: 281584 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20141126/c0566db4/attachment-0006.png
-------------- next part --------------
A non-text attachment was scrubbed...
Name: shapefiles.png
Type: image/png
Size: 279645 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20141126/c0566db4/attachment-0007.png
More information about the ncl-talk
mailing list