Multicolumn index on 3 fields with heterogenous data types

Single-column index Postgres can combine multiple indexes very efficiently in a single query with bitmap index scans. Most of the time, the most selective index is picked (or two, combined with bitmap index scans) and the rest is filtered. Once the result set is narrow enough, it’s not efficient to scan more indexes. Multicolumn index … Read more

convert Postgres geometry format to WKT

Have you tried this? SELECT ST_AsText(your_geom_column) FROM your_table In the following examples I’ll show you a few ways to serialise your geometries. Here is sample data with two points encoded as 4326 (WGS84): CREATE TEMPORARY TABLE tmp (geom GEOMETRY); INSERT INTO tmp VALUES (‘SRID=4326;POINT(1 2)’), (‘SRID=4326;POINT(2 4)’); Geometries as WKB (Well-Known Binary, default): SELECT geom … Read more

GeoDjango on Windows: “Could not find the GDAL library” / “OSError: [WinError 126] The specified module could not be found”

I have found the following to work for windows: Run python to check if your python is 32 or 64 bit. Install corresponding OSGeo4W (32 or 64 bit) into C:\OSGeo4W or C:\OSGeo4W64: Note: Select Express Web-GIS Install and click next. In the ‘Select Packages’ list, ensure that GDAL is selected; MapServer and Apache are also … Read more

Buffers (Circle) in PostGIS

Isn’t it just doing what is supposed to be done? Which is to compensate the distortion due to projecting the ellipsoid into a 2D flat structure? I believe, the further away you get from the equator, the more oval buffers you will see. Examples: db=# SELECT ST_AsText( ST_Buffer( ST_GeomFromText(‘SRID=4326;POINT(43.29 5.41)’),0.001, ‘quad_segs=16’) ); This query returns … Read more

Getting all Buildings in range of 5 miles from specified coordinates

Why are you storing x,y in separated columns? I strongly suggest you to store them as geometry or geography to avoid unnecessary casting overhead in query time. That being said, you can compute and check distances in miles using ST_DWithin or ST_Distance: (Test data) CREATE TABLE building (name text, long numeric, lat numeric); INSERT INTO … Read more