GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — putianxi.github.io/assets/script/csv2geojson.py at master · putianxi/putianxi.github.io

Expand file tree

/

csv2geojson.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
executable file
·
60 lines (48 loc) · 1.53 KB
/

csv2geojson.py

Copy path

File metadata and controls

executable file
·
60 lines (48 loc) · 1.53 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# -*- coding: utf-8 -*-
import json
import csv
CSV_FILE = '../data/hospital.csv'
GEOJSON_FILE = '../data/hospital.geojson'
# final feature list
features_list = []
def generate_feature_data(hospital_data):
feature_data = {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
hospital_data['geo_lat'],
hospital_data['geo_lng'],
]
},
"properties": {
"id": hospital_data['id'],
"name": hospital_data['name'],
"province": hospital_data['province'],
"city": hospital_data["city"],
"district": hospital_data["district"],
"address": hospital_data["address"],
"phone": hospital_data["phone"].strip(),
"google_map_id": hospital_data["google_map_id"],
"gaode_map_id": hospital_data['gaode_map_id'],
},
}
return feature_data
def generate_geojson():
geojson_data = {
"type": "FeatureCollection",
"features": features_list,
}
return geojson_data
def main():
with open(CSV_FILE, 'r') as f:
f_csv = csv.DictReader(f)
for hospital_data in f_csv:
feature_data = generate_feature_data(hospital_data)
features_list.append(feature_data)
geojson_data = generate_geojson()
with open(GEOJSON_FILE, 'w') as f:
json.dump(geojson_data, f, ensure_ascii=False)
print("Write file {} done".format(GEOJSON_FILE))
if __name__ == '__main__':
main()
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.