25
votes
How to calculate polygon centroids in R (for non-contiguous shapes)
here is an approach using sf. As I demonstrate, results from sf::st_centroid and rgeos::gCentroid are the same.
library(sf)
library(ggplot2)
# I transform to utm because st_centroid is not ...
21
votes
Using Field Calculator in QGIS to update columns with centroid coordinates
Not sure if it worked 5 years ago, but now the solution looks like this:
x(centroid($geometry))
and
y(centroid($geometry))
Results are the same as while using the "Join" option mentioned ...
20
votes
Accepted
Centroid coordinates for odd-shaped polygons
I think the standard QGIS polygon centroid tools calculate the centre of mass in order to determine the polygon's centroid. So this could lie outside the polygon itself (nothing to do with projection)....
20
votes
How to get the centroid of a set of points in PostGIS?
PostGIS has two functions for combining multiple geometries into a single geometry that you can use as an input to ST_Centroid.
ST_Collect simply combines a set of geometries without modifying them.
...
19
votes
Creating centerline of river in QGIS?
The surest method for solving your question from the point of view of the cartographic approach is to use the Voronoi Polygons.
I offer one of the solutions to your question using QGIS tools.
So, ...
16
votes
Accepted
Getting lat/long for centroids using QGIS
Inserting new fields with the field calculator and the expression $x and $y on the layer with your centroids should do the job. If you use the polygon layer of your lakes, you might include there lat/...
16
votes
Creating centroid inside of polygon
If you want a point that is for sure inside the polygon use representative point:
Returns a cheaply computed point that is guaranteed to be within the
geometric object.
import geopandas as gpd
...
14
votes
List of central coordinates (centroid) for all countries?
You can retrieve this information using R like this:
library(rgeos)
library(rworldmap)
# get world map
wmap <- getMap(resolution="high")
# get centroids
centroids <- gCentroid(wmap, byid=TRUE)...
13
votes
Accepted
Getting dual graph from QGIS
You can use Python only (versions 2.7.x and 3.x) without QGIS:
1) With Fiona, shapely and itertools
import fiona
from shapely.geometry import MuliPolygon, LineString, mapping
Multi = ...
13
votes
Accepted
QGIS - how to use geometry generator to place a centroid in each segment of a multiline?
You can use the following expression for Geometry Generator.
with_variable(
'segments', segments_to_lines($geometry),
collect_geometries(
array_foreach(
...
12
votes
Determining the centroid of polygons in QGIS
I just came across this post nearly 5 years late (!), but here's what I do to calculate polygon centroids at version 2.18.14:
Begin editing the polygon layer
Create a new text field, call it ...
12
votes
Centroid coordinates for odd-shaped polygons
Proessing QGIS Algorithms has "Point on Surface" too, under Vector geometry tools group. No need to use external plugins nor DBs
12
votes
Accepted
Generation of centroids outside polygon
There is no problem, a centroid doesn't need to be within the polygon. If you need a point that must be inside the polygon then you should use either pointOnSurface or poleOfInacessability which do ...
11
votes
Accepted
Creating point on surface in QGIS
In QGIS 3.10 this option is not available using Vector > Geometry Tools > Centroids.
However if you search for "Point on surface" in the Processing Toolbox (Ctrl+Shift+T) using QGIS ...
9
votes
Accepted
Getting centroids for multiple lines in QGIS
In tool "Mean coordinate(s)" from the QGIS's Processing Toolbox (Ctrl+Alt+T) use Unique "ID" field.
9
votes
Getting centroids for multiple lines in QGIS
In the Field Calculator, create a new String field and set the length to be something high like 99. Then use the expression:
geomToWKT(centroid($geometry))
This should give centroid coordinate values ...
9
votes
Accepted
Creating radial lines from center of polygon to edge in QGIS
You can use "Geometry by expression" followed by "Multipart to singleparts".
For each angle from 0 to 360-22.5 at 22.5 increments, a line is created from the centroid to a point ...
8
votes
How to get the centroid of a set of points in PostGIS?
If you're looking for performance use this query:
SELECT avg(ST_X(the_geom)) as lon, avg(ST_Y(the_geom)) as lat FROM table
it gives you more or less the same output as:
SELECT ST_AsText(...
8
votes
Real centroid plugin QGIS3
Third party plugins like this are dependant on their author to update for new versions. I'd suggest using the built in "point on surface" algorithm from the processing toolbox instead
8
votes
Accepted
R st_centroid GEOS error Unknown WKB type 12
To handle the conversion mentioned by @user30184 within R, you can use the ogr2ogr() function provided by my gdalUtilities package.
To demonstrate its use, here is a little utility function adapted ...
8
votes
Accepted
Creating centroid on curved surface in QGIS
I don't know a tool to have directly what you want but I propose here a workflow to have the following result :
Names like this refers to QGIS processing algorithms
Compute the Minimum Bounding ...
7
votes
Centering polygon on specific coordinates using QGIS
This answer is for QGIS 3.4.
See this answer for earlier versions: Moving vectors to specified coordinates in QGIS?
I was able to do this by creating a centroid for a polygon:
Then moving the ...
7
votes
How do I create centroids inside polygons in Python?
You just need to use the method representative_point that borrows the shapely method (shapely library borrows the method from GEOS library PointOnSurface method e.g https://github.com/Toblerity/...
7
votes
Accepted
How to ensure centroid is calculated within polygon?
You do not say whether you are using ArcPy with the ArcGIS Pro or ArcMap application of the ArcGIS Desktop product so I'll assume that it is ArcGIS Pro and reference that documentation.
In the ...
7
votes
Ordering polygons from north to south in QGIS
You can create a new field with this expression :
array_find( -- find the current feature id in the list
array_reverse( -- reverse the order of the list, so greastest Y coordinate (= Northest) is ...
6
votes
How to calculate polygon centroids in R (for non-contiguous shapes)
What I did to overcome this problem is to generate a function which negatively buffers the polygon until it is small enough to expect a convex polygon. The function to use iscentroid(polygon)
#' find ...
6
votes
List of central coordinates (centroid) for all countries?
You can get country centroids using Python and GeoPandas.
import geopandas as gpd
import pandas as pd
# Access built-in Natural Earth data via GeoPandas
world = gpd.read_file(gpd.datasets.get_path('...
6
votes
Determining the centroid of polygons in QGIS
Came across this post and was hard to follow, suggested update:
Note:
This will calculate the latitude and longitude in your projection coordinates (which may be meters). If you want the ...
6
votes
Accepted
Bind polygon centroid to polygon attribute data
Load libraries and example data
# Load libraries
library('raster')
library('geosphere')
library('mapview') # incredible interactive map visualization in R
# Get SpatialPolygonsDataFrame object ...
6
votes
Accepted
Scaling more than 1000 polygons in QGIS
In QGIS you can create a "Virtual Layer" through Layer > Add Layer > Add/Edit Virtual Layer.... with a SpatiaLite expression to perform the transformation that you need:
SELECT
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
centroids × 263qgis × 114
polygon × 51
postgis × 22
r × 22
arcgis-desktop × 21
python × 19
geometry × 16
distance × 14
geopandas × 12
point × 11
coordinate-system × 10
coordinates × 10
arcpy × 9
raster × 9
pyqgis × 8
postgresql × 8
line × 8
shapefile × 7
google-earth-engine × 7
field-calculator × 7
spatial-join × 7
qgis-3 × 6
buffer × 6
latitude-longitude × 6