Я новичок в геопространственных данных и мне нужен способ получить данные из CSV в этом формате:
Latitude, Longitude, Altitude, Timestamp, Trip Identifier
и в геойсон, подходящий для kepler.gl
суказанный ими формат:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": { "vendor": "A",
"vol":20},
"geometry": {
"type": "LineString",
"coordinates": [
[-74.20986, 40.81773, 0, 1564184363],
[-74.20987, 40.81765, 0, 1564184396],
[-74.20998, 40.81746, 0, 1564184409]
]
}
}
]
}
Мои попытки в Python (в значительной степени основанные на коде из ewcz ) не увенчались успехом;это возвращает ValueError, и я не вижу способа включить MultiLineString, поскольку число пар координат изменяется между записями.
import csv, json
from geojson import Feature, FeatureCollection, Point, LineString
features = []
with open('Trips.csv', newline='', encoding='utf-16') as csvfile:
reader = csv.reader(csvfile, delimiter=' ')
for Latitude, Longitude, Altitude, Timestamp, ID in reader:
Latitude, Longitude = map(float, (Latitude, Longitude))
features.append(
Feature(
geometry = LineString([Latitude,Longitude,Altitude,Timestamp]),
properties = {
'ID': ID,
}
)
)
collection = FeatureCollection(features)
with open("Trips.json", "w") as f:
f.write('%s' % collection)
Ошибка дана:
ValueError Traceback (most recent call last)
<ipython-input-1-5dadf758869b> in <module>
9 features.append(
10 Feature(
---> 11 geometry = LineString([Latitude,Longitude,Altitude,Timestamp]),
12 properties = {
13 'ID': ID
~/anaconda3/anaconda3/lib/python3.7/site-packages/geojson/geometry.py in __init__(self, coordinates, validate, precision, **extra)
30 super(Geometry, self).__init__(**extra)
31 self["coordinates"] = self.clean_coordinates(
---> 32 coordinates or [], precision)
33
34 if validate:
~/anaconda3/anaconda3/lib/python3.7/site-packages/geojson/geometry.py in clean_coordinates(cls, coords, precision)
53 new_coords.append(round(coord, precision))
54 else:
---> 55 raise ValueError("%r is not a JSON compliant number" % coord)
56 return new_coords
57
ValueError: '0' is not a JSON compliant number