38
votes
Accepted
Overlaying spatial polygon with grid and checking in which grid element specific coordinates are located using R
Here is an example using a SpatialGrid object:
### read shapefile
library("rgdal")
shp <- readOGR("nybb_13a", "nybb")
proj4string(shp) # units us-ft
# [1] "+proj=lcc +lat_1=40.66666666666666 +...
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 ...
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 ...
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 ...
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 ...
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....
21
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)
...
19
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:='...
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 ...
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)
# ...
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 ...
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 ...
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:
...
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
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:=...
11
votes
Accepted
Adding new field in point layer with attribute from another layer in QGIS
You can use refFunctions Plugin. It adds custom user functions to QGIS Field Calculator. Then, you can add a new field to the point layer with the id of the polygon that contains it using the ...
10
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 ...
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 ...
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 ...
10
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 ...
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, ...
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 ...
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 ...
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
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 ...
8
votes
Accepted
Creating duplicate points as many times as it overlap with polygons in QGIS
The "Join Attributes by Location" tool, with a 'one-to-many' join type, should give your desired result.
8
votes
Creating set number of regularly spaced points inside of polygon in QGIS
I use this pyqgis code to create a fixed number of sample plots in forest stands/polygons. It will create a point layer in memory. Click/highlight your polygon layer, adjust the number of plots below ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
point-in-polygon × 421qgis × 149
polygon × 67
point × 51
r × 47
postgis × 46
arcgis-desktop × 44
spatial-join × 33
python × 29
overlapping-features × 29
shapefile × 25
count × 24
arcmap × 19
postgresql × 14
qgis-3 × 14
pyqgis × 11
field-calculator × 11
intersection × 11
shapely × 11
select-by-location × 11
arcgis-10.2 × 9
fields-attributes × 9
geopandas × 9
arcgis-10.1 × 8
attribute-table × 8