Skip to content

Instantly share code, notes, and snippets.

@yohanboniface
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yohanboniface/11147560 to your computer and use it in GitHub Desktop.
Save yohanboniface/11147560 to your computer and use it in GitHub Desktop.
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-3.1640625,
53.014783245859235
],
[
-3.1640625,
51.86292391360244
],
[
-0.50537109375,
51.385495069223204
],
[
1.16455078125,
52.38901106223456
],
[
-0.41748046875,
53.91728101547621
],
[
-2.109375,
53.85252660044951
],
[
-3.1640625,
53.014783245859235
]
]
]
},
"properties": {
"name": "Ho god, sounds like a polygouine"
}
},
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[
1.8017578124999998,
51.16556659836182
],
[
-0.48339843749999994,
49.710272582105695
],
[
-2.2412109375,
49.460983851109454
],
[
-3.1640625,
50.0923932109388
],
[
-5.60302734375,
51.998410382390325
]
]
},
"properties": {
"name": "Light line"
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-0.24169921874999997,
50.84757295365389
]
},
"properties": {
"_storage_options": {
"iconUrl": "/uploads/pictogram/airfield-24-white.png",
"showLabel": true,
"iconClass": "Ball",
"color": "OliveDrab"
},
"description": "<blockquote class=\"twitter-tweet\" lang=\"en\"><p>When streets Speak their Secrets! <a href=\"http://t.co/3899IeOiR8\">pic.twitter.com/3899IeOiR8</a></p>&mdash; Digital Parcoursdescription han\n sdfdfsf\n{{http://www.submarine.gg/image.jpg}}",
"name": "pouet en live mon pote"
}
}
]
}
#!/usr/bin/env python
"""geoflatjson
Usage:
geoflatjson.py toflat <filepath>
Options:
-h --help Show this screen.
--version Show version.
"""
import simplejson
from docopt import docopt
if __name__ == '__main__':
args = docopt(__doc__, version='geoflatjson 0.1')
if args['<filepath>']:
with open(args['<filepath>'], encoding='utf-8') as a_file:
g = simplejson.loads(a_file.read())
final = {
"type": [],
"coordinates": [],
}
for idx, f in enumerate(g['features']):
final['_type'].append(f['geometry']['type'])
final['_coordinates'].append(f['geometry']['coordinates'])
for key, value in f['properties'].items():
if not key in final:
final[key] = [''] * idx
final[key].append(value)
print(final)
{
"_type": ["Polygon", "LineString", "Point"],
"_coordinates": [[[[-3.1640625, 53.014783245859235], [-3.1640625, 51.86292391360244], [-0.50537109375, 51.385495069223204], [1.16455078125, 52.38901106223456], [-0.41748046875, 53.91728101547621], [-2.109375, 53.85252660044951], [-3.1640625, 53.014783245859235]]], [[1.8017578124999998, 51.16556659836182], [-0.48339843749999994, 49.710272582105695], [-2.2412109375, 49.460983851109454], [-3.1640625, 50.0923932109388], [-5.60302734375, 51.998410382390325]], [-0.24169921874999997, 50.84757295365389]],
"description": ["", "", "<blockquote class=\"twitter-tweet\" lang=\"en\"><p>When streets Speak their Secrets! <a href=\"http://t.co/3899IeOiR8\">pic.twitter.com/3899IeOiR8</a></p>&mdash; Digital Parcoursdescription han\n sdfdfsf\n{{http://www.submarine.gg/image.jpg}}"],
"name": ["Ho god, sounds like a polygouine", "Light line", "pouet en live mon pote"],
"_storage_options": ["", "", {"color": "OliveDrab", "iconUrl": "/uploads/pictogram/airfield-24-white.png", "iconClass": "Ball", "showLabel": true}]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment