1
$\begingroup$

I love solution from question (histogram as well as distrubution) https://mathematica.stackexchange.com/questions/31948/show-density-plot-on-us-map#=.

But both cases are a bit more difficult in my case. I have coordinations in csv file where every line contains

LAT_A, LON_A, LAT_B, LON_B, DENSITY.

Sample code:

49.5671;12.34;50.0033;17.9569;10236
48.7635;16.0479;48.9803;17.3013;83
50.0895;13.3265;49.9450;14.7283;9982

I want to plot "highways" from LAT_A, LON_A to LAT_B, LON_B, where DENSITY is density of this line (it is really not real highway). It's easy - just load file as in the noted solutions, but how to plot these lines with densities and obtain density plot? Also any workaround solution will be more than welcome :-)

Thank you very mcuh!

$\endgroup$
  • 1
    $\begingroup$ Please provide sample data. $\endgroup$ – C. E. Nov 11 '14 at 19:12
  • $\begingroup$ I've updated my question. $\endgroup$ – astrak Nov 11 '14 at 19:27
  • $\begingroup$ What do you mean by the "density of a line"? Please be as precise as possible. $\endgroup$ – Rahul Nov 11 '14 at 20:31
  • $\begingroup$ I am sorry Rahul. Each line represent one air route (coordinations tell you where the route starts and where finishes) and density means for how many times was the route used. There are really many routes with different usage. Is it possible to implement solution of this problem into histogram or density plot in the linked question? I am struggling with this problem for a long time... $\endgroup$ – astrak Nov 11 '14 at 20:49
3
$\begingroup$

Guessing/hoping that the following is not too far off from what you have in mind:

lld = {{49.5671, 15.34, 50.0033, 17.9569, 100},
       {48.7635, 16.0479, 49.5671, 15.34, 35},
       {50.0033, 17.9569, 48.7635, 16.0479, 75}};

vertices = Join @@ (Partition[#, 2] & /@ lld[[All, ;; -2]]);
edges = Property[UndirectedEdge[{#, #2}, {#3, #4}],
     EdgeStyle -> Directive[{Hue[.9 #5/Max[Last /@ lld]],
        CapForm["Round"], Thickness[ .1 #5/Max[Last /@ lld]]}]] & @@@ lld;
vlabels = Thread[# -> (Placed[Style[#, 16, "Panel", Background -> Transparent], 
                              Above] & /@ #)] & @ vertices;
vcoords = Thread[vertices -> vertices];

Graph[edges, VertexLabels -> vlabels, VertexSize -> Small, 
 ImagePadding -> 60, VertexCoordinates -> vcoords, ImageSize -> 300]

enter image description here

Update: A DirectedGraph with directed edges in both directions:

lld[[All, -1]] =  Rescale[lld[[All, -1]], Through[{Min, Max}[lld[[All, -1]]]], {.3, .9}];

SeedRandom[223];
llda = lld[[All, {3, 4, 1, 2, 5}]];
llda[[All, -1]] = RandomReal[{.2, .7}, 3];
lld2 = Join[lld, llda];
vertices = Join @@ (Partition[#, 2] & /@ lld2[[All, ;; -2]]);
edges = Property[DirectedEdge[{#, #2}, {#3, #4}],
  {EdgeStyle -> Directive[{Hue[.9 #5], CapForm["Butt"], Thickness[.1 #5]}],
   EdgeShapeFunction ->  GraphElementData["ShortFilledArrow",
          "ArrowSize" -> (.3 #5)]}] & @@@ lld2;
vlabels = Thread[# -> (Placed[Style[#, 16, "Panel", Background -> Transparent], 
          Below] & /@ #)] &@vertices;
vcoords = Thread[vertices -> vertices];

Graph[edges, VertexLabels -> vlabels, VertexSize -> Small, 
 ImagePadding -> 50, VertexCoordinates -> vcoords, ImageSize -> 300]

enter image description here

$\endgroup$
  • $\begingroup$ @astrak, is this anywhere close to what you had in mind? $\endgroup$ – kglr Nov 15 '14 at 19:41
  • $\begingroup$ I have tested your code on a real geographical data, but I got just some lines - each under some another one. Is it possible to make some "projection o a globe"? I mean - when I write coordinations from New York to Paris, it should have this direction. Another line some other direction. Otherwise it is great workaround :-) $\endgroup$ – astrak Nov 15 '14 at 19:45
  • $\begingroup$ @astrak, i suggest "projection on a globe" as a new question. $\endgroup$ – kglr Nov 15 '14 at 21:07
  • $\begingroup$ sorry for later replies. For a while, I couldn't test your solution. If I try your solution on my data I get only direct lines, line by line, but no oriented lines according to coordinates which I have noted above. This is the crucial part and I can't change it to be able to connect each edge. I hope, you understand what I mean. $\endgroup$ – astrak Nov 29 '14 at 15:16

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.