필터 지우기
필터 지우기

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

조회 수: 9 (최근 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에서 Vector Volume Data에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by