2
$\begingroup$

Can someone explain the following python code.

value_geojson["features"][0]["properties"]["title"]

value_geojson is a geojson variable. I like to think that I'm not a total python newbie but these are too many [] for me. I am a GeoJSON newbie though.

Would appreciate help on that one, eventhough I know it's probably to simple for SE

$\endgroup$

1 Answer 1

3
$\begingroup$

See sections 3.2 and 3.3 of the geojson standard.

It looks like value_geojson is a FeatureCollection object, which have a single member "features" which is a list of Feature objects. So

value_geojson["features"][0]

is now just the first Feature object. Those have a few members, including "properties", which is an arbitrary JSON object. At that point we're outside of the geojson standard, so whatever "title" means is more context-specific.

$\endgroup$
3
  • $\begingroup$ ok that already helped me a bit. So, "value_geojson["features"][0]" returns the first Object in value_geojson. Each Object is basically a python dictionary with the keys "properties" and "title". Thus, the full line returns the values of both keys for the first Object? In the tutorial I saw that line it returns "5000.00 ". Thus, "5000.00" is the value stored in "Properties" and " " is the value stored in "title"? $\endgroup$ Commented Jan 11, 2021 at 19:23
  • $\begingroup$ No, those last two are also nested. ...["properties"] is itself a dictionary, probably with many key-value pairs, one of which is evidently (very strangely) "title": "5000.00". Try printing value_geojson["features"][0]["properties"].keys(). $\endgroup$ Commented Jan 11, 2021 at 19:37
  • $\begingroup$ Ok I understand. Thanks a lot :). When I run your line I get: dict_keys(['fill', 'fill-opacity', 'stroke', 'stroke-opacity', 'stroke-width', 'title']). Thus, yes title has apparently the value "5000.00". $\endgroup$ Commented Jan 11, 2021 at 19:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.