A typical GIS spatial query is to find all the point features in a buffer around a linear feature. This can be easily achieved using SpatiaLite database also. The following illustrates the workflow using two SpatiaLite feature tables - nodes and segments.

Using any SpatiaLite interface (graphical or command line interface), simply type in the following SQL statement to create a 50 meter buffer around the line segment feature using the spatial operator ST_Buffer:
SELECT ST_Buffer(Geometry, 50) AS buffer
FROM segments
WHERE name='line1'

The screenshot below shows how the 50 meter buffer looks like on a map.

To identify all the point nodes within the buffer, we can wrap the buffer statement in a more complex SQL statement:
SELECT a.* FROM nodes AS a,
(
SELECT buffer FROM
(
SELECT ST_Buffer(Geometry, 50) AS buffer
FROM segments
WHERE name='line1'
) AS b
)
WHERE ST_Contains(buffer, a.Geometry)

The screenshot shows how the results are like on a map.

2 comments:
Hi Hardikgis,
try this
select a.* from linka as a, (
select buffergeometry from (
select st_buffer(transgeometry, 500) as buffergeometry from
(
select st_transform(geometry,26910) as transgeometry from pointa
)
)
)
where st_contains(buffergeometry, a.geometry)
Just replace 26910 with your projected SRID, and 500 with your buffer distance in meters.
rg
Hardikgis,
I am quite certain the sql syntax is correct, as I tested it on a real dataset. So, it must be either your data, or the software that is causing your erroneous result. Would you like to send a representative set of data to me by email or dropbox for me to look at?
Post a Comment