快速将大型csv转换为geojson [英] Fast Convert of large csv to geojson

查看:450
本文介绍了快速将大型csv转换为geojson的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 600万行的csv ,我需要将其转换为 geojson 文件.

I have a csv with 6 millions of rows and i need to convert it to a geojson file.

云解决方案存在于互联网中,但要花费一整天的时间进行转换.
有没有一种快速的方法可以使用python做到这一点?

cloud solutions exists in the internet but it takes whole day to convert it.
Is there a quick way to do that with python ?

问题更新:

我尝试了此处错误:

ValueError                                Traceback (most recent call last)
<ipython-input-48-0224e45ed66e> in <module>()
  5 with open('Documents/neo4j-community-3.3.5/import/train.csv', newline='') as csvfile:
  6     reader = csv.reader(csvfile, delimiter=',')
----> 7     for pickup_latitude, pickup_longitude in reader:
  8         pickup_latitude,pickup_longitude = map(float,   (pickup_latitude, pickup_longitude))
  9         features.append(

ValueError: too many values to unpack (expected 2)

这是我的代码:

import csv, json
from geojson import Feature, FeatureCollection, Point

features = []
with open('Documents/neo4j-community-3.3.5/import/train.csv', newline='')   as csvfile:
reader = csv.reader(csvfile, delimiter=',')
for pickup_latitude, pickup_longitude in reader:
    pickup_latitude,pickup_longitude = map(float, (pickup_latitude, pickup_longitude))
    features.append(
        Feature(
            geometry = Point((pickup_longitude, pickup_latitude)),

        )
    )

collection = FeatureCollection(features) 
with open("GeoObs.json", "w") as f:
f.write('%s' % collection)

注意:pickup_latitude和Pickup_longitude是我的csv中的两列

Note :pickup_latitude and pickup_longitude are two columns in my csv

推荐答案

该错误表示您的csv文件中的列多于for语句所期望的两列.要解决此问题,您可以采用所有列,然后仅分析前两列:

The error means that you have more columns in your csv file than just two which the for statement expects. To fix this, you could take all columns and then analyze only the first two:

for cols in reader:
    pickup_latitude, pickup_longitude = map(float, cols[0:2])

这篇关于快速将大型csv转换为geojson的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