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
  • Loading branch information
ryanbaumann committed Mar 13, 2018
1 parent e00bad3 commit 0842dfe
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions mapboxgl/utils.py
@@ -1,5 +1,7 @@
from .colors import color_ramps
import geojson, json, re
import geojson
import json
import re
from colour import Color


Expand Down Expand Up @@ -39,22 +41,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 0842dfe

Please sign in to comment.