def clusters(self, maxpoints=1000000, **kwargs): """Computes clusters using centroids of geometries. Parameters: max_points (int): The maximum number of features that will be used for the cluster computation. **kwargs: Additional optional arguments for clustering. See clustering.Clustering. Returns: (object) A Clustering object. """ if not self._has_geometry: warnings.warn('DataFrame is not spatial.') return None if maxpoints is not None and maxpoints < len(self.df): pois = self.df.sample(n=maxpoints) else: pois = self.df.copy() pois.constructive.centroid(inplace=True) geom = pois.geometry.to_pygeos().values() filt = pg.get_coordinate_dimension(geom) pois.add_column('tmp', filt, dtype=int) pois = pois[pois.tmp == 2] pois.drop('tmp', inplace=True) pois = pois.extract() return Clustering(pois, **kwargs)
def test_get_coordinate_dimension(): actual = pygeos.get_coordinate_dimension([point, point_z, None]).tolist() assert actual == [2, 3, -1]
def test_apply_correct_coordinate_dimension(): # ensure that new geometry is 2D with include_z=False geom = line_string_z assert pygeos.get_coordinate_dimension(geom) == 3 new_geom = apply(geom, lambda x: x + 1, include_z=False) assert pygeos.get_coordinate_dimension(new_geom) == 2