Skip to content

Commit

Permalink
Add support for Labeled Places.json format
Browse files Browse the repository at this point in the history
Saved Places format:

```json
{'geometry': {'coordinates': [...], 'type': 'Point'},
 'properties': {'Google Maps URL': '...',
  'Location': {'Address': '...',
   'Business Name': '...',
   'Country Code': 'US',
   'Geo Coordinates': {'Latitude': '...', 'Longitude': '...'}},
  'Published': '2018-05-02T01:46:02Z',
  'Title': '...',
  'Updated': '2018-05-02T01:46:02Z'},
 'type': 'Feature'}
```

Labeled Places format:

```json
{'geometry': {'coordinates': [...], 'type': 'Point'},
 'properties': {'address': '...',
  'name': 'Home'},
 'type': 'Feature'}
```
  • Loading branch information
endolith committed Oct 23, 2022
1 parent c4e7372 commit bfbe590
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions json2kml.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,28 @@
count = 0
for place in data["features"]:
if place["type"] == "Feature":
name = html.escape(place["properties"]["Title"])
try:
name = html.escape(place["properties"]["Title"])
except KeyError:
name = html.escape(place["properties"]["name"])
print(f'Parsing place "{name}"')

placeLocation = place["properties"]["Location"]
lon = place["geometry"]["coordinates"][0]
lat = place["geometry"]["coordinates"][1]

if "Address" in placeLocation:
address = html.escape(placeLocation["Address"])
else:
address = None
try:
placeLocation = place["properties"]["Location"]

if "Address" in placeLocation:
address = html.escape(placeLocation["Address"])
else:
address = None

except KeyError:
if 'address' in place['properties']:
address = html.escape(place['properties']['address'])
else:
address = None

kml.newpoint(name=name, coords=[(lon, lat)], address=address)
count += 1
Expand Down

0 comments on commit bfbe590

Please sign in to comment.