Why are shapefile data files not included when compiling a MATLAB function for mapping toolbox functions that use them using the MATLAB Compiler?

4 views (last 30 days)
I have a MATLAB function that utilizes the "usastatelo.shp" shapefile to plot the map of the all the states in the US. The contents of the function file are shown below:
function test
figure; ax = usamap('conus');
set(ax, 'Visible', 'off');
states = shaperead('usastatelo', 'UseGeoCoords', true,'Selector',{@(name) ~any(strcmp(name,{'Alaska','Hawaii'})), 'Name'});
names = {states.Name};
indexConus = 1:numel(states);
stateColor = [0.5 1 0.5];
geoshow(ax(1), states(indexConus), 'FaceColor', stateColor);
In order to deploy this code onto a machine which does not have MATLAB installed, I use the MCC command:
mcc -m test
to create a stand-alone executable, using the MATLAB Compiler.
However, when I try to test the executable by running the following command from the MATLAB command prompt:
!test
I receive the following error message:
ERROR: Error in ==> mapformats\private\openShapeFiles at 19
Error in ==> shaperead at 204
Error in ==> example_track at 5
??? Error using ==> mapformats\private\openShapeFiles>checkSHP
Failed to open both usastatelo.shp and usastatelo.SHP.
map:openShapeFiles:failedToOpenSHP1

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 17 Feb 2021
Edited: MathWorks Support Team on 17 Feb 2021
Shapefiles and their related data files (for example: .dbf, .shx, etc.) that are needed for correct Mapping Toolbox functionality are intentionally not included in the deployment package when a function file is compiled using the MATLAB Compiler. This is because the Compiler cannot identify the dependencies imposed by these data files during compile time.
To work around this issue, you may use the -a flag with the MCC command to include the directories containing the shapefiles and related data files needed in your application. For example, using the 'mapdemos' directory:
mcc('-m','test.m','-a',fullfile(matlabroot, 'toolbox', 'map','mapdemos'));
or if you do not wish to recursively add all subdirectories of 'mapdemos':
mcc('-m','testWorld2.m','-a',fullfile(matlabroot, 'toolbox', 'map','mapdemos', '*'));
For more information on using the -a flag with MCC to add directories to your application archive, refer to the official Help page for MCC:
Starting with MATLAB Compiler 4.5 (R2006b) you may also add the directories containing the shape data files to your DEPOYTOOL project under "Other Files."

More Answers (0)

Categories

Find more on MATLAB Runtime in Help Center and File Exchange

Products


Release

R14SP2

Community Treasure Hunt

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

Start Hunting!