Grabbing info from an .ndk file and making a .kml file

  • Thread starter jadeco
  • Start date
  • Tags
    File
In summary: File);In summary, to create a .kml file, you need to use information from an .ndk file. However, there are a few mistakes in the provided code, such as not defining the variable numLinesInBlock and using incorrect parameters in the kmlwrite function. The correct code should include formatting the input correctly and using the fclose command to close the file.
  • #1
jadeco
1
0
So I have to make a .kml file, but I'm grabbing some info (latitude, longitude) from an .ndk file. I'm not quite sure how to do this. Right now I have this (sorry it sucks, 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);

And it's wrong in so many ways
 
Physics news on Phys.org
  • #2
. Can someone help me?There's a few things that need to be corrected in this code. Firstly, you need to define the variable numLinesInBlock, as that is used in the for loop. Secondly, you should not use the 'Name,' string in the kmlwrite function, as that is not a valid parameter. You should instead use a string such as 'Name', or some other descriptive name. Also, when writing to the KML file, you will need to format the input correctly. The KML format requires that you specify the latitude and longitude in separate variables, so you will need to create two variables (latitude and longitude) and populate them with the corresponding values from your input file. Finally, you should also use the fclose command at the end of your code to close the file. The following code should work:inputFilename = 'M:\week2\may11.ndk';numLinesInBlock = 5; %Define the number of lines in the blockinputFile = 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 endend% Create variables for the KML write commandlatitude = lat;longitude = lon;name = CMT_ID;filename = 'M:\week2\week2.kml';kmlwrite(filename, latitude, longitude, 'Name', name);% Close the input file
 

Related to Grabbing info from an .ndk file and making a .kml file

What is an .ndk file?

An .ndk file is a file format used by GIS (Geographic Information System) software to store geospatial data such as coordinates, attributes, and other spatial information.

What is a .kml file?

A .kml file is a file format used for displaying geographic data in 3D on a virtual globe, such as Google Earth. It contains information such as coordinates, placemarks, and polygons.

How do I grab information from an .ndk file?

To grab information from an .ndk file, you will need to use a GIS software or programming language that supports the .ndk file format. This software or programming language will have functions or methods to extract the data from the .ndk file.

How do I make a .kml file from an .ndk file?

To make a .kml file from an .ndk file, you can use a GIS software or programming language that supports both file formats. You will need to extract the data from the .ndk file and then use the functions or methods to convert it into a .kml file.

What are the advantages of using a .kml file over an .ndk file?

A .kml file allows for easy visualization of geographic data in 3D on a virtual globe, making it more user-friendly and accessible. It also has a more universal format that can be easily shared and viewed on different platforms. On the other hand, an .ndk file may have more detailed and precise information, but it is often used for analysis and not for display purposes.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Programming and Computer Science
Replies
6
Views
5K
Back
Top