[ncl-talk] Problem masking lat-lon points from a csv file using a shapefile

Mary Haley haley at ucar.edu
Tue Oct 9 16:06:33 MDT 2018


Lyndz,

I'm going through some old emails and didn't see a response to this one.

You were almost there, but in order to mask lat/lon values against one or
more shapefile outlines, you must provide a data array that has the lat/lon
arrays attached to it.

Since you don't have a data array associated with your lat/lon pairs, you
can simply create a dummy array, and then attach the lat/lon to it.  For
example:
    data1d=asciiread("jma.csv",-1,"float")
    shp_filename="Bicol_region.shp"
    print_shapefile_info(shp_filename)
    lat = data1d(0::2)
    lon = data1d(1::2)

;---Create dummy data array so we can attach lat/lon attributes to it.

    npts = dimsizes(lat)
    data = new(npts,float)
    data at lat1d = lat
    data at lon1d = lon

;---Return a mask array (0s and 1s) indicating which lat/lon pairs fall
inside the shapefile region
    opt = True
    opt at return_mask = True
    data_mask = shapefile_mask_data(data,shp_filename,opt)

I've attached a full script that creates a plot and draws all the lat/lon
pairs in red, with the ones inside the shapefile regions (only two of them)
in blue.

--Mary




On Thu, Sep 13, 2018 at 1:51 AM, Lyndz <olagueralyndonmark429 at gmail.com>
wrote:

> Hello,
>
> I am trying to filter Tropical Cyclone (TC) lat-lon points from a csv file
> using a shapefile and display the tracks.
>
> I'm reading the csv file and shapefile like this:
>
>     data=asciiread("jma.csv",(/1519,2/),"float")
>     load "./shapefile_utils.ncl"
>     shp_filename="Bicol_region.shp"
>     data_mask    = shapefile_mask_data(data,shp_filename,True)
>
> Error: shapefile_mask_data: Error: not a valid rectilinear, curvilinear,
> or uns
> tructured grid
>
> I think I am missing a step after reading the csv file. Attached are the
> shapefile and csv file.
>
> Any suggestions on how to do this correctly in NCL?
>
> Sincerely,
>
> Lyndz
>
> _______________________________________________
> 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/20181009/36471bab/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mask_data.ncl
Type: application/octet-stream
Size: 2917 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20181009/36471bab/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Bicol_region.png
Type: image/png
Size: 115942 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20181009/36471bab/attachment.png>


More information about the ncl-talk mailing list