使用投影将 Lon、Lat 坐标写入 Matlab 中的 shapefile

发布于 2024-11-18 05:47:00 字数 765 浏览 4 评论 0原文

我有一个经度和纬度点列表,用于在地图上绘制随时间移动的对象;它有点像一条稍微弯曲的线。我正在使用 Matlab 生成这些点,并希望将它们导出到折线 shapefile 中以在 ArcGIS 中加载。

从 mathworks 网站查看示例后,我能够创建一个线 geostruct 对象:

[Tracks(1:length(myLon)-1).Geometry] = deal('Line');
trackType = 'gc';
[Tracks.Type] = deal(trackType);
for i = 1:(length(myLon)-1)
    [Tracks(i).Lon Tracks(i).Lat] = track2(trackType, myLon(i, 1), myLat(i, 1), myLon(i+1, 1), myLat(i+1, 1));
end

shapewrite(Tracks, 'path_line');

这通常工作正常,但 Geostruct 不包含任何类型的投影,尽管文档声称 Mapstruct 包含。不幸的是,我没有看到任何有关如何创建 Mapstruct 的示例或函数。有谁知道我会怎么做?

另外,我尝试使用 mathworks 示例创建一个点地理结构而不是一条线,但它不会生成 .dbf 文件,仅生成 .shp 和 .shx 文件。对此有什么解释吗?感谢您的任何建议!

I have a list of longitude and latitude points that plot an object moving over time on a map; it sort of forms a line that curves around a bit. I am using Matlab to generate these points and would like to export them into a polyline shapefile to load in ArcGIS.

After looking at this example from the mathworks website, I am able to create a line geostruct object:

[Tracks(1:length(myLon)-1).Geometry] = deal('Line');
trackType = 'gc';
[Tracks.Type] = deal(trackType);
for i = 1:(length(myLon)-1)
    [Tracks(i).Lon Tracks(i).Lat] = track2(trackType, myLon(i, 1), myLat(i, 1), myLon(i+1, 1), myLat(i+1, 1));
end

shapewrite(Tracks, 'path_line');

This generally works fine but Geostruct does not contain any type of projection, although the documentation claims Mapstruct does. Unfortunately I don't see any examples or functions on how to create a Mapstruct. Does anyone know how I would go about doing that?

Also, I tried to create a Point Geostruct instead of a line using the mathworks example, but it doesn't generate the .dbf file, only .shp and .shx files. Is there any explanation for this? Thanks for any suggestions!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

美人迟暮 2024-11-25 05:47:01

您需要使用 arcgis 中的“定义投影”工具来定义导入的折线的投影。这应该创建一个相应的 .prj 文件。

you would need to use the "define projection" tool in arcgis to define the projection of your imported polyline. This should create a corresponding .prj file.

挽容 2024-11-25 05:47:01

除了要创建的 .dbf 文件的经纬度和几何值之外,地理结构中还必须至少有一个“属性”

you have to have at least one 'attribute' in the geostruct other than the lat and lon and geometry values for the .dbf file to be created

妳是的陽光 2024-11-25 05:47:01

我知道为时已晚,但是...使用 Matlab 2020,您需要使用下一个过程创建 .prj 文件(在本示例中我使用点):

pts(:,1) = data.X;  % Longitude data
pts(:,2) = data.Y;  % Latitude data

% Creating a structure where we will save the spatial data
dats = struct();

% Knowing the number of point to export
[r,~] = size(pts);

% Setting the geographic entity
[dats(1:r).Geometry] = deal('Point');

% Building the attributes table
for i = 1 : r
    dats(i).Lon = pts(i,1);
    dats(i).Lat = pts(i,2);
    dats(i).Name = horzcat('Pt',num2str(i));
end

% Exporting the data to shapefile
shapewrite(dats,'test.shp'));

% Setting the CRS
proj = geocrs(4326,'Authority','EPSG'); % WGS84

% Wkt string
srtWkt = wktstring(proj,'Version','wkt1');

% Creating the projecting data
fid = fopen('test.prj'),'w');
fprintf(fid,srtWkt);
fclose all;

在本示例中,您将获得 *.shp、*.prj 文件。您可以在 QGIS 中使用的 dbf、*.shx 和 *.prj 文件。

我的答案基于此另一个

例子是使用折线和表格来创建带有投影的形状文件。此代码只能在 Matlab 2021b 上运行:

ptos(:,1) = data.X;
ptos(:,2) = data.Y;

Shape = geolineshape(ptos(:,2),ptos(:,1));
proy = geocrs(4326,'Authority','EPSG');
Shape.GeographicCRS = proy;

Name = {'Polyline01'};

geota = table(Shape,Name);

shapewrite(geota,horzcat('test,'.shp'));

srtWkt = wktstring(proy,'Version','wkt1');
fid = fopen(horzcat('test','.prj'),'w');
fprintf(fid,srtWkt);
fclose all;

wmline(geota);

I know that is too late, but... Using Matlab 2020, you need to create the .prj file using the next procedure (in this example I use points):

pts(:,1) = data.X;  % Longitude data
pts(:,2) = data.Y;  % Latitude data

% Creating a structure where we will save the spatial data
dats = struct();

% Knowing the number of point to export
[r,~] = size(pts);

% Setting the geographic entity
[dats(1:r).Geometry] = deal('Point');

% Building the attributes table
for i = 1 : r
    dats(i).Lon = pts(i,1);
    dats(i).Lat = pts(i,2);
    dats(i).Name = horzcat('Pt',num2str(i));
end

% Exporting the data to shapefile
shapewrite(dats,'test.shp'));

% Setting the CRS
proj = geocrs(4326,'Authority','EPSG'); % WGS84

% Wkt string
srtWkt = wktstring(proj,'Version','wkt1');

% Creating the projecting data
fid = fopen('test.prj'),'w');
fprintf(fid,srtWkt);
fclose all;

With this example, you will get the *.shp, *.dbf, *.shx and *.prj files that you can use in QGIS.

My answer is based on this post

Another example is using a polyline and table to create a shapefile with its projection. This code only would run with Matlab 2021b:

ptos(:,1) = data.X;
ptos(:,2) = data.Y;

Shape = geolineshape(ptos(:,2),ptos(:,1));
proy = geocrs(4326,'Authority','EPSG');
Shape.GeographicCRS = proy;

Name = {'Polyline01'};

geota = table(Shape,Name);

shapewrite(geota,horzcat('test,'.shp'));

srtWkt = wktstring(proy,'Version','wkt1');
fid = fopen(horzcat('test','.prj'),'w');
fprintf(fid,srtWkt);
fclose all;

wmline(geota);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文