One of the cool thing about graphs is they can link to themselves. The reason why this is a graph and not a quad tree (as most maps are) is to create recursive images.
Here we will see how to create a recursive image continuing from the getting started image. Let us create a recursive image where Mt. Tacoma is inside Seattle, and Seattle is inside Mt. Tacoma.
In [18]:
%pylab inline
import sys
import os
sys.path.insert(0,'..')
import graphmap
from graphmap.graphmap_main import GraphMap
from graphmap.memory_persistence import MemoryPersistence
from graphmap.graph_helpers import NodeLink
In [19]:
G = GraphMap(MemoryPersistence())
seattle_skyline_image_url = 'https://upload.wikimedia.org/wikipedia/commons/thumb/2/2f/Space_Needle002.jpg/640px-Space_Needle002.jpg'
mt_tacoma_image_url = 'https://upload.wikimedia.org/wikipedia/commons/thumb/a/a2/Mount_Rainier_from_the_Silver_Queen_Peak.jpg/1024px-Mount_Rainier_from_the_Silver_Queen_Peak.jpg'
seattle_node_link = NodeLink('seattle')
mt_tacoma_node_link = NodeLink('tacoma')
G.create_node(root_node_link=seattle_node_link, image_value_link=seattle_skyline_image_url)
G.create_node(root_node_link=mt_tacoma_node_link, image_value_link=mt_tacoma_image_url)
insert_quad_key = '13'
created_node_link_result = G.connect_child(root_node_link=seattle_node_link,
quad_key=insert_quad_key,
child_node_link=mt_tacoma_node_link)
created_node_link = created_node_link_result.value
print(created_node_link_result)
In [20]:
plt.imshow(G.get_image_at_quad_key(created_node_link, 256, '').value)
Out[20]:
In [21]:
recursive_quad_key = '1333'
recursive_node_link_result = G.connect_child(root_node_link=created_node_link,
quad_key=recursive_quad_key,
child_node_link=created_node_link)
recursive_node_link = recursive_node_link_result.value
print(recursive_node_link_result)
In [22]:
plt.imshow(G.get_image_at_quad_key(recursive_node_link, 256, '').value)
plt.figure()
plt.imshow(G.get_image_at_quad_key(recursive_node_link, 256, '1').value)
plt.figure()
plt.imshow(G.get_image_at_quad_key(recursive_node_link, 256, '13').value)
Out[22]:
Suppose we want to create an infinitely thin line. We could describe it this neat way
self = [ self , blue ]
[ green, self ]
As it replaces self with definition of self it will look like this
The end product will be
This is an infinitely thin line between colors blue and green. You can keep zooming but never see a blunt edge. View it in KaiiMaps
In [ ]: