Message Boards Message Boards

Geographical Maps - replace an area with a density illustration

Posted 10 years ago

I have used the morphological components function:

(you can copy and paste the Africa map code in to Mathematica)

Once this is done I have the map with each area separated by a different colour. What I want to do is take a particular area (which corresponds to a particular colour in the map) and then replace it with a density plot (e.g. image of 400 points scattered uniformly in this area, of which 70% are blue and 30% are red).

Any idea how this can be done? Thanks!

POSTED BY: Priyan Fernando
4 Replies

Have you seen this example in documentation (below)? You can use scatter plots instead of flags.

flags = EntityValue[EntityClass["Country", "Africa"], {"Entity", "Flag"}]; 
GeoGraphics[{EdgeForm[Black], {GeoStyling[{"Image", #2}], 
     Tooltip[Polygon[#1], CommonName[#1]]} & @@@ flags}, 
 GeoBackground -> "StreetMapNoLabels"]

enter image description here

POSTED BY: Vitaliy Kaurov
Posted 10 years ago

you can set area = 100. I have edited the. code. Thanks

POSTED BY: Priyan Fernando
Posted 10 years ago

Here is some code for what I want to do:

(* import map and display components *)
image = Import[""];
image2 = Binarize[image, 0.5];
morphcomp = 
  MorphologicalComponents[image2 , 0, CornerNeighbors -> False] ;

This loads a map of Africa colour the different components. The code below lets you "zoom in on one of the regions"

(* calculate rows and columns, and number of regios *)
rows = Dimensions[morphcomp][[1]]
columns = Dimensions[morphcomp][[2]]
regions = Length@Tally@Flatten@morphcomp
(* Zoom in on particular region *)
 minrow = 
     MemberQ[morphcomp[[#, All]], i] == True & /@ Range[rows], True]]];
 maxrow = 
     MemberQ[morphcomp[[#, All]], i] == True & /@ Range[rows], True]]];
 mincol = 
     MemberQ[morphcomp[[All, #]], i] == True & /@ Range[columns], 
 maxcol = 
     MemberQ[morphcomp[[All, #]], i] == True & /@ Range[columns], 
 subset = morphcomp[[minrow ;; maxrow, mincol ;; maxcol]];
 MatrixPlot[subset], {i, 1, regions, 1}]

Now what I want to do is to do a scatter plot within each region: For example here is a scatter plot (e.g. could be spatial map of individuals voting in the particular country, colored blue/red according to the vote):

(* create density plot *)
blue = 0.75 ;(* 75 percent *)
 red = 0.25;
chartsize = 1;
    numberpoints = 100;
    bluepositions = 
      area, {numberpoints*blue, 2}]; (*xy coordinates of blue points *)
    redpositions = 
      area, {numberpoints*red, 2}];(*xy coordinates of red points *)
    ListPlot[{bluepositions, redpositions}, PlotStyle -> {Blue, Red}]

To Summarize, what I would like to do is basically is:

  1. Select a region (say a country within Africa)
  2. For this country create a scatter plot in the shape of the country (i.e. select random points within the country and color it blue or red - you can assume 75% of ppl voted blue, and 25% red).
  3. Take this scatterplot (which is shaped like the country) and superimpose it on to the country
  4. Do this (steps 1-3) for all the regions (which is the number of morphological components) - and then assemble the final image.
  5. This will look like Africa - where each country within - is overlaid with it's own scatterplot - which shows how in each country, how individuals voted.

This way I can preserve the population densities in the map.

I hope someone can give me some pointers on how this can be done! Maybe it can't be done in Mathematica?

Many thanks, Priyan.

POSTED BY: Priyan Fernando

In your last code block variable area is undefined. Could not run it.

POSTED BY: Sam Carrettie
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract