Monday 27 January 2020

How to get the geometry type of an empty PostGIS table?


I have a web application that needs to know the geometry type of a PostGIS table's geom field before inserting rows into it. I use the following query to determine the geometry type of the geom column:


SELECT GeometryType(geom) FROM my_schema.building LIMIT 1


This returns the geometry type of an actual row, so it does not work when my table is empty. How do I determine the geometry type of the geometry column itself?



Answer



The query could be run against the geometry_columns table in this way


SELECT type 
FROM geometry_columns
WHERE f_table_schema = 'my_schema'
AND f_table_name = 'building'
and f_geometry_column = 'geom';

(or, if you are using a geography type, subsititute geometry_columns with geography_columns and f_geometry_column with f_geography_column)



No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...