Closed blag closed 8 years ago
Here's an example of the JSON data that is stored in the location data field:
[
{
"place_id": "59815669",
"licence": "Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright",
"osm_type": "way",
"osm_id": "15976890",
"boundingbox": [
"52.5170798", /* ymin */
"52.5173311", /* ymax */
"13.3975116", /* xmin */
"13.3981577" /* xmax */
],
"lat": "52.51720765",
"lon": "13.3978343993255",
"display_name": "Kommandantenhaus, 1, Unter den Linden, Scheunenviertel, Mitte, Berlin, 10117, Germany",
"class": "amenity",
"type": "public_building",
"importance": 0.62606775332943,
"address": {
"public_building": "Kommandantenhaus",
"house_number": "1",
"road": "Unter den Linden",
"neighbourhood": "Scheunenviertel",
"suburb": "Mitte",
"city_district": "Mitte",
"city": "Berlin",
"state": "Berlin",
"postcode": "10117",
"country": "Germany",
"country_code": "de"
}
}
]
Note that the bounding box coordinates come in with a weird order (ymin, ymax, xmin, xmax)
, but GeoDjango's Polygon.from_bbox()
expects a different order (xmin, ymin, xmax, ymax)
, and AFAIK there isn't an easy or "Pythonic" way to convert between the two. 😑
You could go with this, but I'm slightly unsure where you would want to do that.
d = data[0]['boundingbox']
data[0]['boundingbox'] = [d[2], d[0], d[3], d[1]]
Wait, I think I can just do:
fixedindex = (2, 0, 3, 1)
data[0]['boundingbox'] = [data[0]['boundingbox'][i] for i in fixedindex]
@@ develop #12 diff @@
==========================================
Files 5 6 +1
Lines 154 185 +31
Methods 0 0
Messages 0 0
Branches 14 19 +5
==========================================
+ Hits 136 167 +31
Misses 12 12
Partials 6 6
Powered by Codecov. Last updated by 2ef0aaa...f7f910f
Add support for a JSON data field in the form. This is useful for when users want to grab the
addressdetails
attribute from OSM and embed it into the form.From there it can either be used in the form to indicate country/state/city/zip, or it can be uploaded as part of the form data so the server can access that information without having to run the HTTP query to OSM itself.
Note that none of this data is protected in any special way (just like the latitude and longitude fields), so a user could definitely modify the data before uploading it to the server.
For users that want slightly more security, the
osm_id
andplace_id
keys in the JSON data to query the exact OSM location.This field is entirely optional and normal processing isn't affected if it isn't specified.