Group Abstract Group Abstract

Message Boards Message Boards

Show ListContourPlot on a polygon map.

Posted 10 years ago
data={lat,long,value}

Hey guys. I am trying to plot a contour graph with a polygon map, but it isn't working well. Think it is something with the coordinates.

p1=ListContourPlot[data];
p2=Graphics[{FaceForm[],EdgeForm[Directive[Black, Opacity[2]]],AdministrativeDivisionData[Control+=Rio Grande do Sul,State, "Polygon"]}];
Show[p1,p2]

data= {{-28.9267, -52.1242, 44}, {-28.3961, -52.6911,     
40}, {-29.1714, -51.5192, 38}, {-29.0442, -52.2953, 
  37}, {-27.4539, -53.2464, 36}, {-27.3617, -52.7714, 
  35}, {-27.8903, -52.2275, 35}, {-27.3617, -52.7714, 
  35}, {-29.5386, -52.5217, 35}, {-29.2442, -52.3122, 
  35}, {-28.6519, -52.07, 34}, {-31.7633, -52.4839, 
  34}, {-29.4533, -52.9614, 34}, {-27.51, -52.5978, 
  33}, {-29.7997, -51.8644, 33}, {-31.5581, -53.6725, 
  33}, {-27.4981, -52.1489, 32}, {-28.8722, -52.1753, 
  32}, {-27.6972, -52.0494, 32}, {-28.6594, -51.745, 
  31}, {-30.0003, -53.4992, 31}, {-27.5694, -52.0203, 
  31}, {-28.7797, -52.1722, 30}, {-28.9703, -52.0047, 
  30}, {-28.9828, -52.3458, 30}, {-29.1253, -56.5531, 
  30}, {-28.9944, -51.6958, 30}, {-29.4764, -51.4211, 
  30}, {-28.6606, -56.0044, 30}, {-29.5911, -51.1606, 
  30}, {-28.6519, -52.07, 29}, {-27.7872, -53.9369, 
  29}, {-28.7953, -52.0369, 29}, {-28.6775, -52.1664, 
  29}, {-29.1647, -51.8678, 29}, {-27.8203, -51.8275, 
  29}, {-28.5942, -51.7856, 29}, {-27.4089, -52.4097, 
  28}, {-28.6519, -52.07, 28}, {-29.7, -51.3247, 
  28}, {-28.5114, -55.2278, 28}, {-29.6842, -53.8069, 
  28}, {-29.2842, -51.8675, 28}, {-27.3592, -53.3944, 
  28}, {-27.3539, -52.1472, 28}, {-28.6594, -51.745, 
  27}, {-28.7117, -51.935, 27}, {-28.6594, -51.745, 
  27}, {-29.4011, -51.945, 27}, {-27.3906, -52.5706, 
  27}, {-27.5631, -53.9742, 27}, {-29.9753, -50.1281, 
  27}, {-29.0019, -52.1542, 27}, {-29.3508, -51.6758, 
  27}, {-31.7325, -53.5849, 27}, {-29.1767, -53.1592, 
  27}, {-27.7614, -51.9989, 27}, {-29.3414, -52.9792, 
  26}, {-27.6322, -51.8033, 26}, {-29.0675, -51.8592, 
  26}, {-28.5308, -51.8878, 26}, {-27.6208, -52.3797, 
  26}, {-28.9836, -51.8369, 25}, {-27.3539, -52.1472, 
  25}, {-27.6592, -53.5314, 25}, {-28.1309, -51.9268, 
  25}, {-27.7703, -51.6603, 25}, {-27.6894, -53.1817, 
  25}, {-29.3328, -53.0933, 25}, {-27.9519, -54.7519, 
  25}, {-29.3234, -52.2345, 25}, {-28.8456, -51.8903, 
  25}, {-27.3003, -52.8408, 25}, {-27.8606, -52.0844, 
  25}, {-28.9361, -51.5494, 25}, {-29.0469, -51.765, 
  25}, {-27.3942, -52.3003, 25}, {-29.4214, -53.0286, 
  25}, {-28.9944, -51.6958, 25}, {-28.8456, -51.8903, 
  25}, {-27.7081, -52.9128, 25}, {-28.4969, -52.0247, 
  25}, {-28.5347, -52.1536, 25}, {-28.0214, -54.9361, 
  25}, {-27.4331, -52.1161, 25}, {-28.4783, -51.845, 
  25}, {-27.8281, -52.9097, 24}, {-28.5006, -51.7036, 24}, {"", "", 
  ""}, {-29.7, -51.3247, 24}, {-28.6467, -54.1222, 
  24}, {-27.4331, -52.1161, 24}, {-28.8628, -51.5333, 
  24}, {-28.8808, -51.6975, 24}, {-27.9522, -52.015, 
  24}, {-28.7236, -51.7047, 24}, {-29.6917, -54.6794, 
  24}, {-29.4764, -51.4211, 24}, {-27.7347, -52.9922, 
  24}, {-27.7347, -52.9922, 24}, {-31.7719, -52.3425, 
  24}, {-28.5611, -51.9783, 24}, {-28.3875, -51.8481, 
  24}, {-29.1767, -53.1592, 24}, {-27.8561, -55.0164, 
  23}, {-29.0933, -52.5828, 23}, {-27.8903, -52.2275, 
  23}, {-28.5872, -52.2019, 23}, {-28.1272, -52.2961, 23}, {-29.1628, 
  -51.6317, 23}, {-27.5625, -53.1819, 23}, {-29.4481, -50.5836, 
  23}, {-27.8903, -52.2275, 23}, {-27.9889, -54.8394, 
  23}, {-27.9497, -51.8067, 23}, {-27.655, -54.7639, 
  23}, {-28.37, -51.6364, 23}, {-28.5114, -55.2278, 
  23}, {-27.3553, -53.9922, 23}, {-29.2975, -51.5036, 
  23}, {-28.7839, -51.61, 22}, {-28.5408, -51.6903, 
  22}, {-29.0289, -51.1817, 22}, {-28.1408, -54.5581, 
  22}, {-27.6342, -52.2739, 22}, {-27.9942, -52.9789, 
  22}, {-28.2686, -51.6897, 22}, {-27.7016, -52.426, 
  22}, {-30.1606, -53.5653, 22}, {-27.6, -53.0728, 
  22}, {-28.0461, -54.6806, 22}, {-29.7831, -55.7919, 
  22}, {-27.6539, -52.4881, 22}, {-28.0569, -51.8547, 
  22}, {-28.1309, -51.9268, 22}, {-28.5114, -55.2278, 
  22}, {-29.6692, -52.7889, 22}, {-28.1072, -52.1442, 
  22}, {-28.3294, -51.7675, 22}, {-28.0681, -52.0139, 
  22}, {-30.3364, -54.32, 22}, {-27.9231, -53.0392, 
  22}, {-27.9253, -51.5364, 22}, {-28.7572, -51.4728, 
  21}, {-28.1314, -55.0256, 21}, {-30.5969, -51.7522, 
  21}, {-27.6308, -53.2772, 21}, {-28.1264, -54.8353, 
  21}, {-30.1197, -51.9622, 21}, {-28.0642, -53.6972, 
  21}, {-31.4481, -53.1042, 21}, {-27.9083, -51.6447, 
  21}, {-28.2584, -54.8185, 21}, {-29.5128, -51.9853, 
  21}, {-27.4556, -53.9319, 21}, {-32.5661, -53.3758, 
  21}, {-27.7069, -53.1356, 21}, {-27.5842, -52.0942, 
  21}, {-27.3711, -53.7583, 21}, {-28.6247, -52.5114, 
  21}, {-27.8553, -52.3019, 21}, {-28.8583, -51.2828, 
  21}, {-27.6139, -53.7394, 21}, {-29.79, -50.435, 
  21}, {-29.5128, -51.9853, 21}, {-28.1836, -55.6389, 
  21}, {-28.1309, -51.9268, 21}, {-29.3833, -52.2686, 
  21}, {-28.8183, -52.5103, 21}, {-27.4706, -53.1689, 
  21}, {-28.3436, -51.8764, 21}, {-31.3653, -51.9783, 
  21}, {-27.6644, -53.6378, 21}, {-28.2992, -54.2631, 
  21}, {-28.2482, -54.6268, 21}, {-27.3289, -53.0586, 
  21}, {-27.6677, -52.6246, 21}, {-29.2914, -54.2239, 
  21}, {-27.4942, -53.6861, 21}, {-27.4792, -53.5236, 
  21}, {-27.4781, -53.4025, 21}, {-28.1769, -52.0339, 
  20}, {-27.6147, -52.8436, 20}, {-27.6308, -53.2772, 
  20}, {-28.1244, -54.8872, 20}, {-27.3003, -52.8408, 
  20}, {-29.3525, -54.0717, 20}, {-27.7327, -53.0568, 
  20}, {-28.8086, -51.7903, 20}, {-28.2253, -55.0458, 
  20}, {-27.9056, -55.1375, 20}, {-28.3933, -53.0947, 
  20}, {-30.3439, -53.8828, 20}, {-27.5203, -52.8833, 
  20}, {-28.6831, -50.7828, 20}, {-28.1311, -54.4633, 
  20}, {-29.3461, -53.3067, 20}, {-27.8747, -51.1733, 
  20}, {-28.6306, -51.5717, 20}, {-28.4492, -52.2, 
  20}, {-27.9367, -52.4264, 20}, {-27.7158, -52.6275, 
  20}, {-27.6753, -53.8033, 20}, {-29.2681, -52.5789, 
  19}, {-27.7289, -52.535, 19}, {-28.2086, -51.5258, 
  19}, {-27.9108, -52.26, 19}, {-27.5436, -53.8658, 
  19}, {-27.7106, -51.7606, 19}, {-28.7483, -53.0936, 
  19}, {-27.7739, -53.2504, 19}, {-28.1016, -51.39, 
  19}, {-27.7694, -51.5944, 19}, {-28.25, -54.0117, 
  19}, {-29.2735, -51.6875, 19}, {-28.8456, -51.8903, 
  19}, {-27.6072, -54.1069, 19}, {-28.3436, -51.8764, 
  19}, {-29.9897, -52.3781, 19}, {-28.4083, -54.9608, 
  19}, {-27.9439, -52.9231, 19}, {-28.9903, -51.4081, 
  19}, {-27.3003, -52.8408, 19}, {-27.4439, -52.9175, 
  19}, {-28.73, -54.9003, 19}, {-27.78, -53.1217, 
  19}, {-28.5122, -50.9339, 19}, {-28.3589, -54.2678, 
  19}, {-29.0239, -53.0642, 19}, {-28.8861, -52.9986, 
  18}, {-27.7667, -52.8019, 18}, {-29.8133, -53.375, 
  18}, {-27.9092, -53.1081, 18}, {-30.1914, -52.3736, 
  18}, {-27.1919, -53.71, 18}, {-28.7947, -51.0928, 
  18}, {-27.4539, -53.2464, 18}, {-27.9497, -51.8067, 
  18}, {-27.9797, -52.2597, 18}, {-27.6631, -53.3142, 
  18}, {-28.82, -51.2792, 18}, {-29.235, -52.7958, 
  18}, {-29.6692, -52.7889, 18}, {-28.1836, -55.6389, 
  18}, {-28.3511, -54.4964, 18}, {-29.0239, -53.0642, 
  18}, {-27.2647, -53.8608, 18}, {-27.3975, -54.0839, 
  18}, {-28.2394, -53.7708, 18}, {-28.4303, -52.0356, 
  18}, {-28.7739, -52.9906, 18}, {-28.0447, -55.1989, 
  18}, {-29.1681, -51.1794, 18}, {-27.7156, -53.7014, 
  17}, {-29.0858, -51.9917, 17}, {-30.8131, -53.895, 
  17}, {-28.8086, -51.7903, 17}, {-28.1272, -52.2961, 
  17}, {-28.2878, -54.6383, 17}, {-28.6286, -52.9525, 
  17}, {-27.8165, -52.4381, 17}, {-28.0536, -51.1903, 
  17}, {-28.1486, -54.7381, 17}, {-27.8333, -54.1883, 
  17}, {-27.9228, -53.9414, 17}, {-27.6717, -51.4606, 
  17}, {-28.5628, -54.5542, 17}, {-29.3461, -53.3067, 
  17}, {-28.6467, -54.1222, 17}, {-27.6258, -54.3078, 
  17}, {-28.2783, -52.1917, 17}, {-28.6261, -52.87, 
  17}, {-28.7947, -51.0928, 17}, {-29.7017, -51.2419, 
  17}, {-27.8708, -54.4814, 17}, {-28.7247, -52.8497, 
  17}, {-27.3617, -52.7714, 17}, {-27.7733, -54.24, 
  16}, {-30.2578, -50.5097, 16}, {-28.0308, -54.5431, 
  16}, {-27.5669, -51.6678, 16}, {-29.2269, -53.6817, 
  16}, {-28.6678, -50.4167, 16}, {-28.3142, -51.1817, 
  16}, {-28.1408, -54.5581, 16}, {-28.6922, -52.6922, 
  16}, {-28.3878, -53.9147, 16}, {-30.5439, -52.5219, 
  16}, {-32.0236, -53.3956, 16}, {-27.5281, -52.7325, 
  16}, {-30.0331, -51.23, 16}, {-28.7483, -53.0936, 
  16}, {-27.6569, -54.4403, 16}, {-29.1031, -52.9561, 
  16}, {-32.2375, -53.0869, 16}, {-30.2583, -54.9142, 
  16}, {-28.3961, -52.6911, 16}, {-27.8328, -54.0614, 
  16}, {-29.0883, -53.2125, 16}, {-28.0553, -53.0678, 
  16}, {-28.0283, -54.3497, 16}, {-28.1189, -52.7825, 
  16}, {-29.4675, -51.2008, 16}, {-28.5169, -53.9922, 
  15}, {-27.6677, -52.6246, 15}, {-28.6275, -53.0897, 
  15}, {-28.3831, -54.0656, 15}, {-29.9592, -51.7222, 
  15}, {-28.2628, -52.4067, 15}, {-29.6453, -53.24, 
  15}, {-28.1025, -52.9187, 15}, {-29.6789, -51.0533, 
  15}, {-31.8564, -52.8128, 15}, {-28.6467, -54.1222, 
  15}, {-27.5492, -53.5042, 15}, {-27.8328, -54.0614, 
  15}, {-30.3385, -54.0707, 15}, {-27.7872, -53.9369, 
  15}, {-29.5378, -53.8547, 15}, {-29.2269, -53.6817, 
  15}, {-29.0933, -52.5828, 15}, {-28.25, -54.0117, 
  15}, {-28.5261, -54.1492, 14}, {-28.0592, -52.6772, 
  14}, {-28.5358, -52.4642, 14}, {-28.5239, -52.9942, 
  14}, {-27.7564, -54.4817, 14}, {-30.0392, -52.8939, 
  14}, {-30.2911, -51.3011, 14}, {-28.2686, -51.6897, 
  14}, {-29.3694, -49.8497, 14}, {-28.7953, -55.2353, 
  14}, {-28.4592, -52.8208, 14}, {-27.7156, -53.7014, 
  14}, {-27.4242, -52.6731, 14}, {-28.5708, -52.8578, 
  14}, {-28.25, -54.0117, 14}, {-29.905, -51.7603, 
  14}, {-27.6592, -53.5314, 14}, {-28.5824, -52.5996, 
  14}, {-27.8831, -54.0169, 14}, {-29.0239, -53.0642, 
  14}, {-31.3314, -54.1069, 14}, {-28.1825, -55.2672, 
  14}, {-28.0553, -53.0678, 14}, {-29.2735, -51.6875, 
  14}, {-30.1267, -52.0475, 14}, {-28.7972, -53.2228, 
  13}, {-28.3933, -53.0947, 13}, {-28.5603, -52.7483, 
  13}, {-28.5169, -53.9922, 13}, {-28.6275, -53.0897, 
  13}, {-28.6467, -54.1222, 13}, {-27.6894, -53.1817, 
  13}, {-27.5736, -54.5053, 13}, {-29.8175, -50.5197, 
  13}, {-28.4989, -52.5733, 13}, {-27.8508, -53.7772, 
  13}, {-28.4233, -53.6558, 13}, {-29.8567, -51.2739, 
  13}, {-30.1606, -53.5653, 13}, {-28.0642, -53.6972, 
  13}, {-28.3961, -52.6911, 13}, {-27.8994, -53.3136, 
  12}, {-29.1917, -54.8672, 12}, {-28.2839, -52.7864, 
  12}, {-28.9215, -54.7009, 12}, {-33.5189, -53.3681, 
  12}, {-27.5753, -54.6681, 12}, {-27.3975, -54.0839, 
  12}, {-28.3583, -53.2472, 12}, {-29.0806, -53.8358, 
  12}, {-27.6347, -53.9456, 11}, {-29.4975, -54.69, 
  11}, {-31.8642, -52.8233, 11}, {-28.3685, -53.7706, 
  11}, {-28.585, -53.7993, 11}, {-28.6386, -53.6064, 
  11}, {-28.2925, -53.5017, 11}, {-30.7042, -52.1075, 
  11}, {-27.9942, -52.9789, 10}, {-29.7175, -52.4258, 
  10}, {-28.2078, -53.4872, 10}, {-29.5503, -55.1311, 
  10}, {-30.0392, -52.8939, 9}, {-29.0883, -53.2125, 
  9}, {-29.5892, -55.4828, 9}, {-30.5122, -53.4914, 
  8}, {-31.5783, -53.3811, 7}, {-29.0883, -53.2125, 
  7}, {-28.8191, -53.3875, 7}, {-29.8836, -54.825, 
  6}, {-29.3508, -51.6758, 6}, {-30.0811, -51.0233, 
  5}, {-31.1069, -50.9211, 5}, {-29.6886, -51.4611, 
  5}, {-29.6783, -51.1306, 4}, {-30.8908, -55.5328, 
  3}, {-29.6206, -54.1789, 3}, {-30.2578, -50.5097, 2}}
