Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #1610 from strk/2.1.x-whole-centroid

Fix "whole" multi centroid computation (#1606)
  • Loading branch information...
commit 3ec3a7cd665d208da2c7c7ea68e0b7d5e0c48ffb 2 parents 9728f34 + e9cb647
@springmeyer springmeyer authored
View
13 include/mapnik/geom_util.hpp
@@ -340,12 +340,10 @@ bool centroid_geoms(Iter start, Iter end, double & x, double & y)
double start_x = x0;
double start_y = y0;
- bool empty = true;
-
double atmp = 0.0;
double xtmp = 0.0;
double ytmp = 0.0;
- unsigned count = 1;
+ unsigned count = 0;
while (start!=end)
{
@@ -353,7 +351,11 @@ bool centroid_geoms(Iter start, Iter end, double & x, double & y)
path.rewind(0);
unsigned command = path.vertex(&x0, &y0);
if (command == SEG_END) continue;
- empty = false;
+
+ if ( ! count++ ) {
+ start_x = x0;
+ start_y = y0;
+ }
while (SEG_END != (command = path.vertex(&x1, &y1)))
{
@@ -369,9 +371,10 @@ bool centroid_geoms(Iter start, Iter end, double & x, double & y)
y0 = y1;
++count;
}
+
}
- if ( empty ) return false;
+ if (count == 0) return false;
if (count <= 2) {
x = (start_x + x0) * 0.5;
View
2  tests/visual_tests/data/whole-centroid.csv
@@ -0,0 +1,2 @@
+i|wkt
+1|MULTIPOLYGON(((1350057.96009438 5942345.52058283,1384876.13646624 5891754.2133652,1527153.68896859 5865144.36766544,1489794.86785838 5828107.21457916,1521644.71000822 5808839.16705438,1500586.73589334 5782129.46376012,1549474.58270654 5722446.94649062,1526963.22131985 5715859.64352432,1468675.11142609 5744853.11521536,1367157.74707515 5695509.5055605,1353768.57268098 5663160.88833932,1395853.46277285 5615400.34143299,1363168.83576153 5576894.81504537,1376836.42020216 5503694.0028362,1516356.92287605 5396662.575031,1560328.12173938 5261876.31080913,1640818.23615492 5173802.74601002,1796912.65253506 5148129.98779792,1773597.67574436 5083111.70893878,2005049.37613903 4960037.26198969,2060770.68121407 4885821.98463312,2042650.53978071 4835753.32622244,1988073.15379307 4907241.27057499,1882814.34135654 4930901.063827,1835287.04135981 4832212.44229475,1909252.60910046 4777690.54700568,1911262.92778469 4716420.6995481,1847346.61575592 4693181.77244718,1788068.875589 4568718.26175616,1740109.09937055 4581073.81722757,1805880.43939388 4708906.48580766,1744005.2815483 4870423.42300908,1235522.56053157 5220039.63151647,1125161.53055404 5466602.89896275,973921.757167397 5532097.82173426,838019.24926376 5432786.3871293,852954.651385017 5491916.6901273,776607.959736312 5509523.04321204,782761.478548388 5595015.13624148,736908.312373676 5638877.1573602,793460.506128018 5662194.42680345,756857.878318762 5745270.82868898,783472.587455564 5769448.93739922,874497.199243332 5767386.72200479,939134.416294499 5854912.10535634,1005956.9462694 5754390.71173147,1033261.27965169 5860165.00562569,1127666.33041638 5816836.29071798,1118791.82929085 5867309.80784728,1164989.30665057 5868344.65660203,1165652.54817671 5921100.82966656,1350057.96009438 5942345.52058283),(1386948.01482887 5449379.17151171,1392606.60718488 5463421.03119553,1382120.31115215 5458937.77184712,1386948.01482887 5449379.17151171),(1385381.11851082 5146477.94829492,1386669.06721543 5146224.9584086,1386111.70929647 5147206.59661607,1385381.11851082 5146477.94829492)),((1382897.20987839 5687974.04417046,1371857.98993491 5675822.90372079,1377393.1289756 5689163.60754804,1382897.20987839 5687974.04417046)),((1095847.54640445 5317215.2838641,1091704.01231816 5313451.44710224,1091394.65545324 5321701.46563701,1094455.94145006 5323479.01597989,1095847.54640445 5317215.2838641)),((1162299.15983606 5288324.53042776,1160289.06379081 5267765.62824438,1124543.26210218 5277407.73480368,1162299.15983606 5288324.53042776)),((1123028.09251298 5247084.38946664,1122316.87228631 5254141.60947014,1124512.20396424 5250317.54284925,1123028.09251298 5247084.38946664)),((1215144.97114443 5209828.83212963,1209640.77892215 5214848.8689761,1210908.5966028 5219286.46510058,1215144.97114443 5209828.83212963)),((1148446.00580429 5208658.24432317,1145817.64130717 5213552.48912728,1149497.41839483 5212548.16532901,1148446.00580429 5208658.24432317)),((1059019.27398736 5033998.10699295,1093806.61486026 4942691.99568292,1065234.68643633 4743259.71214946,1003916.12604469 4759901.51823648,986197.736653606 4704377.88889769,935856.725207561 4715744.68629496,952523.590688621 4846503.91226084,911984.817004403 4999606.76073705,1059019.27398736 5033998.10699295)),((928311.824080081 5021563.59386512,914520.452365687 5011234.44611049,926301.728034833 5030262.29618597,928311.824080081 5021563.59386512)),((1443164.46899898 4995230.22633471,1441618.24127186 5000220.31310592,1445823.55767554 5002226.81825718,1443164.46899898 4995230.22633471)),((1553061.29669992 4968395.29665014,1542207.75766705 4973291.02362767,1552690.38015659 4974433.31609162,1553061.29669992 4968395.29665014)),((1581911.63517033 4947738.11891254, 1587632.34380218 4947004.77788114,1580427.52371907 4944237.33055168,1581911.63517033 4947738.11891254)),((923085.819265294 4735088.56864719,915479.024500905 4745293.69583645,924260.796490606 4748923.38178062,923085.819265294 4735088.56864719)),((1693571.31832746 4688858.4894456,1690973.90064878 4691713.90965507,1696416.19923417 4693935.9965921,1693571.31832746 4688858.4894456)),((1466448.61029075 4677403.01590106,1465211.85074803 4680849.56314581,1469231.59756058 4680414.29421003,1466448.61029075 4677403.01590106)),((1655135.14718535 4654767.34922581,1646940.91946804 4659946.37928978,1655166.09400377 4661409.67928983,1655135.14718535 4654767.34922581)),((1664813.70899286 4642559.56041499,1660020.95963625 4652672.28390196,1665772.39244759 4652790.51476716,1664813.70899286 4642559.56041499)),((1668555.37971741 4630998.75869634,1663236.86840579 4636007.55629286,1665215.68367412 4640507.06235257,1668555.37971741 4630998.75869634)),((1728668.01606527 4598788.94471507,1679439.97688818 4506146.77040914,1705043.45977066 4440345.73224938,1678852.4326158 4390316.66779138,1382835.42756099 4550662.053593,1482404.47818411 4610314.59733156,1532745.60094962 4575266.49172867,1728668.01606527 4598788.94471507)),((1344059.17537453 4572873.96816367,1339173.36292359 4577580.75464391,1342420.21851156 4577895.44505675,1344059.17537453 4572873.96816367)),((1375259.46829558 4566170.07673534,1366044.55216722 4570443.18173048,1373589.78725316 4570168.66006012,1375259.46829558 4566170.07673534)),((1337596.41101701 4402695.43852239,1328134.14298011 4415398.45409661,1341214.18314831 4410841.06668909,1337596.41101701 4402695.43852239)))
View
BIN  tests/visual_tests/images/whole-centroid-600-reference.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
21 tests/visual_tests/styles/whole-centroid.xml
@@ -0,0 +1,21 @@
+<Map maximum-extent="736908, 4390316, 2060771, 5942346">
+<Style name="whole">
+ <Rule>
+ <MarkersSymbolizer placement="point" multi-policy="whole" fill="yellow" width="20" allow-overlap="true"/>
+ </Rule>
+</Style>
+<Style name="boundary">
+ <Rule>
+ <LineSymbolizer />
+ </Rule>
+</Style>
+<Layer name="multi">
+ <StyleName>boundary</StyleName>
+ <StyleName>whole</StyleName>
+ <Datasource>
+ <Parameter name="type">csv</Parameter>
+ <Parameter name="file">../data/whole-centroid.csv</Parameter>
+ <Parameter name="separator">|</Parameter>
+ </Datasource>
+ </Layer>
+</Map>
View
2  tests/visual_tests/test.py
@@ -28,6 +28,8 @@
{'name': "lines-3", 'sizes': sizes_few_square},
{'name': "lines-shield", 'sizes': sizes_few_square},
{'name': "marker-multi-policy", 'sizes':[(600,400)]},
+ {'name': "whole-centroid", 'sizes':[(600,400)],
+ 'bbox': mapnik.Box2d(736908, 4390316, 2060771, 5942346)},
{'name': "simple-E"},
{'name': "simple-NE"},
{'name': "simple-NW"},
Please sign in to comment.
Something went wrong with that request. Please try again.