- "fopen" - https://www.mathworks.com/help/matlab/ref/fopen.html
- "fprintf" - https://www.mathworks.com/help/matlab/ref/fprintf.html
- "fclose" - https://www.mathworks.com/help/matlab/ref/fclose.html
How to export data as a shapefile without the mapping toolbox?
16 views (last 30 days)
Show older comments
I have a polygon definied by a series of longitude and latitude coordinates.
E.g.
lat = [56.182254, 56.185120, 56.163141, 56.165244];
lon = [-6.3276100, -6.2664986, -6.2664986, -6.3121605];
Is there a way to export this polygon as a shapefile in matlab R2021? I do not have the mapping toolbox so cannot use shapewrite.
Thanks for your help!
0 Comments
Answers (1)
Moksh
on 2 Nov 2023
Edited: Moksh
on 2 Nov 2023
Hi Emma,
I understand that you don’t have access to the “Mapping Toolbox” in MATLAB and you want to export the defined polygon as a shapefile.
You can try using the “fopen” function in MATLAB to create a shapefile. Then the shapefile can be edited using the “fprintf” function and exported using without the use of mapping toolbox.
Here is an example code for this:
% Define the polygon coordinates
lat = [56.182254, 56.185120, 56.163141, 56.165244];
lon = [-6.3276100, -6.2664986, -6.2664986, -6.3121605];
% Create a new shapefile file
fid = fopen('my_polygon.shp', 'w');
% Write the polygon coordinates to the shapefile file
fprintf(fid, '%.8f %.8f\n', lon, lat);
% Close the shapefile file
fclose(fid);
Here the “%.8f” represents the format specifier which tells the “fopen” function to write the polygon coordinates with 8 places of precision, separated by a space and a new line. This can be updated as per the requirements.
For more information about the used functions please refer to the following documentation:
I hope this information helps resolve the issue.
Best Regards,
Moksh Aggarwal
0 Comments
See Also
Categories
Find more on Map Display in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!