Need to create a polygon shapefile from a binary mask... any functions that could help? [message #88864] |
Sun, 29 June 2014 14:49  |
ca11h
Messages: 3 Registered: June 2014
|
Junior Member |
|
|
Hey guys, I have a binary mask (just 1s and 0s) and I need to somehow extract the polygons (1s) out of there and convert them to a shapefile. Well all the documentation I've found seems to suggest that I need all the vertex data for each of the polygons I want to add, and I need to add them one by one... is there any other way to go straight from binary mask -> shapefile?
If not, is there anyway to extract the polygons from the binary mask easily?
Thank you all for the help, finding help online for IDL is painstakingly frustrating sometimes, as I'm sure you all know...
Also does anyone have any examples of creating a polygon shapefile? Documentation only has examples for a point shapefile...
|
|
|
Re: Need to create a polygon shapefile from a binary mask... any functions that could help? [message #88885 is a reply to message #88864] |
Tue, 01 July 2014 08:19   |
Russell Ryan
Messages: 122 Registered: May 2012
|
Senior Member |
|
|
Hi FSU
I've been trying to do the same thing. I don't have anything working, but this is what I planned to try...
Does the mask have multiple "masks?" Or is it just one monolithic thing? if it's just one grouping of 1s and 0s, then I think this might work... Myabe.... I haven't tried it, but this is where I was going to start.
Use the contour procedure. Set the parameters to only contour the 1s. Use the XY_PATH variable to have it return the xy values of the contour. We might need to monkey around with the settings on how contour smooths (if it does).
If you have multiple regions, then I think we to use label_regions in a clever way to go through and contour each region separately and default to the previous.
I'm going on a trip for the Fourth, but I'll be working on this problem with my laptop. If I get anywhere, I'll drop you a line here.
-Russell
On Sunday, June 29, 2014 5:49:07 PM UTC-4, ca...@my.fsu.edu wrote:
> Hey guys, I have a binary mask (just 1s and 0s) and I need to somehow extract the polygons (1s) out of there and convert them to a shapefile. Well all the documentation I've found seems to suggest that I need all the vertex data for each of the polygons I want to add, and I need to add them one by one... is there any other way to go straight from binary mask -> shapefile?
>
>
>
> If not, is there anyway to extract the polygons from the binary mask easily?
>
>
>
> Thank you all for the help, finding help online for IDL is painstakingly frustrating sometimes, as I'm sure you all know...
>
>
>
> Also does anyone have any examples of creating a polygon shapefile? Documentation only has examples for a point shapefile...
|
|
|
Re: Need to create a polygon shapefile from a binary mask... any functions that could help? [message #88886 is a reply to message #88885] |
Tue, 01 July 2014 08:31   |
Helder Marchetto
Messages: 520 Registered: November 2011
|
Senior Member |
|
|
On Tuesday, July 1, 2014 5:19:51 PM UTC+2, rr...@stsci.edu wrote:
> Hi FSU
>
>
>
> I've been trying to do the same thing. I don't have anything working, but this is what I planned to try...
>
>
>
>
>
> Does the mask have multiple "masks?" Or is it just one monolithic thing? if it's just one grouping of 1s and 0s, then I think this might work... Myabe.... I haven't tried it, but this is where I was going to start.
>
>
>
> Use the contour procedure. Set the parameters to only contour the 1s. Use the XY_PATH variable to have it return the xy values of the contour. We might need to monkey around with the settings on how contour smooths (if it does).
>
>
>
> If you have multiple regions, then I think we to use label_regions in a clever way to go through and contour each region separately and default to the previous.
>
>
>
> I'm going on a trip for the Fourth, but I'll be working on this problem with my laptop. If I get anywhere, I'll drop you a line here.
>
>
>
>
>
> -Russell
>
>
>
>
>
>
>
> On Sunday, June 29, 2014 5:49:07 PM UTC-4, ca...@my.fsu.edu wrote:
>
>> Hey guys, I have a binary mask (just 1s and 0s) and I need to somehow extract the polygons (1s) out of there and convert them to a shapefile. Well all the documentation I've found seems to suggest that I need all the vertex data for each of the polygons I want to add, and I need to add them one by one... is there any other way to go straight from binary mask -> shapefile?
>
>>
>
>>
>
>>
>
>> If not, is there anyway to extract the polygons from the binary mask easily?
>
>>
>
>>
>
>>
>
>> Thank you all for the help, finding help online for IDL is painstakingly frustrating sometimes, as I'm sure you all know...
>
>>
>
>>
>
>>
>
>> Also does anyone have any examples of creating a polygon shapefile? Documentation only has examples for a point shapefile...
Hi,
if you have a set of points (1s) and want to find the polygon that cointains them, then I think that this article from David is what you want:
https://www.idlcoyote.com/ip_tips/boundary.html
Alternatively this article might also help:
https://www.idlcoyote.com/math_tips/convexhull.html
But be careful, the second one is VERY different from the first one!
Hope it helps,
Helder
|
|
|
Re: Need to create a polygon shapefile from a binary mask... any functions that could help? [message #88887 is a reply to message #88885] |
Tue, 01 July 2014 08:31   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
rryan@stsci.edu writes:
>
> Hi FSU
>
> I've been trying to do the same thing. I don't have anything working, but this is what I planned to try...
>
>
> Does the mask have multiple "masks?" Or is it just one monolithic thing? if it's just one grouping of 1s and 0s, then I think this might work... Myabe.... I haven't tried it, but this is where I was going to start.
>
> Use the contour procedure. Set the parameters to only contour the 1s. Use the XY_PATH variable to have it return the xy values of the contour. We might need to monkey around with the settings on how contour smooths (if it does).
>
> If you have multiple regions, then I think we to use label_regions in a clever way to go through and contour each region separately and default to the previous.
>
> I'm going on a trip for the Fourth, but I'll be working on this problem with my laptop. If I get anywhere, I'll drop you a line here.
>
>
> -Russell
>
>
>
> On Sunday, June 29, 2014 5:49:07 PM UTC-4, ca...@my.fsu.edu wrote:
>> Hey guys, I have a binary mask (just 1s and 0s) and I need to somehow extract the polygons (1s) out of there and convert them to a shapefile. Well all the documentation I've found seems to suggest that I need all the vertex data for each of the polygons I want to add, and I need to add them one by one... is there any other way to go straight from binary mask -> shapefile?
>>
>>
>>
>> If not, is there anyway to extract the polygons from the binary mask easily?
>>
>>
>>
>> Thank you all for the help, finding help online for IDL is painstakingly frustrating sometimes, as I'm sure you all know...
>>
>>
>>
>> Also does anyone have any examples of creating a polygon shapefile? Documentation only has examples for a point shapefile...
Another, possibly better (if you can understand the documentation),
alternative to the path information in the CONTOUR command is
ISOCONTOUR. This should give you want to need in a single go. Again, if
you understand what you need. The documentation obviously assumes you
do. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
|
|
|
Re: Need to create a polygon shapefile from a binary mask... any functions that could help? [message #88890 is a reply to message #88885] |
Tue, 01 July 2014 12:00  |
ca11h
Messages: 3 Registered: June 2014
|
Junior Member |
|
|
Hey STSCI!
Unfortunately the masks I'm going to need to do this with vary... some may have just one grouping of 1's, some may have many...
Using contour seems like a good idea...I'm going to give what you wrote a try and I'll also let you know if I find anything.
Good to know I'm in the same boat with someone else!
On Tuesday, July 1, 2014 11:19:51 AM UTC-4, rr...@stsci.edu wrote:
> Hi FSU
>
>
>
> I've been trying to do the same thing. I don't have anything working, but this is what I planned to try...
>
>
>
>
>
> Does the mask have multiple "masks?" Or is it just one monolithic thing? if it's just one grouping of 1s and 0s, then I think this might work... Myabe.... I haven't tried it, but this is where I was going to start.
>
>
>
> Use the contour procedure. Set the parameters to only contour the 1s. Use the XY_PATH variable to have it return the xy values of the contour. We might need to monkey around with the settings on how contour smooths (if it does).
>
>
>
> If you have multiple regions, then I think we to use label_regions in a clever way to go through and contour each region separately and default to the previous.
>
>
>
> I'm going on a trip for the Fourth, but I'll be working on this problem with my laptop. If I get anywhere, I'll drop you a line here.
>
>
>
>
>
> -Russell
>
>
>
>
>
>
>
> On Sunday, June 29, 2014 5:49:07 PM UTC-4, ca...@my.fsu.edu wrote:
>
>> Hey guys, I have a binary mask (just 1s and 0s) and I need to somehow extract the polygons (1s) out of there and convert them to a shapefile. Well all the documentation I've found seems to suggest that I need all the vertex data for each of the polygons I want to add, and I need to add them one by one... is there any other way to go straight from binary mask -> shapefile?
>
>>
>
>>
>
>>
>
>> If not, is there anyway to extract the polygons from the binary mask easily?
>
>>
>
>>
>
>>
>
>> Thank you all for the help, finding help online for IDL is painstakingly frustrating sometimes, as I'm sure you all know...
>
>>
>
>>
>
>>
>
>> Also does anyone have any examples of creating a polygon shapefile? Documentation only has examples for a point shapefile...
|
|
|