Re: shapefile over contour

From: ugo merlini <ugomerlini_at_nyahnyahspammersnyahnyah>
Date: Tue Sep 13 2011 - 05:22:16 MDT

Try to use this code

;----------------------------------------------------------------------
; This example shows how to read geographic data
; from Natural Earth shapefiles
; and plot them as polylines and polygons.
;----------------------------------------------------------------------
; This particular example plots data for Switzerland.
;----------------------------------------------------------------------
; Download the shapefiles from http://www.naturalearthdata.com/
; Unzip to a directory
;----------------------------------------------------------------------

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/csm/contributed.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"

begin

;*****************************************
; Open workstation and define colormap *
;*****************************************

  wks_type = "png" ; use "newpdf" instead of "pdf" for smaller files
  wks_type@wkWidth = 1200
  wks_type@wkHeight = 1200
  wks = gsn_open_wks(wks_type,"temp")
  gsn_define_colormap(wks,"rainbow+white+gray") ; choose colormap

;*****************
; Generare map *
;*****************
;--- resouces for map
  res = True ; plot mods desired
  res@mpProjection = "LambertConformal" ; choose projection
  
  res = True ; plot mods desired
 
  res@gsnMaximize = True
  res@gsnDraw = False ; do not draw the plot
  res@gsnFrame = False ; do not flip the page
  
  res@mpProjection = "LambertConformal" ; choose projection
  res@mpLimitMode = "LatLon"
  res@mpMaxLonF = 47.0
  res@mpMaxLatF = 88.5
  res@mpMinLatF = 27.0
  res@mpMinLonF = -43.0
  res@mpGridAndLimbOn = True ; turn on grid lines
  res@mpGridLineDashPattern = 10 ; lat/lon lines dashed
  
  
  drawNDCGrid(wks)
 
  map = gsn_csm_map(wks,res)

;--- create map from shapefiles

  fnames = "/mnt/internetserver/map/shapefile/europa/aaa_full/" + (/"europa"/) + ".shp" ; Files to be open
  linecolors = (/"Black"/) ; color definition for each shapefile
  fillcolors = (/"Transparent"/) ; Fill color definition for each shapefile
  thicks = (/2/) ; Thickness for each shapefile
  lnres = True ; resources for polylines
  plres = True
  prims = True
  lines = True
  do n=0,dimsizes(fnames)-1 ; Loop through files that we want to read geographic information from.
   f = addfile(fnames(n),"r") ; Open the shapefile number n.
   segments = f->segments ; Read data off the shapefile
   geometry = f->geometry
   segsDims = dimsizes(segments)
   geomDims = dimsizes(geometry)
   geom_segIndex = f@geom_segIndex ; Read global attributes
   geom_numSegs = f@geom_numSegs
   segs_xyzIndex = f@segs_xyzIndex
   segs_numPnts = f@segs_numPnts
   geometry_type = f@geometry_type
   numFeatures = geomDims(0)
   lon = f->x
   lat = f->y
   if (geometry_type.eq."polygon") then ; Put if statement outside the loop
      plres@gsFillColor = fillcolors(n)
      plres@gsEdgesOn = True ; Draw border around polygons
      plres@gsEdgeColor = linecolors(n)
      plres@gsEdgeThicknessF = thicks(n)
      do i=0, numFeatures-1 ; Section to draw polygons on map.
        startSegment = geometry(i, geom_segIndex)
        numSegments = geometry(i, geom_numSegs)
        do seg=startSegment, startSegment+numSegments-1
          startPT = segments(seg, segs_xyzIndex)
          endPT = startPT + segments(seg, segs_numPnts) - 1
          dumstr = unique_string("lines") ; This call adds the polygon.
          map@$dumstr$ = gsn_add_polygon(wks, map , lon(startPT:endPT), lat(startPT:endPT), plres)
        end do
      end do
   else
      lnres@gsLineThicknessF = thicks(n)
      lnres@gsLineColor = linecolors(n)
      do i=0, numFeatures-1 ; Section to draw polylines on map.
        startSegment = geometry(i, geom_segIndex)
        numSegments = geometry(i, geom_numSegs)
        do seg=startSegment, startSegment+numSegments-1
          startPT = segments(seg, segs_xyzIndex)
          endPT = startPT + segments(seg, segs_numPnts) - 1
          dumstr = unique_string("primitive") ; This call adds the line segment.
          map@$dumstr$ = gsn_add_polyline(wks, map, lon(startPT:endPT), lat(startPT:endPT), lnres)
        end do
      end do
   end if
   delete(lat) ; Clean up before we read in same variables again.
   delete(lon)
   delete(segments)
   delete(geometry)
   delete(segsDims)
   delete(geomDims)
  end do

