Skip to content

A C extension for doing quad trees (spatial indexing) in Python.

Notifications You must be signed in to change notification settings

Dav3xor/pyquadtree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pyquadtree

A C extension for doing quad trees (spatial indexing) in Python.

Usage

First, you need to make a new tree:

import quadtree
quadtree = quadtree.QuadTree(0,0,1000,1000)

Then, you can add some data at different (x,y) locations:

quadtree.addpoint(1,1,'abc')
quadtree.addpoint(1,2,'def')
quadtree.addpoint(1,3,'ghi')

If you want to find a list of things within 5 units of the location (1,1):

quadtree.listnearby(1,1,5)   --> ['ghi','def','abc']
quadtree.listnearby(1,1,2.1) --> ['def','abc']

You can also map a function to points given a location and a radius:

def fun(arg):
  print arg[0]
quadtree.maptonearby(fun,1,1,.1) --> (prints) abc

Lastly, you can delete a thing from the quadtree, given the thing and it's location:

x = 5
quadtree.addpoint(5,5,x)
quadtree.deletepoint(5,5,x)

About

A C extension for doing quad trees (spatial indexing) in Python.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published