Git Product home page Git Product logo

pyquadtree's Introduction

Documentation for PyQuadTree

A pure Python QuadTree spatial index for GIS or rendering usage.

Karim Bahgat, 2014

Version: 0.2

License: MIT

Platforms: Python 2x and 3x

Based on Matt Rasmussen's original code: https://github.com/mdrasmus/compbio/blob/master/rasmus/quadtree.py

Installing It

Installing PyQuadTree is as easy as putting the "pyqtree" folder anywhere Python can import it, such as the folder "PythonXX/Lib/site-packages"

Example Usage

Start your session by importing the module.

import pyqtree

Setup the spatial index, giving it a bounding box area to keep track of. The bounding box being in a four-tuple: (xmin,ymin,xmax,ymax).

spindex = pyqtree.Index(bbox=[0,0,100,100])

Populate the index with items that you want to be retrieved at a later point, along with each item's geographic bbox.

#this example assumes you have a list of items with bbox attribute
for item in items:
    spindex.insert(item=item, bbox=item.bbox)

Then when you have a region of interest and you wish to retrieve items from that region, just use the index's intersect method. This quickly gives you a list of the stored items whose bboxes intersects your region of interests.

overlapbbox = (51,51,86,86)
matches = spindex.intersect(overlapbbox)

There are other things that can be done as well, but that's it for the main usage!

Functions and Classes

pyqtree.Index(...) --> class object

The top spatial index to be created by the user. Once created it can be populated with geographically placed members that can later be tested for intersection with a user inputted geographic bounding box. Note that the index can be iterated through in a for-statement, which loops through all all the quad instances and lets you access their properties.

option description
bbox the coordinate system bounding box of the area that the quadtree should keep track of, as a 4-length sequence (xmin,ymin,xmax,ymax)
  • .countmembers(...):

Returns a count of the total number of members/items/nodes inserted into this quadtree and all of its child trees.

  • .insert(...):

Inserts an item into the quadtree along with its bounding box.

option description
item the item to insert into the index, which will be returned by the intersection method
bbox the spatial bounding box tuple of the item, with four members (xmin,ymin,xmax,ymax)
  • .intersect(...):

Intersects an input boundingbox rectangle with all of the items contained in the quadtree. Returns a list of items whose bounding boxes intersect with the input rectangle.

option description
bbox a spatial bounding box tuple with four members (xmin,ymin,xmax,ymax)
results only used internally

pyquadtree's People

Contributors

karimbahgat avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.