- "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?
조회 수: 15 (최근 30일)
이전 댓글 표시
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
답변 (1개)
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Map Display에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!