フィルターのクリア

How to generate geojson file ?

45 ビュー (過去 30 日間)
THOUMY François
THOUMY François 2020 年 1 月 20 日
回答済み: Raphaël Nussbaumer 2023 年 1 月 31 日
Hello,
I'd like to generate geojson file from GPS coordinates computed with Matlab.
here is an example of the expected geojson file:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-1.789,
48.286
],
[
-1.781,
48.283
],
[
-1.776,
48.260
],
]
Using the below Matlab code, I could get correctly the first lines but I can't find how to generate the coordinates with the right syntax in the json file..
data.type='FeatureCollection';
data.features=[];
data.features.type = "Feature";
data.features.properties = "{}";
data.features.geometry.type = "LineString";
%data.features.geometry.coordinates =
saveJSONfile(data, 'test2.json');
Thank for your help
  2 件のコメント
Carlos Vidal
Carlos Vidal 2020 年 5 月 21 日
could you finally obtain the geoJSON? If not, I may come back with a solution later. Thank you.
Dmitry Kaplan
Dmitry Kaplan 2020 年 9 月 11 日
I am also interested in this. Would love to avoid a forest of sprintfs.

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

回答 (1 件)

Raphaël Nussbaumer
Raphaël Nussbaumer 2023 年 1 月 31 日
Sadly Matlab is not really easy to use with such a popular and common format. Here is my solution for generating square polygon
FC={};
FC.type="FeatureCollection";
FC.features=[];
F={};
F.type='Feature';
F.geometry={};
F.properties={};
F.geometry.type="Polygon";
pos = cat(3,...
loc(:,2)/10 + [0 res res 0 0],...
loc(:,1)/10 + [0 0 res res 0]...
);
res = 0.1;
for i=1:height(loc)
F.geometry.coordinates(1,:,:)= pos(i,:,:);
F.properties.value=0;
FC.features=[FC.features;F];
end
fileID = fopen('grid.geojson','w');
fwrite(fileID,jsonencode(FC));
fclose(fileID)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

タグ

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by