<div dir="ltr"><div dir="ltr">Hi David,<div><br></div><div>Yes, I found a loop was the only way to do this. Thank you for clearing that up. Why can't ncl_convert2nc work for this purpose?</div><div><br></div><div>"<span style="font-family:verdana,sans-serif;font-size:13.3333px"><font color="#0b5394">ncl_convert2nc converts one or more GRIB1, GRIB2, HDF 4, HDF-EOS 2, HDF-EOS 5, netCDF, and/or shapefile files to netCDF formatted files</font></span><span style="color:rgb(0,0,0);font-family:verdana,sans-serif;font-size:13.3333px">"</span> </div><div><br></div><div><br></div><div> shp_file_name = "tresh_ease23.shp"<br> shape_var_name = "tresh"<br><br>;========================================================<br>; Region 1<br>;========================================================<br><br> areas_of_interest = 1<br><br> print("areas_of_interest = "+ areas_of_interest)<br><br> opt = True<br> opt@debug = True<br> opt@return_mask = True<br> opt@minlat = minlat<br> opt@maxlat = maxlat<br> opt@shape_var = shape_var_name<br> opt@shape_names = areas_of_interest<br><br> temp_mask = shapefile_mask_data(t2flip,shp_file_name,opt)<br> copy_VarMeta(t2flip,temp_mask)<br> printVarSummary(temp_mask)<br><br> tresh_mask = temp_mask<br><br> delete(temp_mask)<br><br><br>;========================================================<br>; Region 2 - 25<br>;========================================================<br><br><br> do k = 2, 25<br> areas_of_interest = k<br><br> print("area of interest = "+k)<br><br> opt = True<br> opt@debug = True<br> opt@return_mask = True<br> opt@minlat = minlat<br> opt@maxlat = maxlat<br> opt@shape_var = shape_var_name<br> opt@shape_names = areas_of_interest<br><br> temp_mask = shapefile_mask_data(t2flip,shp_file_name,opt)<br><br> do i=1, 721<br> do j=1, 1440<br> if(temp_mask(i-1,j-1).eq.1)<br> temp_mask(i-1,j-1) = areas_of_interest<br> tresh_mask(i-1,j-1) = (/temp_mask(i-1,j-1)/)<br> end if<br> end do<br> end do<br> <br><br> delete(temp_mask)<br><br> end do<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Nov 27, 2019 at 12:07 AM Hiep Duc <<a href="mailto:Hiep.Duc@environment.nsw.gov.au">Hiep.Duc@environment.nsw.gov.au</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div lang="EN-AU">
<div class="gmail-m_1916183973643206922WordSection1">
<p class="MsoNormal">Hi all,<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Is it possible to convert from netcdf file back to shapefile ?.
<u></u><u></u></p>
<p class="MsoNormal">Or is this transformation one way only ?
<u></u><u></u></p>
<p class="MsoNormal">Thanks<u></u><u></u></p>
<p class="MsoNormal">Hiep<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><b><span lang="EN-US">From:</span></b><span lang="EN-US"> ncl-talk <<a href="mailto:ncl-talk-bounces@ucar.edu" target="_blank">ncl-talk-bounces@ucar.edu</a>>
<b>On Behalf Of </b>Dave Allured - NOAA Affiliate via ncl-talk<br>
<b>Sent:</b> Wednesday, 27 November 2019 6:27 PM<br>
<b>To:</b> Amy Hendricks <<a href="mailto:ashendricks@alaska.edu" target="_blank">ashendricks@alaska.edu</a>><br>
<b>Cc:</b> <a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a><br>
<b>Subject:</b> Re: [ncl-talk] converting shapefile to netcdf<u></u><u></u></span></p>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">Correction, the name of this example is shapefiles_14_mask, not just shapefiles_14.<u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">On Tue, Nov 26, 2019 at 8:57 PM Dave Allured - NOAA Affiliate <<a href="mailto:dave.allured@noaa.gov" target="_blank">dave.allured@noaa.gov</a>> wrote:<u></u><u></u></p>
</div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0cm 0cm 0cm 6pt;margin-left:4.8pt;margin-right:0cm">
<div>
<div>
<p class="MsoNormal">Example shapefiles_14 is close to what you want. Please notice these two lines. Their function is to select a particular subset of all the state outlines in the example shapefile, then apply a binary mask to the base grid "tc_lev0" so
that only grid points over the listed states are retained. All grid points outside this list of states are set to missing. This demonstrates how to access a subset of a shape file, instead of all regions together,<br>
<br>
opt@shape_names = (/"Texas","New Mexico","Colorado","Kansas","Oklahoma"/)<br>
tc_mask = shapefile_mask_data(tc_lev0,shp_filename1,opt)<br>
<br>
For your application, use this masking function to select one region at a time. Start with a master grid with ERA5 coordinates, set to all zero or missing values. Loop over each region value or region number. Call the function shapefile_mask_data inside
the loop, selecting the grid points for only one region each time. U<span style="font-family:Arial,sans-serif">se the resulting binary mask to add the current region number to the master grid. When the loop is complete, write the master grid with all region
numbers to a Netcdf file.</span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">On Tue, Nov 26, 2019 at 3:51 PM Amy Hendricks via ncl-talk <<a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a>> wrote:<u></u><u></u></p>
</div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0cm 0cm 0cm 6pt;margin-left:4.8pt;margin-right:0cm">
<div>
<p class="MsoNormal">Hello NCL geniuses,<u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">I am trying to write a shapefile to netcdf. The shapefile consists of circumpolar Treshnikov regions, and I would like to create a netCDF file that has the region values like tresh(lon,lat) = [region# from shapefile] on the ERA5 grid. All
the examples I'm finding are for creating binary masks, and the ncl_convert2nc does not seem to work, at least it doesn't return anything useable. <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Attached are the ERA5 netCDF file, Treshnikov shapefile, as well as the result of ncl_convert2nc. <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Thank you in advance,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Amy<u></u><u></u></p>
</div>
</div>
</blockquote>
</div>
</div>
</blockquote>
</div>
</div>
</div>
<p>----------------------------------------------------------------------------------------------------------------------------------------------------------------------<br>This email is intended for the addressee(s) named and may contain confidential and/or privileged information. <br>If you are not the intended recipient, please notify the sender and then delete it immediately.<br>Any views expressed in this email are those of the individual sender except where the sender expressly and with authority states them to be the views of the NSW Office of Environment and Heritage.</p>
<p>PLEASE CONSIDER THE ENVIRONMENT BEFORE PRINTING THIS EMAIL</p></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>Amy Hendricks</div>Graduate Research Assistant<div><div>Department of Atmospheric Sciences<br><div>University of Alaska Fairbanks</div><div>IARC 343-E</div><div>907-388-9893</div><div><a href="mailto:ashendricks@alaska.edu" target="_blank">ashendricks@alaska.edu</a></div></div></div></div></div></div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Nov 26, 2019 at 10:26 PM Dave Allured - NOAA Affiliate <<a href="mailto:dave.allured@noaa.gov">dave.allured@noaa.gov</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">Correction, the name of this example is shapefiles_14_mask, not just shapefiles_14.<div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Nov 26, 2019 at 8:57 PM Dave Allured - NOAA Affiliate <<a href="mailto:dave.allured@noaa.gov" target="_blank">dave.allured@noaa.gov</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Example shapefiles_14 is close to what you want. Please notice these two lines. Their function is to select a particular subset of all the state outlines in the example shapefile, then apply a binary mask to the base grid "tc_lev0" so that only grid points over the listed states are retained. All grid points outside this list of states are set to missing. This demonstrates how to access a subset of a shape file, instead of all regions together,<br><br> opt@shape_names = (/"Texas","New Mexico","Colorado","Kansas","Oklahoma"/)<br> tc_mask = shapefile_mask_data(tc_lev0,shp_filename1,opt)<br><br>For your application, use this masking function to select one region at a time. Start with a master grid with ERA5 coordinates, set to all zero or missing values. Loop over each region value or region number. Call the function shapefile_mask_data inside the loop, selecting the grid points for only one region each time. U<span style="font-family:arial,sans-serif">se the resulting binary mask to add the current region number to the master grid. When the loop is complete, write the master grid with all region numbers to a Netcdf file.</span></div><div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Nov 26, 2019 at 3:51 PM Amy Hendricks via ncl-talk <<a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hello NCL geniuses,<div><br></div><div>I am trying to write a shapefile to netcdf. The shapefile consists of circumpolar Treshnikov regions, and I would like to create a netCDF file that has the region values like tresh(lon,lat) = [region# from shapefile] on the ERA5 grid. All the examples I'm finding are for creating binary masks, and the ncl_convert2nc does not seem to work, at least it doesn't return anything useable. </div><div><br></div><div>Attached are the ERA5 netCDF file, Treshnikov shapefile, as well as the result of ncl_convert2nc. </div><div><br></div><div>Thank you in advance,</div><div><br></div><div>Amy<br></div></div></blockquote></div></div>
</blockquote></div></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>Amy Hendricks</div>Graduate Research Assistant<div><div>Department of Atmospheric Sciences<br><div>University of Alaska Fairbanks</div><div>IARC 343-E</div><div>907-388-9893</div><div><a href="mailto:ashendricks@alaska.edu" target="_blank">ashendricks@alaska.edu</a></div></div></div></div></div></div></div></div></div>