0
|
10360 Views
|
4 Replies
|
1 Total Likes
View groups...
Share

# Geographical Maps - replace an area with a density illustration

Posted 9 years ago
 I have used the morphological components function: http://reference.wolfram.com/language/ref/MorphologicalComponents.html#41373480 (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!
4 Replies
Sort By:
Posted 9 years ago
 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"] Posted 9 years ago
 you can set area = 100. I have edited the. code. Thanks
Posted 9 years ago
 Here is some code for what I want to do: (* import map and display components *) image = Import["http://www.theodora.com/maps/new6/african_color.gif"]; image2 = Binarize[image, 0.5]; morphcomp = MorphologicalComponents[image2 , 0, CornerNeighbors -> False] ; Colorize[morphcomp] 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][] columns = Dimensions[morphcomp][] regions = Length@Tally@Flatten@morphcomp (* Zoom in on particular region *) Manipulate[ minrow = Min[Flatten[ Position[ MemberQ[morphcomp[[#, All]], i] == True & /@ Range[rows], True]]]; maxrow = Max[Flatten[ Position[ MemberQ[morphcomp[[#, All]], i] == True & /@ Range[rows], True]]]; mincol = Min[Flatten[ Position[ MemberQ[morphcomp[[All, #]], i] == True & /@ Range[columns], True]]]; maxcol = Max[Flatten[ Position[ MemberQ[morphcomp[[All, #]], i] == True & /@ Range[columns], True]]]; 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; area=100; chartsize = 1; numberpoints = 100; bluepositions = RandomReal[ area, {numberpoints*blue, 2}]; (*xy coordinates of blue points *) redpositions = RandomReal[ 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: Select a region (say a country within Africa) 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). Take this scatterplot (which is shaped like the country) and superimpose it on to the country Do this (steps 1-3) for all the regions (which is the number of morphological components) - and then assemble the final image. 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 9 years ago
 In your last code block variable area is undefined. Could not run it.