[ncl-talk] Subsetting a shapefile
Rick Brownrigg
brownrig at ucar.edu
Mon Apr 6 08:59:54 MDT 2020
Hi,
Answering your second question first, NCL does not write shapefiles.
Example #2 shows using the ind() function to find the indices of a subset
of "features". I am unfamiliar with the plot_shapefile() function, but as
it only takes a filename as input, I don't see how it could be used to draw
that subset, so you would have to draw it yourself. In the case of a
point shapefile, as in Example 2, this was easy. In the case of lines or
polygons, you'll have to draw them explicitly by looping over the geometry
indices identified via the ind(). Example #1 shows such drawing.
http://ncl.ucar.edu/Applications/shapefiles.shtml
Finally, you might be able to use GDAL's "ogr2ogr" command to subset and
write a new shapefile, and plot that with NCL using plot_shapefile(). It
definitely reads/writes shapefiles, and it allows you to specify an
SQL-like "WHERE..." clause to subset your data. I've personally not used
ogr2ogr in this fashion, so it might take some experimentation.
Good luck...
Rick
On Mon, Apr 6, 2020 at 6:27 AM Lyndz via ncl-talk <ncl-talk at ucar.edu> wrote:
> Dear NCL-experts,
>
> I am plotting a shapefile based on the basic commands provided in the NCL
> webpage.
>
> ncl 1> load = "../shapefile_utils.ncl"
>
> ncl 2> sname
>
> ncl 2> sname="PHL_climatetype.shp"
>
> ncl 3> print_shapefile_info(sname)
>
> (0)
>
> (0) Filename: "PHL_climatetype.shp"
>
> (0) Geometry type: polygon
>
> (0) # of features: 4
>
> (0) Min/max lat: 4.59/ 21.12
>
> (0) Min/max lon: 116.93/ 126.61
>
> (0) Variable names and their types:
>
> (0) geometry : integer
>
> (0) segments : integer
>
> (0) x : double
>
> (0) y : double
>
> (0) Id : integer
>
> (0) Type : double
>
> (0)
>
>
>
> I want to do the following:
>
>
> [1] The "Type" in the shapefile are numbers 1 to 4.
>
> I would like to select only Type 2 and plot the result.
>
>
> My question is, is it possible to select only the Type 2 in the shapefile
> and plot it using the plot_shapefile(sname) command?
>
>
> [2] I want to save the selected shapefile in [1] as an independent
> shapefile. How can I do this in NCL?
>
>
>
> I'll appreciate any advise on this.
>
>
>
> 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/20200406/01788e42/attachment.html>
More information about the ncl-talk
mailing list