How to transform multiple sets of coordinates in a csv file into a single shapefile

3 次查看(过去 30 天)
Hi,
I was wondering what was the easiest way to transform the coordinates of multiple polygons in a csv file into a single shapefile ? In the attached file I have multiple polygons with their corresponding latitudee and longitude coordinates and I would like to transform these into a single shapefile consisting of four polygons. I would also like to set the projection to mercator.
How do I do that ?
Thank you,

回答(1 个)

Rohit Pappu
Rohit Pappu 2021-1-25
A possible workaround is as follows
% Read the data from the csv file (exclude the header row)
data = readcell("test.csv","NumHeaderLines",1);
% Create an empty struct array with required field names
d = struct('Geometry','','Lat',[],'Lon',[],'Name','');
% Since there are 4 polygons, iterate four times
for i =1:4
% Define the starting and ending row for each polygon (Every 6th row is filled with NaNs)
first = 6*(i-1)+1;
last = 6*i-1;
% Set the fields for a dummy struct
Data.Geometry='Polygon';
Data.Lat = cell2mat(data(first:last,2));
Data.Lon = cell2mat(data(first:last,3));
Data.Name = cell2mat(data(first,1));
% Store the data in the struct array
d(i) = Data;
end
% Write struct array to shapefile
shapewrite(d,'myfile.shp');
% Verify if data has been written correctly or not
P = shaperead('myfile.shp')

类别

Help CenterFile Exchange 中查找有关 Structures 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by