POSTED BY: André Reis
4 Replies
Posted 10 years ago

Now, following your ideas trying with two states this plot resulted in this:

pol1 = AdministrativeDivisionData[ Entity["AdministrativeDivision", {"RioGrandeDoSul", "Brazil"}], "Polygon"][[1, 1, 1]]

pol2 = AdministrativeDivisionData[ Entity["AdministrativeDivision", {"SantaCatarina", "Brazil"}], "Polygon"][[1, 1, 2]]

data1 = Union[pol1, pol2]

MeshRegion[Reverse /@ data1, Line[Append[Range[Length[data1]], 1]]]

My best try to fix but it was far from what I was looking for.

data2 = data1[[Delete[Flatten@FindShortestTour[data1], {{1}, {-1}}]]]

MeshRegion[Reverse /@ data2, Line[Append[Range[Length[data2]], 1]]]

Thank you for your last replies.

POSTED BY: André Reis

I had to edit your data. I removed the {"", "", ""} data point first. Also, in your data there are multiple values in some locations. I averaged the values. Then we should be ready for the following plot:

pol = AdministrativeDivisionData[
    Entity["AdministrativeDivision", {"RioGrandeDoSul", "Brazil"}], 
    "Polygon"][[1, 1, 1]];
reg = BoundaryMeshRegion[Map[Reverse, pol], 
   Line[Append[Range[Length[pol]], 1]]];
