centroid

How to calculate centroid of x,y coordinates in python

梦想的初衷 提交于 2019-12-10 19:52:23
问题 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: coordinates_cluster = [[x1,x2,x3,...],[y1,y2,y3,...]] Each cluster has a minimum length of three points, and all points can have both negative and positive x and y values. I hope that someone can help me. Best, Martin (I am using python 2.7 with canopy 1

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

萝らか妹 提交于 2019-12-10 19:07:08
问题 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 package - and no longer needed to import the rgeos package - to calculate the centroid of a given geometry. However, the use of sf::st_centroid() gave me this warning, which is addressed here: Warning message: In st_centroid.sfc(x = comarea606$geometry)

OpenCV Centroid of Irregular Shape

偶尔善良 提交于 2019-12-08 18:51:21
问题 how do you get the centroid of an irregular shape using OpenCV? 回答1: I'd recommend looking at the cv::Moments (C++) or cvMoments (C) function. This StackOverflow thread gives some example code for a problem very similar to yours. This post goes into some of the theory related to finding object center-points. 回答2: What do you mean by centroid? If it's the center of mass, you can compute the average of the coordinates of the points that are inside your shape. But the center of mass can be

how to set initial centers of K-means openCV c++

早过忘川 提交于 2019-12-06 11:27:22
I am trying to do a segmentation of an image using OpenCv and Kmeans, the code that I have just implemented is the following: #include "opencv2/objdetect/objdetect.hpp" #include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp" #include <iostream> #include <stdio.h> using namespace std; using namespace cv; int main(int, char** argv) { Mat src, Imagen2, Imagris, labels, centers,imgfondo; src = imread("C:/Users/Sebastian/Documents/Visual Studio 2015/Projects/ClusteringImage/data/leon.jpg"); imgfondo = imread("C:/Users/Sebastian/Documents/Visual Studio 2015/Projects

R - add centroids to scatter plot

社会主义新天地 提交于 2019-12-03 14:46:53
问题 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 for each class. I can easily create the scatter plot using ggplot2, but I can't figure out how to add the centroids. Is it possible to do this using ggplot / qplot? Here is some example code: x <- c(1,2,3,4,5,2,3,5) y <- c(10,11,14,5,7,9,8,5) class

Calculating weighted polygon centroids in R

女生的网名这么多〃 提交于 2019-12-01 18:07:33
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 <- raster(volcano) # simulated population data polys <- readShapePoly(system.file("etc/shapes/columbus.shp",package="spdep")[1]) # set consistent coordinate ref. systems and bounding boxes proj4string(dat) <- proj4string(polys) <- CRS("+proj=longlat +datum=NAD27") extent(dat) <- extent(polys) # illustration plot plot(dat, asp = TRUE) plot(polys, add =

Calculating weighted polygon centroids in R

纵饮孤独 提交于 2019-12-01 17:13:41
问题 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 <- raster(volcano) # simulated population data polys <- readShapePoly(system.file("etc/shapes/columbus.shp",package="spdep")[1]) # set consistent coordinate ref. systems and bounding boxes proj4string(dat) <- proj4string(polys) <- CRS("+proj=longlat

Calculate longitude/latitude for geographic centroid

陌路散爱 提交于 2019-12-01 13:47:32
问题 I want to do some spatial statistic analysis with the county-level crop yield data in Nebraska for the STAT class. For that I need the longitude and latitude of the geographic centroids of each county. Anybody know how to do it in R? I know it can be done in ArcGIS but I have no access to it now. 回答1: You didn't give any details where you got your shapefile from, but I got one from here and you can use gCentroid from rgeos thusly: library(rgdal) library(sp) library(rgeos) nebraska <- readOGR(

how to calculate centroid of an arraylist of points

南楼画角 提交于 2019-12-01 06:30:19
I am trying to add up all the x and y coordiantes respectively from points of ArrayList. public static ArrayList knots = new ArrayList<Point>(); public Point centroid() { Point center = new Point(); for(int i=0; i<knots.size(); i++) { ???????????????????? return center; } How do I find the centroid ?? public Point centroid() { double centroidX = 0, centroidY = 0; for(Point knot : knots) { centroidX += knot.getX(); centroidY += knot.getY(); } return new Point(centroidX / knots.size(), centroidY / knots.size()); } public Point centroid() { Point center = new Point(); int sumofx=0,sumofy=0; for

how to calculate centroid of an arraylist of points

给你一囗甜甜゛ 提交于 2019-12-01 04:11:21
问题 I am trying to add up all the x and y coordiantes respectively from points of ArrayList. public static ArrayList knots = new ArrayList<Point>(); public Point centroid() { Point center = new Point(); for(int i=0; i<knots.size(); i++) { ???????????????????? return center; } How do I find the centroid ?? 回答1: public Point centroid() { double centroidX = 0, centroidY = 0; for(Point knot : knots) { centroidX += knot.getX(); centroidY += knot.getY(); } return new Point(centroidX / knots.size(),