- traces = Trace.find(:all, :conditions => ['inserted = ?', false])
-
- if traces and traces.length > 0
- traces.each do |trace|
- begin
-
- logger.info("GPX Import importing #{trace.name} from #{trace.user.email}")
-\r
- # TODO *nix specific, could do to work on windows... would be functionally inferior though - check for '.gz'
- gzipped = `file -b /tmp/#{trace.id}.gpx`.chomp =~/^gzip/\r
-
- if gzipped
- logger.info("gzipped")
- else
- logger.info("not gzipped")
- end
- gpx = OSM::GPXImporter.new("/tmp/#{trace.id}.gpx")
-
- f_lat = 0
- l_lon = 0
- first = true
-
- gpx.points do |point|
- if first
- f_lat = point['latitude']
- f_lon = point['longitude']
- end
-
- tp = Tracepoint.new
- tp.latitude = point['latitude']
- tp.longitude = point['longitude']
- tp.altitude = point['altitude']
- tp.user_id = trace.user.id
- tp.gpx_id = trace.id
- tp.trackid = point['segment']
- tp.save!
- end
-
- if gpx.actual_points > 0
- max_lat = Tracepoint.maximum('latitude', :conditions => ['gpx_id = ?', trace.id])
- min_lat = Tracepoint.minimum('latitude', :conditions => ['gpx_id = ?', trace.id])
- max_lon = Tracepoint.maximum('longitude', :conditions => ['gpx_id = ?', trace.id])
- min_lon = Tracepoint.minimum('longitude', :conditions => ['gpx_id = ?', trace.id])