[ncl-talk] Visualizing shapefiles with multiple polygons

Adam Sisco aws0006 at uah.edu
Thu May 30 06:57:29 MDT 2019


Hi Rick,

Thank you so much for taking a look at the underlying code for me. I really
appreciate it. I also understand the constraints that the pivot to Python
might place on resolving this bug. For anyone else who might be seeking a
quick open source solution for a "shapefile island" visualization, Spatial
Features for R (https://github.com/r-spatial/sf) is able to properly
display the interior feature (see attached figure). R script below:

****************************************************
library(sf)
library(ggplot2)

test <- st_read("***PATH TO SHAPEFILE***/test_shapefile.shp")
ggplot() + geom_sf(data = test, fill = "lightgreen")
****************************************************

Best,
Adam


On Wed, May 29, 2019 at 10:47 PM Rick Brownrigg <brownrig at ucar.edu> wrote:

> Hi Adam,
>
> Firstly, much thanks for providing the concise, nicely illustrated example
> of the problem!
>
> After looking through the code, I can believe this is a bug, and
> unfortunately, not one easily fixed. The underlying code properly knows how
> to decode shapefile "features" that are comprised of multiple "segments" or
> closed loops. But in drawing, it treats each sub-polygon independently.
> This works well, for example, for a coastal nation with a mainland and many
> islands, but it does not work for the case you provided, one with an outer
> hull containing interior islands/regions. Alas, the code that
> gsn_add_shapefile_polygons() is based upon does not provide interface to
> specify multiple nested interior loops. We can file this as a github issue,
> but with our current prioritization, I can't promise a timely fix.
>
> I wish I had a better response...
>
> Rick
>
>
> On Wed, May 29, 2019 at 11:15 AM Adam Sisco <aws0006 at uah.edu> wrote:
>
>> Hello NCL users,
>>
>> I have a question regarding the visualization of shapefiles using NCL.
>> For the sake of this help request, I have constructed a sample shapefile
>> with a simplified geometry to illustrate the issue I am having. The
>> shapefile contains a polygon within the opening of larger polygon, but I'm
>> not sure NCL's gsn_add_shapefile_polygons function is capturing the
>> polygon-within-polygon nature of this shapefile. So that my issue can be
>> reproduced, I have attached:
>>
>>    1. The sample shapefile I am attempting to plot
>>    2. The desired visualization of the shapefile
>>    3. The visualization that results from the gsn_add_shapefile_polygons
>>    function
>>    4. The NCL script used to plot the shapefile
>>
>> I suspect that a more nuanced approach may be needed to produce the
>> proper visualization. If this is within the capabilities of NCL, I would
>> appreciate any assistance you can offer. I am using NCL 6.4.0 on a Windows
>> machine.
>>
>> ********************
>> begin
>>   wks  = gsn_open_wks("x11","shapefile_testing")
>>
>>   res = True
>>   res at gsnDraw = False
>>   res at gsnFrame = False
>>   res at gsnMaximize = True
>>
>>   res at mpMinLonF = -110
>>   res at mpMaxLonF = -75
>>   res at mpMinLatF = 25
>>   res at mpMaxLatF = 55
>>
>>   plot = gsn_csm_map(wks,res)
>>
>>   polyRes = True
>>   polyRes at gsEdgesOn = True
>>
>>   poly = gsn_add_shapefile_polygons(wks,plot,"***PATH TO
>> SHAPEFILE***/test_shapefile.shp",polyRes)
>>
>>   draw(plot)
>>   frame(wks)
>> end
>> ********************
>>
>> Regards,
>>
>> *Adam Sisco*
>> Research Associate
>> NASA MSFC IMPACT
>> University of Alabama in Huntsville
>>
>> _______________________________________________
>> 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/20190530/a56b1104/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_shapefile.png
Type: image/png
Size: 5421 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190530/a56b1104/attachment.png>


More information about the ncl-talk mailing list