# How to create arcs between two points in Python?

I've been working on an python script automating the visualization of live point data. I have a table with two coordinate pairs. I'd like to connect these two point with an arc of a circle or similar (parabola??).

I've been able to connect the two points with a straight line, but it gives me a boring visual.

One of the major hurdles is my license level: ArcView. Anyone have any idea how I can generate a set of points that represent the path of a line between these two points? I can then use the points to polyline command.

I know this is a tough one, but I know there are some amazing math whizzes in this community!

-
You don't really provide enough information: "improve a boring visual" is neither specific nor a good problem statement. But perhaps you will get some ideas from a similar thread at gis.stackexchange.com/questions/5204/…. – whuber Sep 29 '11 at 21:43
Are you simultaneously viewing many lines, or just one (or a few) at a time? – Andy W Sep 30 '11 at 12:33
The point number could be anywhere from 2 to around 50. – Pixel Sep 30 '11 at 14:45

It seems the most common problem with these types of "flow maps" is that when many lines are included, they collide to such a great extent that it makes it difficult to discern any non-obvious pattern (when reciprocal flows are considered it happens to an even greater extent). Also the long lines tend to dominate the graphic, although it is quite possible the distribution of flows is predominately over short spaces (for instance a host of different distributions between places tend to be similar to Levy flights). I suppose this isn't necessarily a bad thing (the long lines may be more intrinsically interesting that the short lines for many phenomenon), but I don't think we want to lose the forest for the trees so to speak.

Although I don't doubt I've missed some potential "solutions" that have been proposed, I will try to sum up some of the ways individuals have tried to solve the problem in work that I have come across.

## Distorting the Lines

If you peruse some of the other threads on the sight you will see some examples of how people have dealt with this problem. In particular, the lines are distorted so they don't overlap with each other or other objects on the map. Whuber's answer on another similar question (already mentioned in a comment) is an example of this. A presentation by some researchers at Stanford demonstrates this same idea (Phan et al., 2005). Thanks for that presentation goes to dslamb for this answer on another thread (and all of the answers to that thread will be on interest for your question as well). I particularly find it interesting that one of the cardinal examples of this is the old immigration map by Minard is an example of a desirable output (circa 1864!).

Given your particular use case (small number of nodes and lines), this seems sufficient. The other "solutions" I present are more intended to visualize data with many lines and many origins-destinations (although I assume they will be useful summaries for the community in general, so I continue on regardless).

## Using Alpha Blending, Color, and Line Width/Height

The maps I listed in that same thread previously noted, Representation of network flows are examples of these. The facebook friends is a good case of adjusting the alpha level of lines, so it takes many more flows to represent a darker (or brighter in that case) connection between the two places. This also demphasizes the longer lines because they tend to happen more infrequently. Similar logic comes from Value-by-Alpha maps for polygon areas (Roth et al., 2010) that have been mentioned on this forum before.

The other map I present in that same answer uses color, and a non-traditional 3d perspective arcing lines (Ratti et al., 2010). The authors used a clustering criteria to group homogenous areas together and color code them (so by definition the areas within the color have more similar flow patterns than between colors). The clustering criteria in and of itself could be interesting to identify patterns in the data, although it seems a likely problem with this, as Andrew Gelman has mentioned, is that it tells you pretty much what you already know, that places nearer to each other tend to have more connections.

Lastly, in this category I include techniques that weight the lines (similar to alpha blending) using either the line width, or in the case of the 3d perspective line height, to convey the volume of the flow. See the page on Tobler's flow mapping software page for some examples in 2d (and the other article I mentioned is an example in 3d using line heights). Also on that page Tobler has a very useful article describing the problems with flowmapping and their historical application (Tobler, 1987).

Another example in 3d is this answer by a mankoff on this site. This post on the Sociological images blog shows a useful way in a flow diagram to distinguish between in-flows and out-flows (although again it works because the number of nodes and relatively small, and the nodes on the network can be layed out in an arbitrary way to reduce overplotting). Those same types of arrows (and a few others using hashings) are also in (Tobler, 1987).

In the end though line width and color don't really solve the over-plotting problem. The arcs in 3d help somewhat, although with more complicated flow patterns I think they will have limited utility. IMO alpha blending seems to be the most useful in a wide variety of situations of these three, but color and line width could/should be used in conjunction with line distortion mentioned above.

## Data Reduction

I group two types of techniques here, 1) using small multiple maps (i.e. many maps with inherently less objects to visualize so overplotting is reduced), or 2) other graphical representions, that are not lines, but represent some of the flows via density or choropleth maps. Examples of these can be found in (Corcoran et al., 2009; Rae, 2009; Wood et al., 2010) (thanks to iant for the Rae reference). These tend to reduce the amount of visual information presented by either presenting a series of small multiple maps (or just a smaller area), or use a choropleth mapping scheme to represent some statistic (examples could be number of in-flows, number of outflows, direction of the flows, average distance of the flows). If you have point level data you could represent these statistics through kernal density raster maps, or aggregate them into quadrats.

