【问题标题】:values missing while inserting geojson values to postgres table将geojson值插入postgres表时缺少值
【发布时间】:2017-12-06 02:05:51
【问题描述】:

我正在尝试读取 geojson 文件并将记录插入到 postgres 表中 - 使用下面的 python 代码。

import json
import psycopg2
conn = psycopg2.connect(host="<<ip_address>>",database="DB1", user="<<id>>", password="pwd")
cur = conn.cursor()
with open('NTA_shape.json') as f:
Geojson_data = json.load(f)
for feature in Geojson_data['features']:   
    type_val=feature['geometry']['type']
    geom=feature['geometry']['coordinates']
    ntaname=feature['properties']['NTAName']
    boroname=feature['properties']['BoroName']
    data = {"type":type_val,"coordinates":geom}
    sql ="""Insert into <<Table_NAME> (geom,ntaname,boroname) VALUES(ST_GeomFromGeoJSON(%s),%s,%s)""" 
    nta_boro=(json.dumps(data),ntaname,boroname)
    cur.execute(sql,nta_boro)
    conn.commit()
conn.close()

但是当我查询表时,很多记录都丢失了。 如果我打印 json.dumps(data) 变量 - 它会显示所有记录。

我不确定,在表格插入过程中我缺少什么 请帮忙。

【问题讨论】:

  • 我能够通过以下更改修复它 nta_boro=(json.dumps(data,),ntaname,boroname)

标签: python postgresql gis geojson


【解决方案1】:

我能够通过以下更改进行修复

nta_boro=(json.dumps(data,),ntaname,boroname)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-22
    • 1970-01-01
    • 1970-01-01
    • 2017-01-23
    • 1970-01-01
    • 2011-03-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多