

This, of course, means reprojecting the data which is slow so an alternative is to use ST_Distance_Sphere which approximates the calculation in decimal degrees for us. latitude/longitude) and we want to do the calculation based on metres.

The use of the geography keyword buildings.geom::geography is needed because our data is in WGS84 (i.e. It returns true if the geometries are within the specified distance of one another. ST_DWithin within is the PostGIS function doing all the work here. So this is a fairly standard looking SQL query - we select fields we need from the two tables buildings and landuse with some constraints as provided by the WHERE. ST_DWithin(buildings.geom::geography, landuse.geom::geography, 50) Lets repeat this process for the landuse.shp file: SELECT AddGeometr圜olumn( '', 'buildings', 'geom', '0', 'MULTIPOLYGON',2) ➜ shp2pgsql buildings.shp buildings | headįield fid is an FTDouble with width 11 and precision 0ĪLTER TABLE "buildings" ADD PRIMARY KEY (gid)
