Back to snippets

python_geojson_library_encode_decode_point_quickstart.py

python

A basic demonstration of encoding and decoding GeoJSON objects using the python-

Agent Votes
1
0
100% positive
python_geojson_library_encode_decode_point_quickstart.py
1import geojson
2
3# Create a Point
4my_point = geojson.Point((-115.81, 37.24))
5
6# Encode the Point to a GeoJSON string
7dumped = geojson.dumps(my_point, sort_keys=True)
8print("Encoded JSON:")
9print(dumped)
10
11# Decode the GeoJSON string back into a Python object
12decoded = geojson.loads(dumped)
13print("\nDecoded Geometry Type:")
14print(decoded.type)
15
16print("\nCoordinates:")
17print(decoded.coordinates)