Geography Reference
In-Depth Information
event_date = record[1..10]
event_time = record[13..22]
latitude = record[26..32]
longitude = record[37..44]
longitude_direction = record[46..46]
depth = record[50..54]
magnitude = record[66..69]
# if the longitude is in the western hemisphere, it must be
# negative
if longitude_direction == 'W'
longitude = -1 * longitude.to_f
end
# print a delimited record
STDOUT << event_date << "|" << event_time << "|" \
<< latitude << "|" << longitude << "|" \
<< depth.strip << "|" << magnitude.strip << "|\n"
end
# close the input file
f.close
When we run this script, we get a nicely formatted file, delimited with |
and containing only the fields in which we are interested.
event_date|event_time|latitude|longitude|depth|magnitude
06/29/1898|18:36:00.0|52.0000|172.0000|0.0|7.6
10/11/1898|16:37:32.7|50.7100|-179.5|0.0|6.9
07/14/1899|13:32:00.0|60.0000|-150.0|0.0|7.2
You can now import the data using the Delimited Text plugin in QGIS,
using the same method as we used with the volcano data. The only
difference is this time we are using | as a delimiter.
If you are lucky, you won't have to go through a big preparation process
before importing your data. Oftentimes you can patch up the text file
using a text editor and global search/replace to get it formatted for
import. When you can't just write a quick Ruby (or Python or Perl)
script to do the job.
Importing with GRASS
Once we have the delimited text file formatted, importing into GRASS
is even quicker than using QGIS. From the GRASS shell, we can use
the v.in.ascii command to import the data. If you don't specify column
names, GRASS assigns default names that may not be too meaningful.
We want meaningful names, so for the columns option, we specify the
name for each in SQL style.
 
 
Search WWH ::




Custom Search