creating a shapefile or geojson file

35 次查看(过去 30 天)
I have geopoints of a boat track and other vectors like dateTime vector, CourseOverGround(degree),Speed over Ground(in knots) . I am not able to write the shape file . Only geopoints are written. Please help.
  2 个评论
KSSV
KSSV 2022-5-12
What error you are getting? Show us your code.
Urmila Datta
Urmila Datta 2022-5-12
编辑:Chad Greene 2022-8-22
Shape=geopoint(latitude,longitude);
CourseOverGround=[0 ;beta]; % beta a vector angles
SpeedOverGround=[0 ;sog_knt];% sog_knt a vector of speed values
dateTime=timeInterp; % datetime vector
dbfspec=makedbfspec(Shape);
dbfspec=struct('dateTime',timeInterp,'sog',SpeedOverGround,'cog',CourseOverGround);
shapewrite(Shape,'test.shp','DbfSpec',dbfspec);

请先登录,再进行评论。

回答(1 个)

Siraj
Siraj 2023-9-18
Hi!
It is my understanding that you have a boat track dataset consisting of geopoints representing the boat's locations at different times, along with other attributes such as timestamp, CourseOverGround (in degrees), and Speed over Ground (in knots)” and want to store data in a shape file but are facing some issues.
To address this, one alternative approach can be to use the "geopoint" function to create a container object that holds geographic point coordinates and attributes. By utilizing the dot notation, attributes such as dateTime, CourseOverGround, and SpeedOverGround can be dynamically added to the "geopoint" object. Subsequently, the enhanced object can be written to a shapefile using the "shapewrite" function. Refer to the following code for a clearer understanding.
% Define the range for latitudes and longitudes
latRange = [8, 37]; % Latitude range
lonRange = [68, 97]; % Longitude range f
% Generate vectors of latitudes and longitudes
latitudes = linspace(latRange(1), latRange(2), 10);
longitudes = linspace(lonRange(1), lonRange(2), 10);
% Generating CourseOverGround
numPoints = 10; % Number of points, same as the length of latitudes and longitudes
minCOG = 0; % Minimum value for CourseOverGround
maxCOG = 360; % Maximum value for CourseOverGround
% Generate random values for CourseOverGround
CourseOverGround = rand(1, numPoints) * (maxCOG - minCOG) + minCOG;
% Generating SpeedOverGround
numPoints = 10; % Number of points, same as the length of latitudes and longitudes
minSOG = 0; % Minimum value for SpeedOverGround
maxSOG = 10; % Maximum value for SpeedOverGround
% Generate random values for SpeedOverGround
SpeedOverGround = rand(1, numPoints) * (maxSOG - minSOG) + minSOG;
shape = geopoint(latitudes, longitudes);
shape.CourseOverGround = CourseOverGround;
shape.SpeedOverGround = SpeedOverGround;
dbfspec = makedbfspec(shape);
shapewrite(shape, "test.shp", 'DbfSpec',dbfspec)
S = shaperead("test.shp");
T = struct2table(S)
T = 10×5 table
Geometry X Y CourseOverG SpeedOverGr _________ ______ ______ ___________ ___________ {'Point'} 68 8 9.538 6.615 {'Point'} 71.222 11.222 182.54 1.8426 {'Point'} 74.444 14.444 338.76 1.5514 {'Point'} 77.667 17.667 312.84 9.3558 {'Point'} 80.889 20.889 292.82 4.1901 {'Point'} 84.111 24.111 311.94 5.4456 {'Point'} 87.333 27.333 33.675 4.2153 {'Point'} 90.556 30.556 100.61 5.0957 {'Point'} 93.778 33.778 193.2 3.1128 {'Point'} 97 37 242.11 1.8382
Refer to the following links for more information about the "geopoint" and "shapewrite" functions.
Hope this helps.

类别

Help CenterFile Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息

标签

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by