creating a shapefile or geojson file

조회 수: 36 (최근 30일)
Urmila Datta
Urmila Datta 2022년 5월 12일
답변: Siraj 2023년 9월 18일
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