15 votes
Accepted

Where is Spatial query in QGIS3?

I found the answer myself. In Processing toolbox> Vector Selection > Select by location. There is the Spatial query.
user avatar
  • 561
14 votes
Accepted

PostGIS ST within does not exist

Your problem is that you have excluded the public schema from the search_path. All functions and types is in the public schema (by default) So what you have to do is just include the public schema ...
user avatar
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: ...
user avatar
  • 25.9k
11 votes

Performing a Spatial Query in a loop in PyQGIS

You don't need a special function (as "Ray Casting"), everything is in PyQGIS (contains() in PyQGIS Geometry Handling) polygons = [feature for feature in polygons.getFeatures()] points = [feature for ...
user avatar
  • 50.7k
11 votes
Accepted

How to build a query/expression to select specific points within a buffer? (in QGIS)

This can be done using the Processing Graphical Modeler to set up a custom chain. Here's a pic: From left to right we have three inputs - the tree layer (a Vector Layer Input Object), the buffer size ...
user avatar
  • 51.1k
11 votes

Is there a way to use a spatial query to invert X and Y coordinates in QGIS?

I propose a solution using PyQGIS: the several codes instantly work from the Python Console, but they can easily be implemented in separate scripts (see the edit at the end of the answer). Each script ...
user avatar
  • 15.5k
10 votes

Identify points in a shapefile that have no other point within x km with QGIS

You can use Vector > Analysis Tools > Distance Matrix, and a join to achieve what you ask. I will use qgis sample data airport's layer to exemplify. This is a small dataset so I'm not sure how it ...
user avatar
10 votes
Accepted

Get the width and height of a rectangular polygon in PostGIS

I'd go with the Geometry Accessors for X to give width: ST_XMax - ST_XMin, and the related functions for Y for height.
user avatar
10 votes

Is there a way to use a spatial query to invert X and Y coordinates in QGIS?

You can use the Affine Transformation plugin to do this. It's not particularly fast, so you might want to try on some fairly simple geometries to begin with. Also, it only works with editable layers, ...
user avatar
  • 19.8k
7 votes

drawing concentric circles in arcmap 10.1

Basically, this is just Buffer. Since you want to make multiple buffers at once, though, the Multiple Ring Buffer tool would be more appropriate. and the default will be the crs/gcs of the input ...
user avatar
  • 8,906
7 votes
Accepted

Selecting Counties within Region via Spatial Query using QGIS/PostGIS?

PostGIS has a function that addresses just this centroid problem: use ST_PointOnSurface() to return a point guaranteed to be inside your county, then just find the ST_Intersection() of the county-...
user avatar
  • 1,134
7 votes
Accepted

Postgis using st_geometry linestring on column

I think the issue here is with your WKT construction: SELECT st_geomfromtext('LINESTRING(line_att.wkt_left)', 27700) will try to create a geometry from the WKT 'LINESTRING(line_att.wkt_left)' ...
user avatar
  • 3,875
7 votes

Where is Spatial query in QGIS3?

The Count points in polygon tool should work for you, though I'd be interested to see what output you're getting. Input polygon and points layers in the count points... tool: Output from above: If ...
user avatar
  • 3,669
7 votes

Spatial join attributes based on closest point in PostGIS

Run SELECT a.id, b.value, -- ST_Distance(a.wkb_geometry::GEOGRAPHY, b.wkb_geometry::GEOGRAPHY) as dist, a.wkb_geometry FROM t2 AS a JOIN LATERAL ( SELECT value FROM t1 ...
user avatar
  • 23.2k
7 votes
Accepted

Spatial query with clip (PostGIS)

This is what you're looking for: SELECT ST_Intersection(t1.geom, t2.geom) FROM t1 JOIN t2 ON ST_Intersects(t1.geom, t2.geom) For more info: https://postgis.net/docs/ST_Intersection.html
user avatar
  • 797
6 votes

Update field based on spatial query (QGIS)

To add a column containing some attribute of a feature of another layer, with which there exists a topological relation: Define a function: layer properties -> attributes -> field calculator -> ...
user avatar
  • 4,400
6 votes

Update field based on spatial query (QGIS)

You can use the Join attributes by location tool. Say you have the following layers: layer_a : the layer to which you want to attach attribute values from layer_b layer_b : the layer from which you ...
user avatar
  • 2,580
6 votes
Accepted

Is it possible to have R write out .sbn and .sbx files?

From the GDAL docs, which is what R uses: Starting with OGR 1.10, it can also use the ESRI spatial index files (.sbn / .sbx), but writing them is not supported currently. So not possible. ...
user avatar
  • 51.1k
5 votes

Performing a Spatial Query in a loop in PyQGIS

You can use the "Ray Casting" algorithm that I have slightly adapted for using with PyQGIS: def point_in_poly(point,poly): x = point.x() y = point.y() n = len(poly) inside = False ...
user avatar
  • 25.9k
5 votes
Accepted

Spatial Query for a Virtual Layer

A sample syntax for you. SELECT * FROM F, C WHERE st_within(F.geometry, C.geometry) = 1 On a side note: SELECT * will output everything (including geometry column) fits your conditions. FROM F,C ...
user avatar
  • 29k
5 votes
Accepted

Test if a spatial query contains another

When using a SELECT statement as an expression, as you are doing with the parameters to ST_Contains, you need to wrap it in parentheses. Also, in the case of the SELECT GeomFromText(...), what you are ...
user avatar
5 votes
Accepted

Comparing and find out which feature has highest shape area in QGIS?

There is a possibility of using a "Virtual Layer" through Layer > Add Layer > Add/Edit Virtual Layer... Let's assume we have 10 features in 'layer' accordingly, where each feature has ...
user avatar
  • 23k
5 votes
Accepted

Constructing spatial queries that include data from non-spatial tables in PostGIS

This is one of the key abilities of relational databases. Just join all three tables together on the attribute ID key and the spatial relationship: SELECT l.name_loc, s.eventdate FROM survey s JOIN ...
user avatar
  • 3,611
4 votes

How to do simple self join and touches function in postgis?

Looser relation, but probably good enough: SELECT s2.cntry_name as sweden_neighbors FROM countries AS s1, countries AS s2 WHERE ST_Intersects(s1.the_geom, s2.the_geom) AND s1.cntry_name = 'Sweden' ...
user avatar
  • 19.3k
4 votes
Accepted

vb.net arcobjects spatial query get fields value of desired layer only

I think you are making this more difficult than it has to be. You are obtaining your selected features from IMap.FeatureSelection. So multiple layers could return a selection. A much better way is to ...
user avatar
  • 38.4k
4 votes
Accepted

Find start of river

ST_StartPoint is the correct function to find single nodes at the start of a Linestring, however it does not work with MultiLinestring, so you will need to use ST_Dump to get the constituent ...
user avatar
  • 13.2k
4 votes

SQL and ArcGIS data querying: what's the difference?

I'm having difficulty with the classification of "search by attribute" as a "language". To understand an answer to this startlingly broad question requires understanding of the meanings of a number of ...
user avatar
  • 18.8k
4 votes
Accepted

Performing a Spatial Query in a loop in PyQGIS

With some advice from a workmate I finally got it to work using within(). General logic get features of polygon(s) get features of points loop through each feature from polygon file, and for each: ...
user avatar
  • 6,209
4 votes
Accepted

query with buffer

You could use 'Vector > Data Management Tools > Joins Attributes by location'. As the buffer was created from the new address layer, the attributes will be in the buffer. This tool will join the ...
user avatar
  • 4,266
4 votes
Accepted

Is there a way to use a spatial query to invert X and Y coordinates in QGIS?

A native new solution in QGIS 3.2, thanks to Nyall Dawson (North Road) : Feature: Swap x/y coordinate values algorithm This algorithm swaps the X and Y coordinate values in input geometries. It can ...
user avatar
  • 7,488

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