All Projects → jblindsay → kdtree

jblindsay / kdtree

Licence: MIT license
A pure Nim k-d tree implementation for efficient spatial querying of point data

Programming Languages

nim
578 projects

Projects that are alternatives of or similar to kdtree

rsgislib
Remote Sensing and GIS Software Library; python module tools for processing spatial data.
Stars: ✭ 103 (+157.5%)
Mutual labels:  gis, spatial-analysis, spatial-data
python-for-gis-progression-path
Progression path for a GIS analyst who wants to become proficient in using Python for GIS: from apprentice to guru
Stars: ✭ 98 (+145%)
Mutual labels:  gis, spatial-analysis, spatial-data
Osmnx
OSMnx: Python for street networks. Retrieve, model, analyze, and visualize street networks and other spatial data from OpenStreetMap.
Stars: ✭ 3,357 (+8292.5%)
Mutual labels:  gis, spatial-analysis, spatial-data
GeoArrays.jl
Simple geographical raster interaction built on top of ArchGDAL, GDAL and CoordinateTransformations
Stars: ✭ 42 (+5%)
Mutual labels:  gis, spatial-data
Awesome Geospatial
Long list of geospatial tools and resources
Stars: ✭ 2,386 (+5865%)
Mutual labels:  spatial-analysis, spatial-data
QGIS-visualization-workshop
QGIS visualization workshop materials.
Stars: ✭ 46 (+15%)
Mutual labels:  gis, spatial-data
spatial efd
A spatial aware implementation of elliptical Fourier analysis
Stars: ✭ 19 (-52.5%)
Mutual labels:  gis, spatial-analysis
topo
A Geometry library for Elixir that calculates spatial relationships between two geometries
Stars: ✭ 125 (+212.5%)
Mutual labels:  gis, spatial-analysis
Landsat8 scene calculator
Creates NDVI, SAVI, RBG, NIR, short wave infrared, agriculture, geology, and bathymetric GeoTIFF files using Landsat8 imagery.
Stars: ✭ 37 (-7.5%)
Mutual labels:  gis, spatial-analysis
shadow-accrual-maps
Accumulated shadow data computed for New York City
Stars: ✭ 15 (-62.5%)
Mutual labels:  gis, spatial-analysis
geospark
bring sf to spark in production
Stars: ✭ 53 (+32.5%)
Mutual labels:  gis, spatial-analysis
Peartree
peartree: A library for converting transit data into a directed graph for sketch network analysis.
Stars: ✭ 116 (+190%)
Mutual labels:  gis, spatial-analysis
covid hospitals demographics
COVID-19 relevant data on hospital location / capacity, nursing home location / capacity, county demographics
Stars: ✭ 21 (-47.5%)
Mutual labels:  gis, spatial-data
Urbansprawl
Open framework for calculating spatial urban sprawl indices and performing disaggregated population estimates using open data
Stars: ✭ 48 (+20%)
Mutual labels:  gis, spatial-analysis
Awesome Gis
😎Awesome GIS is a collection of geospatial related sources, including cartographic tools, geoanalysis tools, developer tools, data, conference & communities, news, massive open online course, some amazing map sites, and more.
Stars: ✭ 2,582 (+6355%)
Mutual labels:  gis, spatial-analysis
Earthenterprise
Google Earth Enterprise - Open Source
Stars: ✭ 2,425 (+5962.5%)
Mutual labels:  gis
Ziptastic Jquery Plugin
This is a jQuery plugin that shows how Ziptastic could be used.
Stars: ✭ 244 (+510%)
Mutual labels:  gis
Openglobus
JavaScript 3d maps and geospatial data visualization engine library.
Stars: ✭ 199 (+397.5%)
Mutual labels:  gis
L7
🌎 Large-scale WebGL-powered Geospatial Data Visualization analysis framework which relies on Mapbox GL or AMap to render basemaps.
Stars: ✭ 2,517 (+6192.5%)
Mutual labels:  gis
gis4wrf
QGIS toolkit 🧰 for pre- and post-processing 🔨, visualizing 🔍, and running simulations 💻 in the Weather Research and Forecasting (WRF) model 🌀
Stars: ✭ 137 (+242.5%)
Mutual labels:  gis

kdtree

Contents

  1. Description
  2. Documentation
  3. Usage

1 Description

kdtree is a pure Nim k-d tree implementation. k-d trees are data structures for performing efficient spatial query operations on point data sets. This implementation is very flexible, allowing for nearest-neighbour (single and multiple), within-radius (circular search areas), and range (rectangular search areas) spatial queries.

2 Documentation

Documentation for kdtree can be found here.

3 Usage

import random, strformat
import kdtree
 
# Generate 100,000 random points
let numPoints = 100_000
var
  points = newSeqOfCap[array[2, float]](numPoints)
  values = newSeqOfCap[int](numPoints) 
  x: float
  y: float
  r = initRand(34)
 
for a in 0..<numPoints:
  x = r.rand(100.0)
  y = r.rand(100.0)
  points.add([x, y])
  values.add(a)
 
echo fmt"Building tree of {numPoints} random points..."
var tree = newKdTree[int](points, values)
# Notice that our 'values' are of int type here; the data associated with points can be of any generic data type.

# The preferred method of tree construction is bulk loading of point data using 'newKdTree'. However, you
# may also add individual points.
x = r.rand(100.0)
y = r.rand(100.0)
let value = numPoints
tree.add([x, y], value)

# However, adding many individual points can result in an unbalanced tree, which can result in inefficient queries. 
# You may check the tree balance and re-balance the tree if necessary.
let balance = tree.isBalanced() # The larger the value magnitude, the more unbalanced the tree is. The sign indicates 
                                # the direction of skew, with negative values indicating a left-skewed tree and positive 
                                # values indicated a right-skewed tree.

if abs(balance) > 1:
    tree.rebalance()


############################ 
# Spatial query operations #
############################ 

# Perform nearestNeighour searches
let numSearches = 10_000
for a in 0..<numSearches:
  x = r.rand(100.0)
  y = r.rand(100.0)
  let (pt, values, dist) = tree.nearestNeighbour([x, y])
  echo fmt"point={pt}, value={value}, dist={dist}"
 
# Perform nearestNeighours searches
let n = 10
for a in 0..<numSearches:
  x = r.rand(100.0)
  y = r.rand(100.0)
  let ret = tree.nearestNeighbours([x, y], n)
  for (pt, value, dist) in ret:
    echo fmt"point={pt}, value={value}, dist={dist}"

# Perform a withinRadius search
x = 50.0
y = 50.0
var ret2 = tree.withinRadius([x, y], radius=5.0, sortResults=true)
for (pt, value, dist) in ret2:
  echo fmt"point={pt}, value={value}, dist={dist}"
 
# Perform a withinRange search
var 
  min: array[2, float] = [0.0, 0.0]
  max: array[2, float] = [10.0, 10.0]
  hyperRect = newHyperRectangle(min, max)

var ret = tree.withinRange(hyperRect)
for (pt, value) in ret:
  echo fmt"point={pt}, value={value}"
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].