Re: overlap of two polygons [message #84528 is a reply to message #84297] |
Mon, 20 May 2013 11:52  |
Chip Helms
Messages: 24 Registered: November 2012
|
Junior Member |
|
|
I think something along the lines of the following would tell you where two regions overlap (although there is probably a more efficient way of doing this)
nROIarr = bytarr(1024,1024)
; add 1 to each roi pixel
;(I'm assuming the indices of the ROIs are in ROIdex1 and ROIdex2)
nROIarr[ROIdex1]++
nROIarr[ROIdex2]++
; overlapping points will be those with values of 2
overlapdex = where(nROIarr eq 2, nOverlap)
; and just to get even fancier...
; here's how you can define polygons outlining these overlapping regions
; using contour's path_xy and path_info keywords
; (word of warning...if you're polygon ends up with a height
; or width less than 2 pixels this might not work...also I should
; credit Ken Knapp with introducing me to this nifty piece of IDL magic)
; calculate the contours (no contour plot is drawn)
contour, nROIarr, path_info=pinfo, path_xy=pxy, /path_data_coords, level=[2]
; locate all overlap polygons (we're looking for contours around higher values)
polyloc = where(pinfo.hihg_low eq 1, npoly)
; initialize list to hold polygon indices
xpoly = list()
ypoly = list()
; loop through each overlapping region and unpack the contour polygons
for ip=0, npoly-1 do begin
; determine index of first point in polygon
i1 = pinfo[polyloc[ip]].offset
; determine index of last point in contour
i2 = i1 + pinfo[polyloc[ip].n - 1
; grab and store contour position
xpoly.Add, pxy[0,i1:i2]
ypoly.Add, pxy[1,i1:i2]
endfor
Each elements of the xpoly and ypoly lists should be a vector containing the x and y coordinates of each vertex of the enclosing polygon, respectively.
On re-reading your post I think I'm not sure I covered the question you were asking (my overeagerness to share nifty IDL tricks strikes again). If you have a list of vertices, you can use the method I outlined above if you first use polyfillv:
nROIarr[polyfillv(xindex, yindex, 1024, 1024)] = 2
If they are lat/lon pairs and you have 1D lat and lon vectors corresponding to the rows and columns of the 1024x1024 array then you could do something like:
; lat, lon are the list of all lats and lons
; vertlat and vertlon are the lat lons of the vertices
nROIarr[polyfillv(value_locate(lon,vertlon),$
value_locate(lat,vertlat),1024,1024)] = 2
And with that I should probably stop procrastinating and get back to work.
Cheers,
Chip
|
|
|