The Stack Overflow podcast is back! Listen to an interview with our new CEO.

# Questions tagged [centroids]

In geometry, the centroid, geometric center, or barycenter of a plane figure or two-dimensional shape X is the intersection of all straight lines that divide X into two parts of equal moment about the line. Informally, it is the "average" (arithmetic mean) of all points of X. The definition extends to any object X in n-dimensional space: its centroid is the intersection of all hyperplanes that divide X into two parts of equal moment.

156 questions
Filter by
Sorted by
Tagged with
34 views

### Speedup function to calculate distance from centroid of building to river segment in PostgreSQL

I am trying to measure the distance from the centroid of a building to a river segment using the following function. CREATE OR REPLACE FUNCTION river_foo_mapper () RETURNS trigger LANGUAGE plpgsql AS ...
28k views

### List of central coordinates (centroid) for all countries?

I need a list of the central points (centroid) for all countries: China: lat/long (coordinates of the most central point in China) France: lat/long (coordinates of the most central point in France) ...
94 views

### R sf extrapolate grid from centroids

I've got a grid/raster in R that is represented as centroids of the grid instead of polygons. I am trying to merge that with points. library(sf) nc <- st_read(system.file("shape/nc.shp", package="...
1k views

### Centroids of each grid cell

I have a grid created by mean the following script: # My grid [using package 'sf'] worldGrid <- st_make_grid(x = worldMap, what = "polygons", cellsize = 10) worldGrid <- st_sf(idcell = 1:length(...
10k views

### Calculating Centroid of all lands of Earth using SQL Server Spatial?

I want to find the center point of all lands of the earth. What I have tried up to now is downloading shapefile of all countries and polar parts of the earth. Then I imported that shapefile into a ...
62 views

### Finding coordinates of centroids?

I have a few thousands of polygons, which I found the centroid for each one of them. Now I want to find the coordinates of each centroid. But for some reason the x and y columns are empty and I don't ...
525 views

### Rasterize in QGIS using point as centroid (not vertex)

I'm attempting to make the full switch from ArcGIS to QGIS, but there are a few snags I'm hitting along the way, one of which is in the GDAL "Rasterize" function. My process goes like this: I have a ...
17 views

### Real Centroids plugin QGis 3.4.4 Inavlid Geometry?

The plugin gives on a specific feature the following error message: "Invalid or empty geometries found". Is the following topology not supported?
25 views

### Spatial Join Polygon to Polygon with Centroids Inside features

I have a parcel feature class with +5M features. I want to spatially join it to a feature class of regions to check if the regional code matches that in the parcel data. I've tried using "have their ...
438 views

### QGIS weighted centroid of polygons with weights from raster layer

I am a total novice with GIS and using QGIS as that is what is available to me. I have a vector layer of polygons (about 3500) and a raster layer of light intensity. What I'm working with looks like ...
62 views

### Making path between polygon using QGIS?

I am trying to draw a line (vector layer) of a certain length that that tries as much as possible to dodge the green polygons. Assuming a starting point, is there some sort of line centroid ...
237 views

### Finding census block with highest pop. value within census tract using QGIS?

In QGIS, I'm trying to plot a centroid of only the census block with the highest population within each census tract. So there should only be one point per tract- that of the block with the greatest ...
2k views

### Calculate centre point of SpatialGrid object

I am using R and have a SpatialGrid object similar to the example from this question: Overlay a spatial polygon with a grid and check in which grid element specific coordinates are located ## read ...
51 views

### Combining st_snaptogrid with st_centroid and group by using PostGIS?

I have a table of devices, each of them has a field 'location' that is a postGis geometry(Point,4326) I need to operate a GROUP BY based of the placement on a grid, I'd use ST_SnapToGrid and then I ...
64 views

### Displaying a legend for a centroid, simple marker with size overwrite?

I am new to QGIS and can't figure out how to display a legend for the dot size of a centroid, simple marker. The size of the dot is dependent on a value from a CSV linked to a layer map of Europe. I ...
58 views

### Geoserver SLD: How to get CENTROID of result of INTERSECTION?

In my GeoServer SLD I need to place a symbol (particularly a piechart) exactly on Centroid of the result of Intersection of 2 geometry: geom field from my PostGIS table AND environment variable ...
25 views

### How is the Point on surface tool calculated in QGIS [duplicate]

I am interested to know how the Point on surface tool works in QGIS 3. I am choosing to use this rather than the Centroids tool which works of the "center of mass" methodology because this creates a ...
28 views

### Computing center and zoom level for a set of points

I need to duplicate google's static map image API api on an internal server with no internet access using OpenStreetMaps. I did find the OSM Wiki Page covering this topic. I initially looked at OSM ...
550 views

### Creating centerline of river in QGIS? [duplicate]

I made two river bank lines and I want to associate them. I want to make a centerline using two rows as a base. I managed to make the centre line with a lot of work creating several lines from one ...
8k views

### How to get the centroid of a set of points in PostGIS?

I use PostgreSQL with the PostGIS extension. I have a set of points in the_geom column from a table myschema.myobjects. I want to create a select statement to get the centroid of this cluster, so ...
33 views

### Centroids: Based on travel distance/time and not straight line distances

I am working on a Sales Person Deployment project and quite often come across requests for calculating centroid of a territory where work is distributed across 1000s of ZIP codes. Increasingly we get ...
95 views

### Calculate weighted centroid of a raster layer using GRASS?

I'm trying to calculate the weighted centroid of some raster layers I have, which are basically patches of positive values in a sea of null values. I know I could convert thoses patches to binary ...
29 views

### NHGIS census files get lat/lon from polygon