;******************
; read gfs data *
;******************

  url = "http://nomad1.ncep.noaa.gov:9090/dods/gfs_master/gfs" + systemfunc("date +%Y%m%d") + "/"
  systemdate = systemfunc("date +%H")
  
  if ((systemdate.ge.06).and.(systemdate.lt.12)) then
    filename = url + "gfs_master_00z"
  end if
  if ((systemdate.ge.12).and.(systemdate.lt.18)) then
    filename = url + "gfs_master_06z"
  end if
  if ((systemdate.ge.18).and.(systemdate.lt.24)) then
    filename = url + "gfs_master_06z"
  end if
  if ((systemdate.ge.24).and.(systemdate.lt.06)) then
    filename = url + "gfs_master_18z"
  end if
  
  exists = isfilepresent(filename)
  if(.not.exists) then
    print("OPeNDAP isfilepresent test unsuccessful.")
    print("Either file doesn't exist, or NCL does not have OPeNDAP capabilities on this system")
  else
    print("OPeNDAP isfilepresent test successful.")
    gfs = addfile(filename,"r")
    vars = getfilevarnames(gfs)
  end if
 
;*******************************
; 2 metres temperature plot *
;*******************************
;--- resouces for 2 metres temperature plot
  res1= True
 
  res1@gsnMaximize = True
  res1@gsnDraw = False ; do not draw the plot
  res1@gsnFrame = False ; do not flip the page
  res1@gsnAddCyclic = True
  res1@gsnSpreadColors = False ; turn off the use entire color map
  res1@gsnContourNegLineDashPattern = 10
  

  
 
  
    
  res1@cnLineDashSegLenF = 0.04
 
  res1@cnLinesOn = True ; turn on contour lines
  res1@cnLineLabelsOn = True ; turn on contour labels
  res1@cnLineLabelFont = "times-roman" ; set font on contour labels
  res1@cnLineLabelFontHeightF = 0.006 ; set font height on contour labels
  res1@cnLineLabelPlacementMode = "Constant" ; set placement mode of labels on contour
  res1@cnLineLabelBackgroundColor = "Transparent" ; set background color of the contour label
  
  res1@cnLevelSelectionMode = "ManualLevels" ; set how manage contour line levels
  res1@cnMinLevelValF = -50 ; max level do draw contour lines
  res1@cnMaxLevelValF = 50 ; min level do draw contour lines

......

 plot = gsn_csm_contour(wks,TEMP2M(it,:,:),res1)
    overlay(map,plot)

draw(map)
    frame(wks)

Ugo

Date: Mon, 12 Sep 2011 23:30:14 -0500
From: lfmontanar@unal.edu.co
To: ncl-talk@ucar.edu
Subject: shapefile over contour

Hi, I'm plotting a shapefile over contour data, but the shapefile does not fit the contour map.
How can I fit the shapefile and how can I remove the line from the edge of the plot?
 
The script and the output are attached.
 
Any suggestions will be appreciated.
 
Best wishes,
 
Fernando
 

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Tue Sep 13 05:22:30 2011

This archive was generated by hypermail 2.1.8 : Fri Sep 16 2011 - 11:24:25 MDT