필터 지우기
필터 지우기

How can I create a point shapefile from a csv (or matrix) with lat/long columns?

조회 수: 11 (최근 30일)
Brittany K
Brittany K 2020년 3월 23일
댓글: Brittany K 2020년 3월 23일
I have a csv file (or I can use a matrix object) within Matlab that I need to convert to a shapefile (points). An example of the first 3 rows of my data is below.
% X Y var1 var2 var3
%463310.925537576 5013978.52568211 5 8 1
%464344.150891795 5013195.54547050 2 4 9
%463782.424931854 5012644.08397560 2 1 8
I want to create the point shp with this data. I've tried this:
%lat long needs to be plotted.
[T.Geometry] = 'Point';
T.x = 'X'; % latitude
T.y = 'Y'; % longitude
T.var1 = 'var1';
T.var2 = 'var2';
T.var3 = 'var3';
T
I've tried this:
%lat long needs to be plotted.
[T(1:1780).Geometry] = deal('Point');
T.x = 'X'; % latitude
T.y = 'Y'; % longitude
T.var1 = 'var1';
T.var2 = 'var2';
T.var3 = 'var3';
T
The problem is that these two methods only work if you delinate each point one at a time. I have a csv with 1780 points...

답변 (1개)

Stijn Haenen
Stijn Haenen 2020년 3월 23일
Im not sure what you want, but maybe this can help:
for i=1:1780
T.(sprintf('var%g',i))=sprintf('var%g',i);
end
This creates a structure with 1780 fields
  댓글 수: 1
Brittany K
Brittany K 2020년 3월 23일
I already have a structure iwth 1780 rows. Is that what you mean by fields? Usually fields means columns--at least in spatial science. structure T is a matrix with 1780 rows. It needs to be converted from a CSV to a SHP (which means a geometry needs to be added).

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by