Re: extraction of data using shapefile

From: Rick Brownrigg <brownrig_at_nyahnyahspammersnyahnyah>
Date: Fri Jul 22 2011 - 09:57:23 MDT

Hi Debasish,

Yes, the function attach_shapefile_polyline illustrates the correct way to *draw* from a shapefile. A polygon shapefile is composed of 1 or more "features", which in turn are composed of 1 or more "segments" (i.e., polygons). If you open the IND_adm0.shp shapefile and print the filevar, you'll see that that file contains 1 feature that has 755 segments.

The shapefile variable "segments" is a 2D array of [755,2], where segments[N,0] is a pointer into the x/y arrays of the Nth segment, and segments[N,1] contains the number of points in the x/y arrays that belong to that segment. If you do print(filevar->segments(:,1)), you'll see that the first segment has vastly more points than any other; clearly its the continental boundary.

So...long story short, to draw the shapefile, islands and all, model the code from attach_shapefile_polyline. To do the in/out tests with just the continental boundary, set your mrb_lon/lat arrays as:

 mrb_lon = f->x(f->segments(0,0) : f->segments(0,1)-1)
 mrb_lat = f->y(f->segments(0,0) : f->segments(0,1)-1)
 
and pass those off to the gc_inout function.

I hope that helps; please let me know otherwise.

RIck

On Jul 22, 2011, at 9:31 AM, Debasish wrote:

> Dear Mary,
>
> Thanks for your response. I am just wondering how same shapefile give expected outline of India for example "shapefiles_8.ncl" (http://www.ncl.ucar.edu/Applications/Scripts/shapefiles_8.ncl). Is the function "attach_shapefile_polyline" make the difference in plot.
>
> Thanks again
>
> Debasish
>
>
>
>
> On 2011-07-22, at 11:11, Mary Haley wrote:
>
>> Hi Debasish,
>>
>> One thing I mentioned to Rick is maybe you need to find a different shapefile. I dont' know if the one you are using has just the outline of India. I did a brief google search for such a thing, but kept getting a pointer to the same one that you already have.
>>
>> I think Rick has a good idea of a solution, so I'll leave it to him for now.
>>
>> --Mary
>>
>> On Jul 22, 2011, at 8:56 AM, Debasish wrote:
>>
>>> Dear Rick,
>>>
>>> Thanks for your response. you are right that I want only continental boundary of India and extract the values for India and mask out the surroundings (China, Pakistan, Bangladesh etc.). How do I solve this problem
>>>
>>> Thanks again
>>>
>>> Debasish
>>>
>>>
>>>
>>> On 2011-07-21, at 18:29, Rick Brownrigg wrote:
>>>
>>>> Hi Debasish,
>>>>
>>>> I see the issue. You are doing the following assignment:
>>>> ...
>>>> f = addfile("IND_adm0.shp", "r")
>>>> mrb_lon = f->x
>>>> mrb_lat = f->y
>>>> ...
>>>>
>>>> and then treating mrb_lon/mrb_lat as though it was a single polygon boundary, when in actuality, the f->x/f->y arrays contain multiple polygons that are the various islands, as well as the continental boundary. That is confounding the in/out tests, and also producing the extraneous lines.
>>>>
>>>> For gc_inout tests, I suspect you want only the continental boundary. If that is the case, I'll try to provide some examples of how to do that, and how to draw the boundaries.
>>>>
>>>> Rick
>>>>
>>>>
>>>>
>>>> On Jul 21, 2011, at 3:32 PM, Debasish wrote:
>>>>
>>>>> Dear Rick,
>>>>>
>>>>> Please find the attached script. Actually I used the example "shapefiles_4.ncl" and shapefile "IND_adm0.shp". Same shapefile is used to run script "shapefiles_8.ncl" and somehow it did not have any problem with boundaries for the Andaman and Nicobar islands. Mary is also looking into this problem.
>>>>>
>>>>> Thanks
>>>>>
>>>>> Debasish
>>>>>
>>>>> <test_APH.ncl>
>>>>>
>>>>>
>>>>> On 2011-07-21, at 16:26, <brownrig@ucar.edu> wrote:
>>>>>
>>>>>> Hi Debasish,
>>>>>>
>>>>>> It looks like that shapefile includes the boundaries for the Andaman and Nicobar islands, and those are getting mixed in with the continental boundary. I'm uncertain as to why this is the case, or how to avoid it, but if you post or send me your script, I'll take a look. As an aside, one trick I often use is to select the polygon from the shapefile that has the largest area, and use only it for drawing and/or masking.
>>>>>>
>>>>>> Rick
>>>>>>
>>>>>> On Thu, 21 Jul 2011 14:34:09 -0400
>>>>>> Debasish <debasish@sca.uqam.ca> wrote:
>>>>>>> Dear NCL Users,
>>>>>>> I am trying to extract data for india using example "shapefiles_4.ncl" (http://www.ncl.ucar.edu/Applications/Scripts/shapefiles_4.ncl). I used the shape file IND_adm0.shp (also used in example "shapefiles_8.ncl"; http://www.ncl.ucar.edu/Applications/Scripts/shapefiles_8.ncl). Unfortunately I am not getting right (expected) results. There is some extra lines in the plots that causes the problem. I realized that this line come from the shapefile of country boundaries. How do I get rid of this extra lines. My plot is attached with this email. Any suggestions in this regard will be appreciated Thanks Debasish
>>>>>
>>>>
>>>
>
Received on Fri Jul 22 09:57:28 2011

This archive was generated by hypermail 2.1.8 : Fri Jul 29 2011 - 08:44:18 MDT