interp = Interpolation[
   Values@Map[Mean, GroupBy[data[[All, {2, 1, 3}]], Most] ], 
   InterpolationOrder -> 1];
DensityPlot[interp[x, y], {x, y} \[Element] reg]

I don't know a way of giving a region directly to ListDensityPlot, so I resorted to explicit interpolation fed into DensityPlot.

POSTED BY: Gianluca Gorni
Posted 10 years ago

Swapping column 1 for column 2 and GeoGraphics for Graphics, it's more what I am looking for

data[[All,{1,2}]]=data[[All,{2,1}]];

p1=ListContourPlot[data,Frame->False,ColorFunction->"ThermometerColors",PlotLegends->Automatic,PlotRange->All];

p2=Graphics[{FaceForm[],EdgeForm[Directive[Black]],AdministrativeDivisionData[Entity["AdministrativeDivisonData",{"RioGrandeDoSul","Brazil"}],"Polygon"]}];

Show[p1,p2]

Which is the best way to do so?

Thank you for your time =D

POSTED BY: André Reis

This works somehow, although with washed-out colors:

GeoGraphics[{Normal[p1[[1]]] /. (primt : (Line | Polygon))[pts_] :> 
    primt[GeoPosition[pts]], {FaceForm[], 
   EdgeForm[Directive[Black, Opacity[2]]], 
   AdministrativeDivisionData[
       Entity[
     "AdministrativeDivision", {"RioGrandeDoSul", "Brazil"}], 
    "Polygon"]}}]

I wonder if GeoGraphics accepts GraphicsComplex inputs.

POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard