15

ST_Distance is a calculation which must be executed and evaluated on every row. ST_DWithin can use an index, so it's likely to be much faster.


14

I found the answer myself. In Processing toolbox> Vector Selection > Select by location. There is the Spatial query.


12

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 in the search_path SET search_path TO sml, public; means that the database will write to sml if you don't give any schema SET search_path TO public, sml; ...


11

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 (a Numeric Input) and the tree height (a String Input). The tree layer is then selected by its height attribute. The selected trees are then buffered by the ...


11

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 will return a new memory vector layer storing the inverted lon/lat coordinates for the geometries. I tested the solution on several datasets available from ...


10

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 feature in points.getFeatures()] for pt in points: point = pt.geometry() # only and not pt.geometry().asPolygon() for pol in polygons: poly ...


9

You just need "KDhh_survey".* in your Select SELECT "KDhh_survey".* FROM public."KDhh_survey", public."ur_pilot_survey" WHERE ST_contains(public."ur_pilot_survey".the_geom, public."KDhh_survey".the_geom);


9

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 will go with a 275000 points shapefile. 1. Create a distance matrix using your layer as both destination and target. Don't forget to tick "Use only the nearest (...


9

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:


9

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, so you will need to convert your delimited file into an editable format. Once installed, the plugin goes under Vector > Geoprocessing tools > Affine ...


8

If you want to test whether some points (or shapes, etc) fall within a given distance of a given location, use the geographic version of ST_DWithin(). From http://www.postgis.org/docs/ST_DWithin.html: boolean ST_DWithin (geography gg1, geography gg2, double precision distance_meters, boolean use_spheroid); Thus, SELECT ST_DWithin( ...


7

There is an ArcMap DataFrame tab that allows you to Clip layers to a Shape. This doesn't alter the data on disk, only the layer view is clipped. You can also exclude specific layers from being clipped in your mxd.


7

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-points and region. Like this: SELECT * FROM counties c, regions r WHERE ST_Intersects(ST_PointOnSurface(c.the_geom), r.the_geom);


7

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 unless you change it with the unit option. It's worth considering that plain distance is not walking distance. Walking routes are restricted: a person can't (...


7

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 you'd rather perform this via a spatial join, which I think is what you're referring to, note that QGIS 3.0 now offers a separate Join attributes by location (...


6

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 want to take attribute values Go to Vector > Data Management Tools > Join Attributes by Location. Then, set the parameters as below: The tool will create a ...


6

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)' which is invalid. Try using string concatenation to ensure the wkt_left values are being inserted into the string: SELECT st_geomfromtext('LINESTRING('||line_att....


6

A virtual layer would work well here: First hit 'Import' to add your layers then add the query: SELECT A.id, group_concat(b.id) FROM A LEFT Join B ON ST_Intersects(a.geometry, b.geometry) GROUP BY A.id group_concat will concatenate all results into a comma seperated string (as your above screenshot). If you want to separate by something other than a comma ...


6

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. Someone has reverse-engineered the formats for reading them, but not implemented writing them yet. GDAL uses a .qix file for spatial indexing, but I don't know if ...


5

I think you're making it too complicated. Try this instead: SELECT sum(building_pop) FROM Buildings WHERE ST_Distance(ST_SetSRID( ST_MakePoint(1116858.6062789 7086290.6680572), 900913), geom) < 10000 That would give you the sum of building_pop column of all the buildings that are less than 10,000 units away from the defined Point.


5

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


5

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 p1x,p1y = poly[0] for i in range(n+1): p2x,p2y = poly[i % n] if y > min(p1y,p2y): if y <= max(p1y,p2y): ...


5

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 SELECT:ing is already an expression, so you can simply remove the SELECT. So, unless there's something else I'm overlooking, the following should work: ...


4

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 get a handle on your ILayer, cast that into an IFeatureLayer then point an IFeatureSelection interface to IFeatureLayer. From this you can get an ISelectionSet....


4

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 Linestrings. If I have understood you question correctly, you then want all start points which are not also end points for more than one line, ie, points where two ...


4

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 computer terms, including: Application software, programming language, data format, user interface, and access paradigm. ArcGIS is application software. It ...


4

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 -> function editor Input code which does the work Eg is_contained_in() returns the value from column of feature from B which contains feature A from qgis.core import *...


4

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 new address attributes to those old address points that fall within the buffer. WARNING this will only work effectively if a single old address point falls ...


4

You need to use Join attributes by location tool to join the point data with the polygon boundary data that you have. You can find the tool from Vector -> Data Management Tools -> Join attributes by location, as you can see below:


4

A simple method for counting only would be to use select by location in vector menu and select points inside that polygon. Then open the attribute table of your points layer and reverse selection. You can see the amount of selected points at the top of attribute table. If you need to unselect points inside more than one polygon you can use add to current ...


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