Last active
February 27, 2017 09:45
-
-
Save guitar1999/9442467 to your computer and use it in GitHub Desktop.
QGIS 2.2 and PostGIS geometry > 2d
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# QGIS 2.2 won't show 4d geometry (maybe not 3dm or 3dz either but I didn't test). | |
# If you don't actually need 4d and it's just an artifact of the data when you loaded | |
# it, use this python snippet to convert it to 2d and get your data showing up in | |
# QGIS again. Use at your own risk. There is NO ERROR HANDLING HERE! | |
import psycopg2 | |
db = psycopg2.connect(host='localhost', port='5432', database='#####',user='#####') | |
cursor = db.cursor() | |
# Customize as necessary to keep the tables where you need 4d | |
query = "SELECT f_table_schema, f_table_name AS table, f_geometry_column, srid, type FROM geometry_columns WHERE coord_dimension > 2 AND NOT f_table_name LIKE '%flowline%';" | |
cursor.execute(query) | |
rels = cursor.fetchall() | |
for schema, rel, geom, srid, gtype in rels: | |
query = """ALTER TABLE {0}.{1} ALTER COLUMN {2} TYPE geometry({3},{4}) USING ST_Force2d({2});""".format(schema, rel, geom, gtype, srid) | |
cursor.execute(query) | |
db.commit() | |
cursor.close() | |
db.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment