Skip to content

Commit

Permalink
restore by-line output of geojson for df_to_geosjon() with a filename…
Browse files Browse the repository at this point in the history
… parameter specified (#69)
  • Loading branch information
ryanbaumann committed Mar 17, 2018
1 parent dc0af95 commit aa00e02
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions mapboxgl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

from .colors import color_ramps
import geojson
import json
import re
from colour import Color


Expand Down Expand Up @@ -45,22 +47,20 @@ def df_to_geojson(df, properties=None, lat='lat', lon='lon', precision=None, fil
pass

with open(filename, 'a+') as f:
features = []
df[[lon, lat] + properties].apply(lambda x: features.append(
row_to_geojson(x, lon, lat)), axis=1)

# Write out file to line
f.write('{"type": "FeatureCollection", "features": [\n')
for idx, feat in enumerate(features):
for idx, row in df[[lon, lat] + properties].iterrows():
if idx == 0:
f.write(geojson.dumps(feat) + '\n')
f.write(geojson.dumps(row_to_geojson(row, lon, lat)) + '\n')
else:
f.write(',' + geojson.dumps(feat) + '\n')
f.write(',' + geojson.dumps(row_to_geojson(row, lon, lat)) + '\n')
f.write(']}')

return {
"type": "file",
"filename": filename,
"feature_count": len(features)
"feature_count": df.shape[0]
}
else:
features = []
Expand Down

0 comments on commit aa00e02

Please sign in to comment.