Where is the polyIntersect.m function in R2024 and how do I load it ?

I have updated my R2022 license and can't locate the polyIintersect.m function and load it ? I need the function
for an old program

 Accepted Answer

I can’t find it in the online documentation. There are several Mapping Toolbox functions, specifically polyxpoly, as well as other intersection functions.
To the best of my knowledge, thater are none in core MATLAB, although there are several in the File Exchange.

More Answers (1)

polyintersect appears to be part of MRST (MATLAB Resevoir Simulation Toolbox), https://www.sintef.no/contentassets/2551f5f85547478590ceca14bc13ad51/nwm.html

16 Comments

Thank you. I downloaded and located the function in the Reservoir Simulation Toolbox, but am not sure how to load it into MATLAB. The read.me file is thin and I am new to MATLAB. I am still surprised that polyintersect is not a standard mapping function. Is there another way to accomplish this without using polyintersect ?
What do you expect polyintersect to do that intersect on polyshape objects doesn't do?
Here is the foemer code that worked in R2022:
[OutData(ii).intsecArea(i).Data, S] = polyIntersect(CoRegErrData, inPolyNewsub, inPolyOldsub)
If I change this to:
[OutData(ii).intsecArea(i).Data, S] = Intersect(CoRegErrData, inPolyNewsub, inPolyOldsub)
I get the error message:
Error in polyshape/intersect (line 68)
ns = polyshape.checkArray(subject);
Error in SDP_Sprinkler_preallocate_1a (line 33)
[OutData(ii).intsecArea(i).Data, S] = intersect(CoRegErrData, inPolyNewsub, inPolyOldsub);
That's not the full text of the error message. Please show all the text displayed in red (and/or orange) when you run that code.
Depending on exactly what your polyintersect function did, intersect may not be a strict "find and replace" replacement. The exact text of the message may tell us what you need to do to modify your code to use it.
Here it is:
Warning: Polyshape has duplicate vertices, intersections, or other inconsistencies that may produce inaccurate or unexpected results. Input data has been modified to create a well-defined polyshape.
> In polyshape/checkAndSimplify (line 526)
In polyshape (line 175)
In SDP_Sprinkler_preallocate_1a (line 23)
Error using polyshape/checkArray (line 562)
First input argument must be of type polyshape.
Error in polyshape/intersect (line 68)
ns = polyshape.checkArray(subject);
Error in SDP_Sprinkler_preallocate_1a (line 33)
[OutData(ii).intsecArea(i).Data, S] = intersect(CoRegErrData, inPolyNewsub, inPolyOldsub);
Okay, so what exactly is CoRegErrData? Nothing in the code you've posted shows what it is. If it's not a polyshape object but it represents a polygonal region, make a polyshape using that data and then call intersect.
CoRegErrData.mat is a data file that contains 2-D contour maps of horizontal positional error (x,y)-- the data convers the state of Montana so it is a polygonal region (I think?). I will try what you suggest.
Sorry, I was not able to find any polyIntersect function anywhere -- only polyintersect
Is the polyintersect function only available with the Reservoir Simulation Toolbox ?
Thanks. I downloaded and extracted the LabelMeToolbox, but can't install it using the add on manager--it does not appear on the selection of available add ons--please advise
Use pathtool to add the appropriate directory or directories to the MATLAB path.
Or just copy the individual polyintersect.m into your current directory.
I copied polyintersect.m into the current directory and the program ran but with these error messages:
Warning: Polyshape has duplicate vertices, intersections, or other inconsistencies that may produce inaccurate or unexpected results. Input data has been modified to create a well-defined polyshape.
> In polyshape/checkAndSimplify (line 526)
In polyshape (line 175)
In SDP_Sprinkler_1 (line 23)
I have had no problem with the simplify process below, but get the error message below--I have attached the full code for context
:
Error using vertcat
The following error occurred converting from struct to polyshape:
x- and y-coordinate vectors must both be numeric or both be cell arrays.
Error in polyintersect (line 8)
min_x = min([X1(:); X2(:)]);
Error in SDP_Sprinkler_1 (line 36)
[OutData(ii).intsecArea(i).Data, S] = polyintersect(CoRegErrData, inPolyNewsub, inPolyOldsub);
%% Load Data
inFiles = readtable('C:\MT_Conversion_Flood_to_Sprinkler\SDP\SDP_Project\inFiles\Overlays_S.xlsx');
dataFolder = 'C:\MT_Conversion_Flood_to_Sprinkler\SDP\SDP_Project\data_folder\';
load('C:\MT_Conversion_Flood_to_Sprinkler\SDP\SDP_Project\CoRegErrData.mat')
%% set subset
hucPoly = shaperead('C:\MT_Conversion_Flood_to_Sprinkler\SDP\SDP_Project\HUC4_Montana.shp');
%'C:\Users\kintla\Documents\SDP_Files\HUC4_Montana.shp']);
%% Run analysis
for ii = 1:length(hucPoly)
hucSub = polyshape(hucPoly(ii).X, hucPoly(ii).Y);
hucID = hucPoly(ii).Name;
OutData(ii).hucID = hucID;
for i = 1:size(inFiles,1)
inShapeOld = shaperead([dataFolder char(inFiles.OldShape(i))]);
inPolyOld = polyshape([inShapeOld.X],[inShapeOld.Y], 'Simplify', false);
inShapeNew = shaperead([dataFolder char(inFiles.NewShape(i))]);
inPolyNew = polyshape([inShapeNew.X],[inShapeNew.Y], 'Simplify', false);
inPolyNewsub = intersect(inPolyNew, hucSub,'KeepCollinearPoints',true);
inPolyOldsub = intersect(inPolyOld, hucSub);
[OutData(ii).intsecArea(i).Data, S] = polyintersect(CoRegErrData, inPolyNewsub, inPolyOldsub);
OutData(ii).intsecArea(i).ID = char(inFiles.NewShape(i));
if ~isnan(S(1).X(1))
shapewrite(S, [dataFolder 'outShapes_S\' hucID '_outInt_' char(inFiles.NewShape(i))])
end
T = table(OutData(ii).intsecArea(i).Data, 'VariableNames', {'outInt_acres1' });
writetable(T, [dataFolder 'outTables_S\' hucID '_outInt_' char(inFiles.NewShape(i)) '.txt'])
end
end
Use your coordinate data from the CoRegErrData struct to create polyshape objects. Then just use intersect.
The CoRegErrData file is large (7GB) and I am not sure how to create the polyshape objects ?
Hmmmm. If one looks at the code above it contains conversion of the data to polyshape objects ?
inPolyOld = polyshape([inShapeOld.X],[inShapeOld.Y], 'Simplify', false);
inShapeNew = shaperead([dataFolder char(inFiles.NewShape(i))]);
inPolyNew = polyshape([inShapeNew.X],[inShapeNew.Y], 'Simplify', false);
So I don't understand the need to do so again ?

Sign in to comment.

Products

Release

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!