![](/img/trans.png)
[英]Error inserting polygon using Python Console in Qgis GIS software
[英]cannot add QGIS polygon in pgAdmin using python
我有一個csv ,其中包括一個easting和northing,easting2和northing2,easting3和northing3,以便在qgis中創建一個多邊形,所有的easting和northing屬性都是數字。
顯示代碼:
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添加多邊形地物嗎?
我不是專家,但是我認為您至少需要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)])))));"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.