You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Where is the polyIntersect.m function in R2024 and how do I load it ?
2 views (last 30 days)
Show older comments
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
Star Strider
on 2 Jul 2024
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)
Walter Roberson
on 2 Jul 2024
polyintersect appears to be part of MRST (MATLAB Resevoir Simulation Toolbox), https://www.sintef.no/contentassets/2551f5f85547478590ceca14bc13ad51/nwm.html
16 Comments
Chuck Dalby
on 2 Jul 2024
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 ?
Chuck Dalby
on 3 Jul 2024
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);
Steven Lord
on 3 Jul 2024
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.
Chuck Dalby
on 3 Jul 2024
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);
Steven Lord
on 3 Jul 2024
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.
Chuck Dalby
on 3 Jul 2024
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.
Walter Roberson
on 3 Jul 2024
Sorry, I was not able to find any polyIntersect function anywhere -- only polyintersect
Chuck Dalby
on 4 Jul 2024
Is the polyintersect function only available with the Reservoir Simulation Toolbox ?
Chuck Dalby
on 4 Jul 2024
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
Walter Roberson
on 4 Jul 2024
Or just copy the individual polyintersect.m into your current directory.
Chuck Dalby
on 4 Jul 2024
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
Steven Lord
on 4 Jul 2024
Use your coordinate data from the CoRegErrData struct to create polyshape objects. Then just use intersect.
Chuck Dalby
on 5 Jul 2024
The CoRegErrData file is large (7GB) and I am not sure how to create the polyshape objects ?
Chuck Dalby
on 6 Jul 2024
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 ?
See Also
Categories
Find more on Elementary Polygons in Help Center and File Exchange
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)