When information is reduced like this, overplotting isn't as much a problem. A very cool interactive online example is this migration map by Forbes magazine. You can only see one county at a time, but the reduction of information makes it much easier to parse the lines (and the difference between in-flows and out-flows). A recent post on the ESRI mapping blog also uses a similar technique with the small multiples (they also choose a particular projection for the world map to have "pretty looking" lines, and make good use of color to further highlight different international origins). In that example it works out pretty well because the end destination is the same for all flows, but if flows could be reciprocal it probably wouldn't work out as well.

## Using Other Non-map Representations of Flows

Others on this site have suggested using alternative diagrams to the actual map to represent the flows (just mapping the origins and destinations in some other manner than their actual geographic location). Examples of these are either cicular visualizations (such as that produced by Circos), arc diagrams (see this example on Protovis, these are also called kriskograms (Xiao & Chun, 2009)), or matrix heat maps (here is another example from the Protovis website). Another option would be to use some type of automated network layout to identify patterns in the flows (such as that capable by Graphviz). Besides Graphviz it appears Gephi, the NetworkX python library, and some R libraries are popular tools as well (see this answer on the stats site).

The libraries I cite are pretty cool as they have developed interactive visualizations as well. Here is an example with a similar style to the circular graphics (although not circular!). Here is another interactive visualization using some of the line distortion techniques discussed earlier, network placement (that appears similar to circular Dorling cartograms) as well as other useful statistical summaries (I saw both of those examples originally on the information aesthetics blog).

Some other resources I think are useful are the software and articles coming from the Spatial Data Mining and Visual Analytics Lab. Also the crime travel demand modeling in the CrimeStat program is a gentle introduction to applicable regression techniques for such flow data. Either of these tools may allow you to identify interesting correlations in the flow patterns to other geographic information. Another place to perhaps recieve some useful inspiration for either graphically displaying the data or statistical analysis would be a recent issue of in the Journal of Computational and Graphical Statistics, Volume 20 Issue 2, on examining flight arrival/departure statistics for commercial carriers in the US from 1987 to 2008 (if you are interested in handling big data this would be worthwhile to examine as well). All the articles are free and they have associated posters with each paper.

In the end, the data and the medium will dictate how well some of these techniques work in reducing the visual clutter that comes along with flow data. I hope this is a useful place though to find ideas on how to deal with this visualization problem though. If you further refine your question into what you want to accomplish, then others can give useful feedback into actual programmatic implementations (if something is not already available).

# Citations

*note, links to ungated pdf documents are included when I could find one

-
I have currently omitted any graphics, but if requested I can include any if people want to see examples without having to follow the links. – Andy W Sep 30 '11 at 18:06
+1 Amazing answer. – whuber Sep 30 '11 at 19:55
Wow!!... Complete with citations! If I could vote twice, I would! Awesome answer, man :) – R Thiede Oct 3 '11 at 6:22
I have currently found another pretty cool interactive visualization using data reduction (and great circle lines), Find out which U.S. city is most popular among international house hunters via the Trulia Insights blog. – Andy W Oct 17 '11 at 13:48

There's a nice procedure here, by our very own underdark.

Basically, the procedure goes like so: - reproject the points you want the line to be between, - get a straight line drawn between them, - subdivide that line into x amount of pieces, and finally - project the subdivided line back to your original projection.

I've kind of stopped using Arc because it costs money, but for this procedure to work, I don't think you need to pay ESRI any extra bribes to give you basic functionality. I mean, I don't think you need to buy any "extensions." I'm speaking under correction though, because I'm not positive on whether subdividing a line is part of Spatial Analyst. Perhaps some of the more ESRIcally inclined can help me out here? :)

-
You used to not be able to do true curves with ArcView, but ArcView has been able to do true curves since version 9 now. – blord-castillo Sep 30 '11 at 17:08

You can go about creating visually attractive polylines from two points on a map using the great circle method. Check out http://www.esri.com/software/arcgis/defense-solutions/military-analyst.html - Military Analyst. Should have what you are looking for!

-
I'm not quite up to speed on Arc any more, but isn't it possible to do this with some reprojections? Because Military Analyst is probably going to cost you money... – R Thiede Sep 30 '11 at 14:30
I don't believe this solution would work anyway, as the extent of my map will be about 40 miles across. I believe this may work if it was at the scale of a continent. – Pixel Sep 30 '11 at 14:47
Military Analyst is free @RThiede Yes, It would work better at a larger extent. However, you may be able to edit the lines after they are created to give you what you want (as they use bezzier curves to produce hundreds of points along the polylines to create the curve) – Michael Markieta Sep 30 '11 at 15:31
I could easily edit lines to get the arcs I want, but as my post indicated I'm using Python to automate this process. Thanks for the feedback! – Pixel Oct 4 '11 at 16:12

Have you seen the article on the Esri Mapping Center blog? It makes use of the XY to Line tool which is available with an ArcView license. http://blogs.esri.com/Support/blogs/mappingcenter/archive/2011/09/06/Creating-Radial-Flow-Maps-with-ArcGIS.aspx

-