Questions tagged [centroid]

Centroid refers to the center of a geometric shape. It may also refer to the center of a clustered point-cloud.

Centroid is the center of a geometric shape. Also known as its center of mass.
See Wikipedia for more information.

310 questions
41
votes
4 answers

Locating the centroid (center of mass) of spherical polygons

I'm trying to work out how best to locate the centroid of an arbitrary shape draped over a unit sphere, with the input being ordered (clockwise or anti-cw) vertices for the shape boundary. The density of vertices is irregular along the boundary, so…
Nordlendingen
  • 623
  • 6
  • 12
25
votes
1 answer

How to calculate centroid of polygon using sf::st_centroid?

I am trying to manipulate some Brazilian Census data in R using the new "sf" package. I am able to import the data, but I get an error when I try to create the centroids of the original polygons library(sf) #Donwload data filepath <-…
LucasMation
  • 2,408
  • 2
  • 22
  • 45
20
votes
1 answer

How to get Agglomerative Clustering "Centroid" in python Scikit-learn

This code is what I am using for silhouette_score. And in here I am using Agglomerative Clustering, linkage as Ward. I would like to get "Centroid" of Agglomerative Clustering, would it be possible from Agglomerative Clustering? I could only get…
Pandalove
  • 201
  • 1
  • 2
  • 3
13
votes
6 answers

Better "centerpoint" than centroid

I'm using the centroid of polygons to attach a marker in a map application. This works definitely fine for convex polygons and quite good for many concave polygons. However, some polygons (banana, donut) obviously don't produce the desired result:…
user2033412
  • 1,950
  • 2
  • 27
  • 47
12
votes
5 answers

How to Calculate Centroid

I am working with geospatial shapes and looking at the centroid algorithm here, http://en.wikipedia.org/wiki/Centroid#Centroid_of_polygon I have implemented the code in C# like this (which is just this adapted), Finding the centroid of a…
peter
  • 13,009
  • 22
  • 82
  • 142
11
votes
4 answers

OpenCV 2 Centroid

I am trying to find the centroid of a contour but am having trouble implementing the example code in C++ (OpenCV 2.3.1). Can anyone help me out?
keshavdv
  • 315
  • 3
  • 5
  • 10
9
votes
1 answer

Calculate Centroid WITHIN / INSIDE a SpatialPolygon

In Software like ArcMap one can create centroids for polygons within a polygon. In cases like the one shown below this is necessary. In R it is possible to calculate centroids of spatial polygons with rgeos::gCentroid(). However there is no way to…
loki
  • 9,816
  • 7
  • 56
  • 82
9
votes
4 answers

Calculating weighted polygon centroids in R

I need to calculate the centroids of a set of spatial zones based on a separate population grid dataset. Grateful for a steer on how to achieve this for the example below. Thanks in advance. require(raster) require(spdep) require(maptools) dat <-…
geotheory
  • 22,624
  • 29
  • 119
  • 196
9
votes
3 answers

How to calculate centroid of x,y coordinates in python

I have got a lot of x,y coordinates which I have clustered based on the distance between them. Now I would like to calculate a centroid measure for each cluster of x,y coordinates. Is there a way to do this? My coordinates are in the format: …
Martin Petri Bagger
  • 2,187
  • 4
  • 17
  • 20
8
votes
1 answer

Do the values returned by rgeos::gCentroid() and sf::st_centroid() differ?

Question Do the values returned by rgeos::gCentroid() and sf::st_centroid() differ? If so, how? Context After reading the relevant commands exported by rgeos section within the r-spatial/sf wiki, I was thrilled to see that I only needed the sf…
Cristian E. Nuno
  • 2,822
  • 2
  • 19
  • 33
7
votes
2 answers

r sf package centroid within polygon

I need to add labels to polygons and I normally use the centroid, however the centroid does not fall inside the polygon. I found this question Calculate Centroid WITHIN / INSIDE a SpatialPolygon but I'm using the sf package. Below is a toy…
user3357059
  • 1,122
  • 1
  • 15
  • 30
7
votes
4 answers

how to choose initial centroids for k-means clustering

I am working on implementing k-means clustering in Python. What is the good way to choose initial centroids for a data set? For instance: I have following data set: A,1,1 B,2,1 C,4,4 D,4,5 I need to create two different clusters. How do i start…
Clint Whaley
  • 459
  • 2
  • 7
  • 18
7
votes
2 answers

R - add centroids to scatter plot

I have a dataset two continuous variables and one factor variable (two classes). I want to create a scatterplot with two centroids (one for each class) that includes error bars in R. The centroids should be positioned at the mean values for x and y…
cyril
  • 2,976
  • 5
  • 19
  • 26
7
votes
2 answers

OpenCV Centroid of Irregular Shape

how do you get the centroid of an irregular shape using OpenCV?
Og Namdik
  • 823
  • 4
  • 14
  • 22
6
votes
1 answer

How to find cluster centroid with Scikit-learn

I have a data set with (labeled) clusters. I'm trying to find the centroids of each cluster (a vector that his distance is the smallest from all data points of the cluster). I found many solutions to perform clustering and only then find the…
sheldonzy
  • 5,505
  • 9
  • 48
  • 86
1
2 3
20 21