【问题标题】:cannot add QGIS polygon in pgAdmin using python无法使用 python 在 pgAdmin 中添加 QGIS 多边形
【发布时间】:2018-03-31 02:09:57
【问题描述】:

我有一个csv,其中包括一个东向和北向、东向和北向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??

【问题讨论】:

    标签: python polygon pgadmin qgis


    【解决方案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)])))));"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-09-22
      • 1970-01-01
      • 2017-12-14
      • 2017-06-02
      • 1970-01-01
      • 2012-03-11
      • 1970-01-01
      相关资源
      最近更新 更多