# [ncl-talk] ncl and shape

Kreienkamp Frank Frank.Kreienkamp at dwd.de
Thu Nov 27 00:32:31 MST 2014

```Hello,

the solution provided by Mary looks very interesting. Thanks a lot for your effort Mary. Now I have to start to understand what happens, to learn to find similar solutions. My first question looks to be solved completely.

Jagan TNAU is correct with the statement that there is still a solution missing for my second question. I am not sure if it is possible to reverse one certain shape function. To fill not the region inside the shape but to fill the region outside the shape. Unfortunately this has to be applied for the coloured pixel points after creating the map and not with the original data used the create the map. What means that, is there a way to manipulate the created pixel values in the map? Is there a matrix of colour information (wtype at wkWidth x wtype at wkHeight) ? Our the values it self before transferring those values to colour information? Can this matrix be manipulated?

Frank

Von: ncl-talk-bounces at ucar.edu [mailto:ncl-talk-bounces at ucar.edu] Im Auftrag von Mary Haley
Gesendet: Mittwoch, 26. November 2014 17:46
An: Kreienkamp Frank
Cc: ncl-talk at ucar.edu
Betreff: Re: [ncl-talk] ncl and shape

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<mailto: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.

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/20141127/64e1ab7e/attachment.html
```