Matlab

Moderators: None (Apply to moderate this forum)
Number of threads: 1494
Number of posts: 2174

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Creating a KML file in MATLAB, pulling info from an ndk file Posted by jadeco on 26 Jan 2012 at 1:18 AM
Hello, I'm making a KML file using the code found on this page: http://www.mathworks.com/help/toolbox/map/ref/kmlwrite.html.

But I have to grab the longitude and latitude on a .ndk file, and I'm not sure how to incorporate that into my script.

This is what I have so far. I know the .ndk part is right, but I don't know how to stick it back into the code that creates the kml. Sorry ahead of time; I'm a total noob.

inputFilename = 'M:\week2\may11.ndk';
inputFile = fopen(inputFilename);

while (feof(inputFile) == 0)
% Read input file in blocks of 5
for i = 1:numLinesInBlock
% Read line from input file
currentLine = fgetl(inputFile);

% If we have the first line, then process it
if (i == 1)
% Extract the information we need
lat = strtrim( currentLine(28:33) );
lon = strtrim( currentLine(35:41) );

elseif (i == 2)
CMT_ID = strtrim( currentLine(1:16) );

end
end
end

filename = 'M:\week2\week2.kml';
kmlwrite(filename, lat, lon, 'Name,' CMT_ID);
Report
Re: Creating a KML file in MATLAB, pulling info from an ndk file Posted by giug on 26 Jan 2012 at 3:09 AM
Sorry, I can't understand what is your problem...
There are variables not defined in your code, and I don't know what is the content of the .ndk file, so I can't understand what are you asking.
Report
Re: Creating a KML file in MATLAB, pulling info from an ndk file Posted by jadeco on 27 Jan 2012 at 5:30 PM
The .ndk file is in this zip file. Here is the description.
Report
Re: Creating a KML file in MATLAB, pulling info from an ndk file Posted by giug on 30 Jan 2012 at 12:53 AM
Ok, what is the problem with the code?
Report
Re: Creating a KML file in MATLAB, pulling info from an ndk file Posted by jadeco on 31 Jan 2012 at 5:02 PM
Nothing. Figured it out, thanks :)

clc;
clear all;

inputFilename = 'M:\week2\may11.ndk';
inputFile = fopen(inputFilename);

numLinesInBlock = 5; % Each CMT record spans over five lines


while (feof(inputFile) == 0)
for i = 1:numLinesInBlock
currentLine = fgetl(inputFile);

if (i == 1)
% Extract the information we need
description = strtrim( currentLine(57:80) );
date = strtrim( currentLine(6:15) );
time = strtrim( currentLine(17:26) );
latitude = strtrim( currentLine(28:33) );
longitude = strtrim( currentLine(35:41) );
depth = strtrim( currentLine(43:47) );
mb = strtrim( currentLine(49:51) );
ms = strtrim( currentLine(53:55) );

elseif (i == 2)
CMT_ID = strtrim( currentLine(1:16) );

filename = 'M:\week2\week2.kml';
kmlwrite(filename, latitude, longitude, 'Description', description);
end
end
end

fclose(inputFile);
fclose(outputFile);



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.