How to export data as a shapefile without the mapping toolbox?

15 ビュー (過去 30 日間)
Emma Whettall
Emma Whettall 2022 年 3 月 14 日
編集済み: Moksh 2023 年 11 月 2 日
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!

回答 (1 件)

Moksh
Moksh 2023 年 11 月 2 日
編集済み: Moksh 2023 年 11 月 2 日
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

カテゴリ

Help Center および File ExchangeMap Display についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by