How do I visualize GIS and PostGIS data from a SQL query?
See the query’s geometry on a map beside the grid, without copying the text into another program. You can draw a shape and paste the polygon back into the SQL.
A POLYGON or a POINT in the result almost always shows up as text. WKT, EWKT, and GeoJSON fit in the cell, so the usual path is copy, paste into QGIS, or open a viewer in the browser.
The query stays in the SQL client and the map lives in another program. A shape you draw does not come back to the editor.
Kerry Studio draws that geometry beside the grid. The Map button opens the split over OpenStreetMap. A text column with WKT, EWKT, or GeoJSON is already enough. A native column (geometry, SDO_GEOMETRY, POINT, and the rest) needs the engine’s spatial support.
You see the shape, draw a polygon, and paste that SQL back into the editor, without switching to another program.
How to open the map
You need an open workspace, a connected SQL tab, and a result with geometry. Without a spatial column and without geometry in the cells, the Map button does not appear.
- Run a
SELECTthat returns a spatial column, WKT, EWKT, or GeoJSON. - In the results panel, click Map.
- The grid and the map sit together. Drag the splitter if you want more room for the map. The expand icon opens the map in an overlay window. Close map gives the whole space back to the grid.
The palette (⌘K / CtrlK) → Toggle results map does the same. The split does not open on its own. If you leave it open, the tab remembers.
In the geometry cell, View on map opens a map for that value only, like the JSON button.
What the map shows
Each geometry column in the result gets a color. Points and areas use different palettes. The legend uses the column name, or the alias if the SELECT has one. If the SELECT has i.location AS home and z.geom AS flood, the legend shows home and flood. The JOIN stays in the SQL. The map only paints what already came back in the result.
A click on a pin opens a card with that column’s name in the title and the other values from the row. The geometry does not go on the card.
Fit view frames every geometry in the result. The first time the map opens, that framing is already applied. Flip lon/lat only changes the drawing. The value in the grid stays what the database returned.
Draw and paste the polygon back into SQL
Lasso, Rectangle, and Ellipse draw on the map. Select is the default tool. Paste polygon into SQL inserts, at the editor cursor, the selected polygon, or every drawing if none is selected. One polygon becomes POLYGON. Several become the spatial union in the tab’s dialect.
On PostgreSQL and MySQL, Kerry pastes ST_GeomFromText. On Oracle it pastes SDO_GEOMETRY. On SQLite it pastes GeomFromText. That SQL needs the engine’s spatial functions. The ST_Intersects operator is still SQL of the tab’s engine.
Measures shows the size of each polygon, in the unit you pick: m², ha, or km². Merge groups the selection and paints the union. You can merge a geometry from the query with a drawing.
The Export map menu saves PNG, SVG, WebP, and GeoJSON. Print uses the same toggles.
What each database needs
Kerry does not install the spatial extension for you. The map still draws WKT, EWKT, and GeoJSON that already came back in the cell, even without the extension.
PostgreSQL. Needs the PostGIS extension. Without it, GEOMETRY and GEOGRAPHY still appear in create table and alter table, and Kerry warns that the type needs PostGIS. In PostgreSQL itself, CREATE EXTENSION postgis installs PostGIS on the database.
MySQL and MariaDB. Spatial types are native (GEOMETRY, POINT, POLYGON, and the rest). There is no extra extension.
Oracle. Needs Locator or Spatial. Without the SDO_GEOMETRY type in the database, Kerry warns in create table and alter table.
SQLite. Needs SpatiaLite. On the SQLite connection, under Extensions, add the extension file and turn on Load on connect.
It works on all four engines of the tab: PostgreSQL, MySQL/MariaDB, Oracle, and SQLite. A query with @project.table from another project materializes the rows on the tab’s connection. If that destination has GIS, the temporary table uses the native spatial type. If it does not, the geometry goes as EWKT text.
Each control is documented in Map in results.