0

I am trying to get data put on a leaflet map that I have set up. I am following this tutorial: https://www.youtube.com/watch?v=fDfkjx-VhLI

I have all of the html, css and js scripts up and running, and I have entered my geojson .js file the same way as in the video. It is not showing up, and I think it is because my geojson looks like this:

var data = {"features": [{"geometry": {"coordinates": [51.05632117022859, -114.0952643473764], "type": "Point"}, "properties": {"address": "429 14 ST, CALGARY, AB", "complaint": "Back alley. Storm drain flooded. And parkade and apartment building are flooded", "id": "15-00468661", "status": "OPENED", "ward": "7"}, "type": "Feature"}, {"geometry": {"coordinates": [51.03665002997416, -114.0447471198658], "type": "Point"}, "properties": {"address": "607 ALBERTA AV, CALGARY, AB", "complaint": "Developer grading today- dug and and damaged tree roots to city protected tree.", "id": "15-00468646", "status": "OPENED", "ward": "9"}, "type": "Feature"}, {"geometry": {"coordinates": [51.05389046021835, -114.0834087320735], "type": "Point"}, "properties": {"address": "1022 1 AV, CALGARY, AB", "complaint": "Loose tree branch knocked off by storm sitting precariously in large tree about 3 stories above sidewalk. Potentially hazardous if it is dislodged.", "id": "15-00468618", "status": "OPENED", "ward": "7"}, "type": "Feature"}, {"geometry": {"coordinates": [51.096251, -113.981983], "type": "Point"}, "properties": {"address": "4881 METIS TR, CALGARY, AB", "complaint": "Potholes at bottom of ramp from Mcknight to metis Tr  southbound.", "id": "15-00468588", "status": "OPENED", "ward": "3"}, "type": "Feature"}, {"geometry": {"coordinates": [51.05480794333951, -114.0375342407394], "type": "Point"}, "properties": {"address": "404 10 ST, CALGARY, AB", "complaint": "Branches from city trees in front yard.", "id": "15-00468584", "status": "OPENED", "ward": "9"}, "type": "Feature"}, {"geometry": {"coordinates": [51.068128, -113.974563], "type": "Point"}, "properties": {"address": "207 RUNDLERIDGE RD, CALGARY, AB", "complaint": "Street is flooding East of us and the manhole cover is almost off with water gushing out.", "id": "15-00467971", "status": "CLOSED", "ward": "5"}, "type": "Feature"}, {"geometry": {"coordinates": [51.110387, -113.966348], "type": "Point"}, "properties": {"address": "5167 64 AV, CALGARY, AB", "complaint": "Uneven road on 64 ave from martindale Dr to martindale gate westbound  64 ave.", "id": "15-00468582", "status": "OPENED", "ward": "5"}, "type": "Feature"}, {"geometry": {"coordinates": [50.955734, -114.104648], "type": "Point"}, "properties": {"address": "10819 BRAE RD, CALGARY, AB", "complaint": "Residents leave their garbage cart overflowing, which leads to magpies ripping bags open and spreading rubbish all over the alleyway.", "id": "15-00468568", "status": "OPENED", "ward": "11"}, "type": "Feature"}, {"geometry": {"coordinates": [51.110603, -113.946894], "type": "Point"}, "properties": {"address": "64 AV, CALGARY, AB", "complaint": "Uneven road please fix this i have report this before but nothing been done. If you drive you car your car just fly twice in the air and winter time no mater how slow you go rhere is more chance to slip. Please fix this intersection.", "id": "15-00468560", "status": "OPENED", "ward": "4"}, "type": "Feature"}, {"geometry": {"coordinates": [51.110708, -113.946829], "type": "Point"}, "properties": {"address": "FALCONRIDGE BV, CALGARY, AB", "complaint": "Potholes when you tuen to falconridge blvd  from 64 ave NE", "id": "15-00468558", "status": "OPENED", "ward": "5"}, "type": "Feature"}], "type": "FeatureCollection"};

At about the 1:20 mark in the video, I see that the tutorial maker's data has "type": "FeatureCollection" at the front of the data, and in mine, it is at the very end. I need a way to automatically translate some real-time data into geojson, and so I am using a script like this:

feature_collection = FeatureCollection(feature_list)
#print(feature_collection)

print(geojson.dumps(feature_collection))

f = open("F:\calgary311\data.js", "w")
f.write("var data = ")
f.write(geojson.dumps(feature_collection, sort_keys=True))
f.write(";")
f.close()

Is there a way to specify the geojson.dumps() method to put the "type": "FeatureCollection" at the beginning instead of at the end? Would this even matter?

4

GeoJSON is a JSON format, and in that, the order of the attributes is not important.

It does not matter if you have the "type": "FeatureCollection" first, or after the "features" array.

Both will work with all software that read GeoJSON.

However please note, that I think you have another problem in your data. I think your latitude & longitude values are switched. You have coordinates like [51.068128, -113.974563] and GeoJSON needs coordinates in longitude, latitude order; There can't be a latitude of -113

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.