Skip to content

Commit c0789d9

Browse files
author
Anders
committed
Added proper error handling for when ROI is outside map
1 parent 061b942 commit c0789d9

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed

common/ROI/extractROIsFromMap.m

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,29 @@
5454
[X, Y, Z] = mfwdtran(mstruct, ROI.latitude, ROI.longitude, ROI.altitude);
5555
% X = ROI.X;
5656
% Y = ROI.Y;
57-
58-
% Extract neighbourhood (50 * GSD)
59-
[X2,Y2] = polygrow(X,Y, mapInfo.SpatialRef.CellExtentInWorldX*50);
60-
[MapNeighborhood, MapMaskNeighborhood, mapROIrasterRefNeighborhood, ~] = mapcrop(map, mapInfo.SpatialRef, X2, Y2);
61-
62-
if (~isempty(newMapRasterRef))
63-
% Map neihgbourhood into same raster coordinate system as
64-
% new map raster reference
65-
MapNeighbourhoodRemapped = remapmap(MapNeighborhood, mapROIrasterRefNeighborhood, ROIs(r).mapROIrasterRefNeighborhood); %, size(MapNeighborHood), class(MapNeighborHood));
66-
67-
% Extract ROI
68-
[ Iroi, Imask, mapTransformationROI, ~ ] = mapcrop( MapNeighbourhoodRemapped, ROIs(r).mapROIrasterRefNeighborhood, X, Y );
69-
else
70-
[ Iroi, Imask, mapTransformationROI, ~ ] = mapcrop( MapNeighborhood, mapROIrasterRefNeighborhood, X, Y );
57+
try
58+
% Extract neighbourhood (50 * GSD)
59+
[X2,Y2] = polygrow(X,Y, mapInfo.SpatialRef.CellExtentInWorldX*50);
60+
[MapNeighborhood, MapMaskNeighborhood, mapROIrasterRefNeighborhood, ~] = mapcrop(map, mapInfo.SpatialRef, X2, Y2);
61+
62+
if (~isempty(newMapRasterRef))
63+
% Map neihgbourhood into same raster coordinate system as
64+
% new map raster reference
65+
MapNeighbourhoodRemapped = remapmap(MapNeighborhood, mapROIrasterRefNeighborhood, ROIs(r).mapROIrasterRefNeighborhood); %, size(MapNeighborHood), class(MapNeighborHood));
66+
67+
% Extract ROI
68+
[ Iroi, Imask, mapTransformationROI, ~ ] = mapcrop( MapNeighbourhoodRemapped, ROIs(r).mapROIrasterRefNeighborhood, X, Y );
69+
else
70+
[ Iroi, Imask, mapTransformationROI, ~ ] = mapcrop( MapNeighborhood, mapROIrasterRefNeighborhood, X, Y );
71+
end
72+
catch ME
73+
progBar.release()
74+
ProgressBar.deleteAllTimers();
75+
warnStruct = warning;
76+
warning on;
77+
warning(['Could not extract ROI (Name: ' ROI.name{1} ') from map.']);
78+
warning(warnStruct);
79+
rethrow(ME)
7180
end
7281

7382
% % TESTING: REMOVE!!!

common/mapcrop.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@
7272
% end
7373
end
7474
catch ME
75-
disp(size(mapIn));
76-
disp(size(mapOut));
77-
disp(mapRect);
78-
disp([i j]);
79-
rethrow(ME)
75+
if (strcmp(ME.identifier, 'MATLAB:badsubscript'))
76+
error('mapcrop:PolygonOutsideMap','All vertices of the polygon must be located inside the map limits.')
77+
else
78+
rethrow(ME)
79+
end
8080
end
8181

8282
% % Crop each channel and store in cell array

0 commit comments

Comments
 (0)