我有一个 csv ,其中包括东向和北向,东向2和向北2,向东3和向北3,以在qgis中创建一个多边形,其中所有东向和北向属性都是数字。
代码显示:
import os
import csv
import psycopg2
import time
conn = psycopg2.connect (host="xxxx", database="xxxx", user="xxxx"
,password="xxxx", port="xxxx")
delete="ALTER Table highloading_qgis DROP COLUMN geom;"
tem_delete="DELETE FROM public.highloading_qgis;"
tem_carrier="copy highloading_qgis
FROM'/home/ftpuser/Report/highloading_new.csv' With DELIMITER ',' CSV
HEADER;"
add_col="ALTER TABLE highloading_qgis ADD COLUMN geom geometry;"
update_gpis="UPDATE highloading_qgis SET geom =
(ST_MakePolygon(ST_GeomFromText('LINESTRING('Easting' 'Northing','Easting2'
'Northing2','Easting3' 'Northing3')')));"
cursor = conn.cursor()
cursor.execute(delete)
cursor.execute(tem_delete)
cursor.execute(tem_carrier)
cursor.execute(add_col)
cursor.execute(update_gpis)
cursor.close()
conn.commit()
conn.close()
但是我在执行cursor.execute(update_gpis)“
时发现错误ProgrammingError: syntax error at or near "Easting"
LINE 1: ...om = (ST_MakePolygon(ST_GeomFromText('LINESTRING('Easting' '...
^
任何人都可以帮助如何纠正向pgadmin添加多边形几何?
答案 0 :(得分:1)
我不是这方面的专家。但我认为你需要至少4分的polygen。以上你只给了3分。
你也可以尝试下面给出的查询。但不确定
update_gpis="UPDATE highloading_qgis SET geom = (ST_MakePolygon(ST_GeomFromText(ST_AsText(ST_MakeLine(Array[ST_MakePoint(Easting,Northing),ST_MakePoint(Easting2,Northing2),ST_MakePoint(Easting3,Northing3),ST_MakePoint(Easting4,Northing4)])))));"