![](/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.