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

15 ビュー (過去 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).

サインインしてコメントする。

カテゴリ

Find more on Geometric Geodesy in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by