I have a list of casinos. Each casino has:

  • latitude
  • longitude
  • boss (a single boss runs from 1 to 50 casinos)


40.642 -73.997 Freddy Queens
40.680 -73.985 Freddy Queens
40.697 -73.949 Freddy Queens
40.651 -73.968 Freddy Queens
40.772 -73.981 Manhattan Michael
40.813 -73.939 Manhattan Michael
40.755 -74.000 Manhattan Michael
40.781 -73.964 Manhattan Michael
40.721 -74.062 Nicole Je. Polizzi
40.750 -74.042 Nicole Je. Polizzi
40.694 -74.090 Nicole Je. Polizzi
[... 70,000 casinos for 27,000 bosses ...]

From this data I want to generate a map like this:

map (hand-drawn representation, not accurate)

One color per boss. The casinos of each boss should not "overlap" too much. The final goal is to find anomalies (casinos that should be transferred to a different boss because they are clearly in that boss' "territory"). Boss "territories" do not match any official geographical subdivisions, for all that matters the same problem could be set on Mars (Earth map background would be nice though).

Is there a webapp (desktop program also OK) to which I could feed this data (CSV) and that would show this kind of map? It can look different, for instance monochrome areas would be OK too, as long as it can be used to detect anomalies.

  • For what areas of the map? Just NY city and NJ? I think that you would need to find a definitive dataset with master polygons and then sort your list to that to get overlap and look at the resultant map. Nov 9, 2015 at 16:57
  • @ShawnMehan: "For what areas of the map?" <- Are you asking what area of the world the map should show? It should show the whole world, as coordinates actually cover most of the world. But I expect that a good solution would have zoom/scroll capabilities.
    – Nicolas Raoul
    Nov 10, 2015 at 2:46
  • "definitive dataset with master polygons" <- official country borders have no relevance. Actually, I wrote "Manhattan"/"Jersey" but the category is not about definitive geographical places. I updated my question to make it clearer, using a "casino/boss" metaphor.
    – Nicolas Raoul
    Nov 10, 2015 at 3:04
  • you will probably get better answers at gis.stackexchange.com for this
    – Ian Turton
    Nov 10, 2015 at 9:11
  • I'm certain that coordinates cover the whole world. What I'm not certain about is that any such use of said global coordinate system will ALSO include a regional mapping, in strings, of names given to polygon areas as f(global_coordinate_system). Therefore, I, seemingly foolishly, thought that if you restricted the areas where you wanted said mapping, it might improve the probability of finding one. Good luck. Nov 10, 2015 at 16:45

2 Answers 2

  1. For each boss you need to calculate the convex hull of their locations as this defines their "territory".
  2. Casinos that exist in more than one of these regions (use RegionMember) are potential targets for reallocation. Your dataset does not have any conflicts so I leave this to you.

    2.1 You can highlight these by using a different marker and style. Add a click event that will pop up the territories that overlap and assign it to the one you like.

    2.2 If the criteria is formulaic then you can just code it through.

  3. Replot.

I only do part one as there are no conflicts. However, I think I should leave some of the fun of 2 to you. If you attempt 2 in Mathematica and need some help then pop over the the Mathematica SE for assistance.

Mathematica Code

I just imported from the string directly for this one instead of making a text file.

dat = ImportString[ "40.642,-73.997,Freddy Queens
  40.680,-73.985,Freddy Queens
  40.697,-73.949,Freddy Queens
  40.651,-73.968,Freddy Queens
  40.772,-73.981,Manhattan Michael
  40.813,-73.939,Manhattan Michael
  40.755,-74.000,Manhattan Michael
  40.781,-73.964,Manhattan Michael
  40.721,-74.062,Nicole Je.Polizzi
  40.750,-74.042,Nicole Je.Polizzi
  40.694,-74.090,Nicole Je.Polizzi",

I use an Association here but you may want to use Dataset for your larger set. I also swap the order of the co-ordinates as they are not in the conventional order (they were plotting in Antarctica).

(* Calculate the territory and get a colour for each boss *)
bossPts = Association @@ KeyValueMap[
   Function[{key, value},
    With[{pts = value[[All, {2, 1}]]},
     key -> <|
       "Casinos" -> pts,
       "Territory" -> Identity @@@ MeshPrimitives[ConvexHullMesh[pts], 0],
       "Colour" -> ColorData["DarkRainbow"][RandomReal[]]
    ], GroupBy[dat, Last]];

I tooltip the territory with the boss' name and plot everything in the boss' colour.

  Function[{key, value},
     Tooltip[Polygon[value["Territory"]], key]},
    {PointSize[0.02], Point /@ value["Casinos"]}
  bossPts] // GeoGraphics

enter image description here

Hope this helps.

  • Very nice result! Now I have to find Mathematica haha :-)
    – Nicolas Raoul
    Nov 11, 2015 at 5:13

Use Google's MyMaps to map the lats and longs. Use a different color for each cluster/territory/"boss". Adjust the cluster/territory/boss as necessary after mapping each cluster. Draw lines and connect the dots.

If you really want to create polygons automatically, check out QGIS, the open-source GIS package, and PostGIS.

  • I should have specified how many I mean by "very long" in my question. There are 68282 casinos. So would you mind detailing the automatic solution? Thanks!
    – Nicolas Raoul
    Nov 11, 2015 at 1:49
  • 1
    68,282 is not a huge number to map, really. The number of territories you want to create is what matters for the method you choose. I do mind detailing the automatic solution - I don't really have the time and the sites themselves and the documentation do a better job than I.. Go to the PostGIS site or QGIS site to get started. And yes please check out gis.stackexchange.com. Good luck. Nov 11, 2015 at 1:55
  • google maps isn't open source and doesn't rely on open data. this is a nice solution, hope you don't think i'm being negative regarding that. just have to point the proprietary out....
    – albert
    Nov 11, 2015 at 2:17
  • I should have mentioned that there are 27,000 bosses. When you write "Draw lines and connect the dots", I understood it as a manual operation, am I mistaken?
    – Nicolas Raoul
    Nov 11, 2015 at 2:40
  • Yes but obviously don't do that. Use PostGIS. Nov 11, 2015 at 3:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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