I'm trying to import a CSV file that contains the latitude and longitude of some USA routes, but the import process is very slow and Mathematica spent about 10 min importing it.

A link to the file here.

I just change the file and put the original file that I'm using

  • 1
    $\begingroup$ This doesn't look like a correct CSV file. It has Mathematica expressions in them which contain commas. Those commas mess up the CSV structure. If I export as tab-separated values from Google Docs, I can import it. The Mathematica expressions are imported as strings and can be converted back to expressions using ToExpression. Did I misunderstand your question? $\endgroup$ – Szabolcs Jul 21 '15 at 10:16
  • 1
    $\begingroup$ This seems essentially like a duplicate of your previous question here. Usually it would be better to edit an already existing question rather than pose a marginally different new one, especially since we asked for the original data in the first thread. In any case, you shoud supply the code you use to reproduce the problem and save time and effort. $\endgroup$ – Yves Klett Jul 21 '15 at 13:52

This isn't a correct CSV file looking at it in Google Docs:

Mathematica graphics

In the second column one can see a complete Mathematica list as a string. The downloaded version has some issues too, so I read it in as a binary file and process it line by line.

fp = OpenRead["C:\\Users\\XPS15-Sjoerd\\Downloads\\rutas.csv", BinaryFormat -> True];

routes = Reap[
     (data = ReadLine[fp]) =!= EndOfFile,
           Flatten[ImportString[data, "CSV"], 1], {2}]
    ][[2, 1]];

routesClean = DeleteCases[routes, {_, Null}]; (* delete routes without data *)

GeoGraphics[{Red, Thick, Line[GeoPosition /@ routesClean[[All, 2]]]}]

Mathematica graphics

The whole process takes 15 seconds on my old PC.

An individual route:

GeoGraphics[{Red, Thick, Line[GeoPosition@routesClean[[1, 2]]]}]

Mathematica graphics

| improve this answer | |
  • $\begingroup$ I'm using this file mega.nz/#!E8xVHAyA!9dW4ulz0wfUzgdmf9KCO8QB9LXsVKEuTAGoeFvHLP4A $\endgroup$ – Alberto Jul 21 '15 at 10:28
  • 3
    $\begingroup$ Sorry, I'm not going to download from some shady download site. Besides, after the work I put in on the file you originally posted, should I now be working on this one and then..., what next? Make up your mind please, when you're posting questions instead of wasting people's time. $\endgroup$ – Sjoerd C. de Vries Jul 21 '15 at 10:33
  • $\begingroup$ Yes, it works, but it spent to much time importing, reading o whatever it was $\endgroup$ – Alberto Jul 21 '15 at 10:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.