Message Boards Message Boards

Avoid a network operation for GeoDistance to time out?

Posted 8 years ago

I´m trying to calculate the GeoDistance of 50.000 Latitude-Longitude positions to 1 Latitude-Longitude position. But after a while Mathematica 10.1 shows the message: A network operation for GeoDistance timed out. Please try again later.

How can I solve it?

Thanks

enter image description here

POSTED BY: Alejandro G
8 Replies
Posted 8 years ago

Thank you very much for this example! The GeoMarker result is incorrect. We'll fix that.

Jose.

POSTED BY: Updating Name

What are the values of data[[i]][[1]] ? Are they pairs {lat, lon} or GeoPosition objects or Entity objects?

When GeoDistance gets a pair of GeoPosition objects, the distance computation is performed locally in your computer, which is faster. When GeoDistance gets Entity objects or geo primitives (like GeoMarker) the computation is performed in the Wolfram geo server because it may involve accessing data about polygons, etc, which is accessed faster in the geo server, but there is the penalty of the transmission time. With point-to-point computations (i.e. not involving polygons) the results should be very similar.

When you have lots of {lat, lon} pairs, it is worth grouping them in a single GeoPosition object. For example, take 50000 random geo locations:

In[1]:= positions = Table[{RandomReal[{-90, 90}], RandomReal[{-180, 180}]}, 50000];

This computation is quite fast:

In[2]:= AbsoluteTiming[GeoDistance[GeoPosition[positions], GeoPosition[{-34.608116, -58.370380}]];] Out[2]= {0.149878, Null}

The result is a QuantityArray expression containing 50000 values in miles. Use Normal to get a list of Quantity objects, or QuantityMagnitude to get a list of the respective numerical values (in miles).

Posted 8 years ago

Hi Jose,

On my system (version 11.0.0 on Windows 7 x64) GeoPosition and GeoMarker do produce different results:

GeoDistance[#[{77., -65.}], #[{-34., -58.}]] & /@ {GeoPosition, GeoMarker}
{Quantity[12323.4, "Kilometers"], Quantity[5189.68, "Kilometers"]}
POSTED BY: Alexey Popkov
Posted 8 years ago

I solved it using GeoPosition instead of GeoMarker. But the distances differ, GeoDistances calculated with GeoPosition are different than calculated with GeoMarker.

Thanks

POSTED BY: Alejandro G

Best to use the tools at the top of the input area to paste code into a code area...

Of course your code cannot be tested with out the external file you are using...

But to your question, simply use an If statement that tests whether the GeoDistance computation returns

$Failed

as it was for some of your computations. If it returns $Failed then the If statement should try again. If that returns

$Failed

then you can substitute some default value. This is for trying only one extra time. If you want to try n>1 additional times then use another construct such as a While statement or a Do loop that only tries n time.

POSTED BY: David Reiss

It would help if you posted your actual code and not a screen shot.

But to your problem. I am guessing that indeed sometimes the network operation (sending and retrieving from the Wolfram cloud servers) is not completing in the required time. It can happen when so many requests are being sent to it. So, if that is the case, you should build some redundancy into your code so that if a request to the Wolfram servers returns $Failed, you try to sent the request again (and you can write code to do that more than one time if you wish).

But without the code is hard to test and reproduce your experience.

POSTED BY: David Reiss
Posted 8 years ago

My code is quite simple, that's why I didn't pasted it. But here it is in case it helps

data = Import["latlong.csv"];

casarosada = GeoMarker[{-34.608116, -58.370380}];

distanciaacasarosada1 = Table[{i, data[[i]][[2]], data[[i]][[1]], QuantityMagnitude[ GeoDistance[GeoMarker[{data[[i]][[2]], data[[i]][[1]]}], casarosada, UnitSystem -> "Metric"]], data[[i]][[9]]}, {i, 2, Length[data]}];

POSTED BY: Alejandro G
Posted 8 years ago

How can I build a request code with the redundancy you are indicating?

POSTED BY: Alejandro G
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract