Forum in maintenance, we will back soon 🙂
Notifications
Clear all
Covert JSON to GeoJSON
Share your Prompts & Tests
2
Posts
2
Users
2
Reactions
30
Views
Topic starter
Prompt: I want to convert using a python script a JSON to GEOJSON of locations where latitude and longitude have the coordinates of each point. here is the sample JSON to convert ===> "{data": { "licensePlate": "ABCDEFG", "locations": [ { "latitude": -33.381247, "longitude": -70.542402, "date": "2023-04-23 18:36:53", "speed": 5.0, "heading": 101, "altitude": 0 } //you can add more locations here. ]} }<===Â
Â
Output:Â
import json
# JSON original
json_data = { Â "data": { "licensePlate": "RHGBA18", "locations": [ { "latitude": -33.381247, "longitude": -70.542402, Â "date": "2023-04-23 18:36:53", "speed": 5.0, "heading": 101, "altitude": 0 }, { "latitude": -33.381275, "longitude": -70.542338, "date": "2023-04-23 18:36:54", "speed": 12.0, "heading": 129, "altitude": 0 } Â ] } }
# new object that has GeoJSON format
geojson = { "type": "FeatureCollection", "features": [] }
# for each point, we built a Feature of GeoJSON
for pos in json_data["data"]["positions"]:
feature = { "type": "Feature", "geometry": { "type": "Point", "coordinates": [pos["longitude"], pos["latitude"]] }, "properties": { "date": pos["date"], "speed": pos["speed"], "heading": pos["heading"], "altitude": pos["altitude"], Â "licensePlate": json_data["data"]["licensePlate"] } }
geojson["features"].append(feature)
# Finally, convert  GeoJSON to stringÂ
geojson_str = json.dumps(geojson)
print(geojson_str)
Â
Â
Â
Posted : 07/08/2023 11:41 pm
SSAdvisor reacted
Thanks for sharing. Did you try it? What were the results?
Posted : 07/09/2023 6:47 am
SSAdvisor reacted
Forum Information
Our newest member: Shaik Abdul Raheem
Latest Post: Affiliate tool.
Forum Icons:
Forum contains no unread posts
Forum contains unread posts
Topic Icons:
Not Replied
Replied
Active
Hot
Sticky
Unapproved
Solved
Private
Closed
[the_ad_group id="312"]