32 votes

Join spatial point data to polygons in R

over() from package sp can be a little confusing but works well. I'm assuming you've already made "A" spatial with coordinates(A) <- ~longitude+latitude: # Overlay points and extract just the code ...
  • 14.5k
31 votes
Accepted

Check if a point falls within a multipolygon with Python

Shapefiles have no type MultiPolygon (type = Polygon), but they support them anyway (all rings are stored in one feature = list of polygons, look at Converting huge multipolygon to polygons) The ...
  • 51.9k
29 votes
Accepted

Refering to another layer with Field Calculator in QGIS

For QGIS versions QGIS 3.16 and higher Since QGIS 3.16 the functionality of the "refFunctions plugin" was emended into core. The current corresponding function is the overlay_within(). For ...
  • 1,906
23 votes

Refering to another layer with Field Calculator in QGIS

Out of the box, field calculator does not support spatial joins across feature layers. But, if you have a look at NathanW's post on the function editor for qgis expressions you will be able to make ...
  • 3,711
22 votes
Accepted

Looking for GeoPandas QGIS equivalent of ArcGIS "Select by location" tool

If poly is a GeoDataFrame with a single geometry, extract this: polygon = poly.geometry[0] Then, you can use the within method to check which points are within the polygon: points.within(polygon) ...
  • 3,498
21 votes
Accepted

Converting cluster of Points to Polygons using QGIS

Convex hull - as mentioned by Kazuhito - is one option, but - depending on the cluster shape - you will get more appropriate polygons using concave hulls, for example implemented in ConcaveHull plugin....
  • 82.6k
20 votes

Refering to another layer with Field Calculator in QGIS

It can be done in Field Calculator with function aggregate(). In point layer create new field with field calculator expression like this: aggregate( layer:= 'polygon_layer_name', aggregate:='...
  • 6,537
20 votes
Accepted

Re-locating points randomly at certain distance in QGIS

This answer has been updated several times to get a solution that gradually adds complexity to the expression. For the final solution, you should go directely to the very bottom (step 5). The history ...
  • 45.2k
19 votes

Counting points in polygons using QGIS

The tool you're looking for is now called "Count points in polygons", and it can be found in the QGIS's Processing Toolbox (Ctrl+Alt+T) under Vector analysis tools or can be also launched ...
  • 8,398
13 votes

Overlaying spatial polygon with grid and checking in which grid element specific coordinates are located using R

The New York dataset provided in the question is no longer available for download. I use the nc dataset from sf package to demonstrate a solution using sf package: library(sf) library(ggplot2) # ...
  • 1,643
13 votes
Accepted

Applying labelling with obstacles in QGIS

Why obstacles do not work The setting Features act as obstacles only works for features of the same layer. Use Geometry generator to define label placement Go to Label / Placement tab and use Geometry ...
  • 45.2k
12 votes

Boundary from Points

In QGIS, many of the really good tools are in the processing toolbox; you need 'concave hull': Try it with different threshold values for different levels of detail: Finally, add a 10% buffer around ...
  • 14.5k
12 votes
Accepted

Using qgis:selectbylocation in PyQGIS

I used this code: mapcanvas = iface.mapCanvas() layers = mapcanvas.layers() processing.runalg('qgis:selectbylocation', layers[0], layers[1], u'within', 0) with this situation: and it worked: ...
  • 27.2k
11 votes
Accepted

Boundary from Points

Try Concave hull, What are Definition, Algorithms and Practical Solutions for Concave Hull? Concave hull has a smaller area, and most of implementations allows you to tune how small and precise ...
11 votes
Accepted

How to find points within a polygon in PostGIS

You should use the ST_within function and not the ST_intersect function. Here the documentation. Here the sql code. You want only the points within greatermanchester select a.* from "Nov01" as a join ...
  • 1,012
11 votes
Accepted

Counting number of features within another feature using aggregate function in the QGIS Field calculator

This expression will count the number of populated places for each country: aggregate(layer:='ne_110m_populated_places', aggregate:='count', expression:=name, filter:=...
  • 7,940
11 votes
Accepted

Adding new field in point layer with attribute from another layer in QGIS

This plugin is deprecated! The plugin is outdated as of QGIS 3.14 due to the introduction of the new functions for geometry overlay expressions You can use "refFunctions" Plugin. It adds ...
11 votes
Accepted

Getting values from adjacent polygons or nearest point

You can use QGIS expressions with the new overlay_nearest function, availble since QGIS 3.16 and the array_mean() function, available since QGIS 3.18. If you already have an attribute in the polygon ...
  • 45.2k
10 votes

Converting cluster of Points to Polygons using QGIS

You may be interested in Convex Hull which is in Processing | QGIS geoalgorithms | Vector geometry tools. There is Field option which can be used with Method Create convex hulls based on field. Or ...
  • 29.3k
10 votes
Accepted

Count points in polygon grouping by attribute using PyQGIS

Use this script: from PyQt5.QtCore import QVariant # layers polygon_lyr = QgsProject.instance().mapLayersByName("Polygons")[0] point_lyr = QgsProject.instance().mapLayersByName("Points")[0] # index ...
10 votes

Adding new field in point layer with attribute from another layer in QGIS

There is also a possibility without need to install a plugin, simply using this expression. overlay_within() is available since QGIS 3.16, in fact implementing the functions of the refFunctions plugin ...
  • 45.2k
9 votes

Geodjango - trying to get points within a polygon

You first need to understand the different ways to create geometries and the geometrical relations in GeoDjango (GeoDjango: GEOS API), without a database: 1) create valid geometries: # with Point, ...
  • 51.9k
9 votes
Accepted

Join spatial point data to polygons in R

The point.in.poly function in the spatialEco package returns a SpatialPointsDataFrame object of the points that intersect an sp polygon object and optionally adds the polygon attributes. First lets ...
9 votes

Check if a point falls within a multipolygon with Python

The problem in your first example is in this loop: ... shpfilePoints = [] for shape in polygon: shpfilePoints = shape.points ... It only appends the last feature points. I tried out my approach ...
  • 27.2k
9 votes

Selecting and exporting points inside specific polygon using QGIS

There is a direct and very easy way to do this. In the Clip tool, press the green cyclic arrows button next to the Overlay layer dropdown menu. That instructs to iterate the operation over the ...
  • 91
9 votes

Showing data from attribute table in legend in QGIS

You can use the following expression if there is one polygon. @layer_name + ' (' + to_string(array_get(array_agg( "NUMPOINTS" ), 0)) + ')'
8 votes

Creating regular point grid inside polygon in PostGIS

Three algorithms using different methods. Github Repo: https://github.com/imran-5/Postgis-Custom The simple and best approach, using the actual earth distance of coordinates from the x and y ...
8 votes

Preventing labels from overlapping certain features using QGIS

Using QGIS 3.16.0 Assuming your labels are stored in "name" field, go to Layer Properties > Labels and set the labeling expression as below: if(overlay_disjoint('area'), "name", ...
  • 29.3k
8 votes
Accepted

Selecting and exporting points inside specific polygon using QGIS

You can do this in two steps using QGIS. (1) First, use the tool the "Join Attributes by Location" to create a new field in your points layer that describes which polygon each point falls ...
  • 2,634
8 votes
Accepted

NULL values when using overlay_within function in Field Calculator

overlay_within returns Sektor value of the realted polygon feature(s) as a list/array (even if it returns one polygon). You should convert to string. Set Output field type to Text and use this ...

Only top scored, non community-wiki answers of a minimum length are eligible