Repository: martinfleis/momepy
Pull request #151 (2020-03-06 15:01:46)

BUG: CentroidCorner may fail for Polygon Z
Polygon Z support for circular buildings

codecov[bot]: # [Codecov](https://codecov.io/gh/martinfleis/momepy/pull/151?src=pr&el=h1) Report
> Merging [#151](https://codecov.io/gh/martinfleis/momepy/pull/151?src=pr&el=desc) into [master](https://codecov.io/gh/martinfleis/momepy/commit/6d65bac2bb049397f82481d061c906f2a19ba761?src=pr&el=desc) will **decrease** coverage by `0.02%`.
> The diff coverage is `80%`.

[![Impacted file tree graph](https://codecov.io/gh/martinfleis/momepy/pull/151/graphs/tree.svg?width=650&token=i04999UxkK&height=150&src=pr)](https://codecov.io/gh/martinfleis/momepy/pull/151?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #151      +/-   ##
==========================================
- Coverage   93.61%   93.58%   -0.03%     
==========================================
  Files           9        9              
  Lines        2505     2509       +4     
==========================================
+ Hits         2345     2348       +3     
- Misses        160      161       +1
```


| [Impacted Files](https://codecov.io/gh/martinfleis/momepy/pull/151?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [momepy/shape.py](https://codecov.io/gh/martinfleis/momepy/pull/151/diff?src=pr&el=tree#diff-bW9tZXB5L3NoYXBlLnB5) | `95.78% <80%> (-0.2%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/martinfleis/momepy/pull/151?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/martinfleis/momepy/pull/151?src=pr&el=footer). Last update [6d65bac...a502d43](https://codecov.io/gh/martinfleis/momepy/pull/151?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/momepy/shape.py b/momepy/shape.py
index e36ea4f..a02c3b5 100644
--- a/momepy/shape.py
+++ b/momepy/shape.py
@@ -1174,9 +1174,14 @@ class CentroidCorners:
             if not distances:  # circular buildings
                 from momepy.dimension import _longest_axis
 
-                results_list.append(
-                    _longest_axis(row["geometry"].convex_hull.exterior.coords) / 2
-                )
+                geom = row["geometry"]
+                if geom.has_z:
+                    coords = [
+                        (coo[0], coo[1]) for coo in geom.convex_hull.exterior.coords
+                    ]
+                else:
+                    coords = geom.convex_hull.exterior.coords
+                results_list.append(_longest_axis(coords) / 2)
                 results_list_sd.append(0)
             else:
                 results_list.append(np.mean(distances))  # calculate mean


Test patch:
diff --git a/tests/test_shape.py b/tests/test_shape.py
index a0440ff..ac102c0 100644
--- a/tests/test_shape.py
+++ b/tests/test_shape.py
@@ -191,6 +191,12 @@ class TestShape:
 
     def test_CentroidCorners(self):
         self.df_buildings.loc[144] = [145, Point(0, 0).buffer(10), 0, 0]
+        self.df_buildings.loc[145] = [
+            145,
+            Polygon([s + (0,) for s in Point(0, 0).buffer(10).exterior.coords]),
+            0,
+            0,
+        ]
         cc = mm.CentroidCorners(self.df_buildings)
         self.df_buildings["ccd"] = cc.mean
         self.df_buildings["ccddev"] = cc.std