I've never worked with shapefiles before and I'm having a lot of trouble with something that I think should be pretty simple. So I have the census tract files from NHGIS for 1980 and the structure ...
32 views

### How to compare centrality of points in different shaped and sized polygons

Suppose I have several polygons of varying shape and size, each containing a single point. I want to compare the centrality of each point, and determine which point is more central to its polygon. I'm ...
50 views

### Calculating centroid for polygon layer with several features?

I need only 1 centroid point for the whole layer (more than one polygon) instead of 1 centroid point per feature that you get with the menu -> Vector -> Geometry tools -> polygon centroid tool. Its ...
58k views

### How to determine the centroid of polygons?

I have a polygon vector and I want to quickly attain the centroid of this polygon for insertion in a text document. I am working with QGIS. I searched through other questions and although some are ...
153 views

### Centroid value extraction of Landsat image collection in Google Earth Engine

I have an NDVI collection wich I have created from the combination of different collections Landsat5 and 7. How can I exctract the NDVI values of the centroids of each pixel, of each image from my ...
70 views

### Using centroid point to generate polygon using ArcPy? [closed]

Is this possible to generate polygons from points (which are centroids of future polygon)? I got shapefile with ~250 points + they have got two attributes: length and width. I don't need complete ...
55 views

### QGIS Rasterize PolygonZM

I have a triangulated DEM PolygonZM shape and would like to Rasterize it in QGIS (3.2). I couldn´t find an option to use the geometry´s z value so i tried to create a field and calculate the centroid´...
52 views

### Generate Markers from WFS via turf.centroid() with Popups

I have successfully made a map that computes points from a WFS consisting of polygons and generates them as markers. The calculation is carried out by turf.js. However, I do not get all the properties ...
83 views

### How do I center a polygon on specific co-ordinates?

I need to place a set of polygons onto a set of points, so that each polygon is centered on its corresponding point - any ideas? In MapInfo I can just manually edit the co-ordinates of the center, but ...
147 views

### Is there a way to create pixel centroids inside polygons with PostGIS ?

I am trying to find a solution to do the function of the QGIS-tool 'Generate points(pixel centroids) inside polygons' in PostGIS. In the picture below you can see the output. Is there a way to do it ...
95 views

### Raster centroid and relationships with geoTIFF

I have a list (s) containing information on the probable locations of many animals in South America. For example, this is the type of stored information and what it looks like when plotted for the ...
71k views

### find the centroid of a cluster of points

While searching the web, solutions for finding centroids of polygons come up rather often. What I'm interested in is finding a centroid of a cluster of points. A weighted mean of sorts. I would ...
906 views

### Shapely polygons crossing the antimeridian

Sample data Consider the following WKT Polygon, crossing the international dateline (antimeridian): POLYGON((176 49,-65 49,-65 11,176 11,176 49)) And the following points: POINT(-140 32) # ...
294 views

### Spatial Join In PostGIS where centroid of a polygon is inside another polygon

I have two overlapping polygon layers as shown in figure below. One with small grid polygons and another with a large irregular polygon. I want to join them such that attributes of the large polygon ...
164 views

### Finding center of circle given three points?

I have been trying to solve this problem for quite some time, but can't find a good solution. Given three sets of geographic coordinates how can I calculate the center point. By "center point" I mean ...
77 views

### PostGIS Centroid coordinates (E, N)

I would like to add two new columns in the table (E, N), fill in the coordinates of a polygon centroid using PostGIS SQL code and have the column upadated as soon as I save the edit of a drawing in ...
111 views

### Drawing routes through centroids

According with this link http://postgis.net/workshops/postgis-intro/advanced_geometry_construction.html I'm creating lines that describe routes. I have a table stopcentroids4 like in figure with the ...
158 views

### Polygon Centroids working for only some Polygons in PyQGIS?

I have a building Layer(Full of Polygons).I want to get centroids of polygons and save them as point layer.I am using python console within Qgis 3.0. I have tried below code.I got my Centroid Layer(...
499 views

### Real centroid plugin QGIS3

I am looking to use realcentroid where I'm assuming it puts all points within the polygons rather than the tool in QGIS Vector -> geom -> centroid tool, which in my result some bendier polygons have ...
257 views

### Calculate centroids using PyQGIS

I am trying to calculate the centroids of polygons using PyQGIS. When I calculate the centroids with the interface (Vector --> Geometry Tools --> Polygon Centroids) everything works out. However, I ...
42k views

### How to calculate polygon centroids in R (for non-contiguous shapes)

I've spent a little while figuring out the answer to this question. It's not immediately obvious from a Google search, so thought it may useful to post the answer on here. There is also an additional ...
553 views

### Using Polygon centroids tool - points aren't always inside polygon, can I fix that?

When I use Polygon centroid tool, points aren't always inside polygon, because some polygons have weird shape with holes inside them. I have big amount of polygons and I need to use this tool and I ...
33 views

### K means clustering where centroid is a node

How would you approach a k mean clustering where the calculated centroids have to be on the same position as one of the nodes? as you can see we have 2 centroids which are arguably the center of each ...
3k views

### PostGIS - Get a point inside a line or polygon

I need to get the center point of a line or polygon to make marker for my app. So that when you click a marker the geometry appears (line or polygon). I used ST_Centroid to make it work. The result ...
717 views

### How to get, then export as .csv the lat lon centroids from shapefile layer

I have a shapefile with a whole lot of regions on it. I need to find the centroids for each of these regions in the shapefile (as latlons) and export this as a .csv I have done extensive research, ...
155 views

### Getting dual graph from QGIS?

I have a .shp file, and I need to get the dual graph from this file (that is to say, each polygon centroid should become a vertex, and two vertices are linked if their associated polygons are adjacent)...