[ncl-talk] Labeling Shape File Segments Individually

Sean Egan sdegan at alaska.edu
Fri Sep 9 11:58:33 MDT 2016


Dear NCL Community,

I have a shape file containing 3 polyline segments. Each segment is a
"contour" level and these level values are stored in the CONTOUR variable.
See the description of the shape file below.

ncl 0> f = addfile("mp143-mpua5-contour.shp","r")
ncl 1> print(f)

Variable: f
Type: file
filename:    mp143-mpua5-contour
path:    mp143-mpua5-contour.shp
   file global attributes:
      layer_name : mp143-mpua5-contour
      geometry_type : polyline
      geom_segIndex : 0
      geom_numSegs : 1
      segs_xyzIndex : 0
      segs_numPnts : 1
   dimensions:
      geometry = 2
      segments = 2
      num_features = 3  // unlimited
      num_segments = 3
      num_points = 149
   variables:
      integer geometry ( num_features, geometry )

      integer segments ( num_segments, segments )

      double x ( num_points )

      double y ( num_points )

      string CONTOUR ( num_features )

When I plot these shape files, I want to label each segment with the
contour level. I am trying to do this by setting labels=f->CONTOUR and then
setting the gsLineLabelString resource equal to "labels". This, however,
labels each segment with the first entry in labels (labels(0)), instead of
each segment with each value. See the description of labels below.

ncl 5> print(labels)


Variable: labels
Type: string
Total Size: 24 bytes
            3 values
Number of Dimensions: 1
Dimensions and sizes:    [num_features | 3]
Coordinates:
Number Of Attributes: 0
(0)    1,000
(1)    10
(2)    100

So in the output, each segment is given a value of 1,000.

Is there a way that I can either 1) label each segment with the values in
labels or 2) convert the polylines to polygons and shade each a different
color?

The NCL script is below (and is attached) as well as the shape files.

Thanks again for your help!
Sean

load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"

begin

  shapefile = "mp143-mpua5-contour.shp"
  f = addfile(shapefile,"r")

  b = addfile("wrf_redoubt_domain"+".nc","r")

  wks = gsn_open_wks("x11","testing")

  lat = f->y
  lon = f->x

  gsn_define_colormap(wks,"WhBlGrYeRe")
  res                         = True
  res at gsnMaximize             = False
  res at gsnDraw                 = False        ; Turn off for now.
  res at gsnFrame                = False        ; Will draw later

  res at tiMainOn                = False

  mpres                              = res
  mpres                              = wrf_map_resources(b,mpres)
  mpres at mpOutlineBoundarySets        = "GeophysicalAndUSStates"
  mpres at mpFillOn                     = False
  mpres at mpOutlineOn                  = True
  mpres at mpCountyLineThicknessF       = 2.5
  mpres at mpGeophysicalLineThicknessF  = 2.5
  mpres at mpNationalLineThicknessF     = 2.5
  mpres at mpProvincialLineThicknessF   = 2.5
  mpres at mpUSStateLineThicknessF      = 2.5
  mpres at mpCountyLineColor            = "Black"
  mpres at mpGeophysicalLineColor       = "Black"
  mpres at mpNationalLineColor          = "Black"
  mpres at mpUSStateLineColor           = "Black"

  mpres at mpRightCornerLonF = 215.0
  mpres at mpRightCornerLatF = 64.5
  mpres at mpLeftCornerLonF  = 200.0
  mpres at mpLeftCornerLatF  = 55.5

  print(mpres)

  map = gsn_csm_map(wks, mpres)

  labels=f->CONTOUR

  pres                               = res
  pres at gsLineColor                   = "Red"
  pres at gsMarkerIndex                 = 16
  pres at gsMarkerColor                 = "Red"
  pres at gsLineLabelString             = labels

  poly = gsn_add_shapefile_polylines(wks,map,shapefile,pres)

  draw(map)
  frame(wks)

end


-- 
PO1 Sean D. Egan, US Navy
PhD Candidate
Geophysical Institute
University of Alaska Fairbanks
903 Koyukuk Drive
Fairbanks, AK 99775
sdegan at alaska.edu | 907 474-5483
IARC Office 334 | www.gi.alaska.edu/~sdegan
<http://www.gi.alaska.edu/%7Esdegan>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160909/a97c008f/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mp143-mpua5-contour.dbf
Type: application/octet-stream
Size: 99 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160909/a97c008f/attachment.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mp143-mpua5-contour.prj
Type: application/octet-stream
Size: 167 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160909/a97c008f/attachment-0001.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mp143-mpua5-contour.sbn
Type: application/octet-stream
Size: 172 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160909/a97c008f/attachment-0002.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mp143-mpua5-contour.sbx
Type: application/octet-stream
Size: 124 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160909/a97c008f/attachment-0003.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mp143-mpua5-contour.shp
Type: application/octet-stream
Size: 2652 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160909/a97c008f/attachment-0004.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mp143-mpua5-contour.shp.xml
Type: text/xml
Size: 6198 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160909/a97c008f/attachment.xml 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mp143-mpua5-contour.shx
Type: application/octet-stream
Size: 124 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160909/a97c008f/attachment-0005.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: plot_shapefile.ncl
Type: application/octet-stream
Size: 2223 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160909/a97c008f/attachment-0006.obj 


More information about the ncl-talk mailing list