{"id":13630266,"url":"https://github.com/dhconnelly/rtreego","last_synced_at":"2025-05-15T03:13:40.291Z","repository":{"id":2393508,"uuid":"3359810","full_name":"dhconnelly/rtreego","owner":"dhconnelly","description":"an R-Tree library for Go","archived":false,"fork":false,"pushed_at":"2024-12-20T06:54:41.000Z","size":252,"stargazers_count":626,"open_issues_count":5,"forks_count":124,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-04-10T20:24:05.388Z","etag":null,"topics":["algorithms","datastructures","geospatial","go","golang","r-tree","rtree","spatial"],"latest_commit_sha":null,"homepage":"http://dhconnelly.github.com/rtreego","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"gruntjs/grunt-contrib-jshint","license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dhconnelly.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2012-02-05T14:29:59.000Z","updated_at":"2025-04-09T01:54:26.000Z","dependencies_parsed_at":"2023-11-17T00:11:44.577Z","dependency_job_id":"b8e13654-a444-4e1b-80f2-bfa8648e193f","html_url":"https://github.com/dhconnelly/rtreego","commit_stats":{"total_commits":148,"total_committers":17,"mean_commits":8.705882352941176,"dds":0.3648648648648649,"last_synced_commit":"b0f9edc4249785cabb5dc928ca41721defb99f75"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhconnelly%2Frtreego","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhconnelly%2Frtreego/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhconnelly%2Frtreego/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhconnelly%2Frtreego/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dhconnelly","download_url":"https://codeload.github.com/dhconnelly/rtreego/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249344831,"owners_count":21254746,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithms","datastructures","geospatial","go","golang","r-tree","rtree","spatial"],"created_at":"2024-08-01T22:01:36.542Z","updated_at":"2025-04-17T13:31:56.493Z","avatar_url":"https://github.com/dhconnelly.png","language":"Go","funding_links":[],"categories":["开源类库","Go","Open source library","Repositories"],"sub_categories":["数据结构","Data Structure"],"readme":"rtreego\n=======\n\nA library for efficiently storing and querying spatial data\nin the Go programming language.\n\n[![CI](https://github.com/dhconnelly/rtreego/actions/workflows/go.yml/badge.svg)](https://github.com/dhconnelly/rtreego/actions/workflows/go.yml)\n[![Go Report Card](https://goreportcard.com/badge/github.com/dhconnelly/rtreego)](https://goreportcard.com/report/github.com/dhconnelly/rtreego)\n[![GoDoc](https://godoc.org/github.com/dhconnelly/rtreego?status.svg)](https://godoc.org/github.com/dhconnelly/rtreego)\n\nAbout\n-----\n\nThe R-tree is a popular data structure for efficiently storing and\nquerying spatial objects; one common use is implementing geospatial\nindexes in database management systems. Both bounding-box queries\nand k-nearest-neighbor queries are supported.\n\nR-trees are balanced, so maximum tree height is guaranteed to be\nlogarithmic in the number of entries; however, good worst-case\nperformance is not guaranteed.  Instead, a number of rebalancing\nheuristics are applied that perform well in practice.  For more\ndetails please refer to the references.\n\nThis implementation handles the general N-dimensional case; for a more\nefficient implementation for the 3-dimensional case, see [Patrick\nHiggins' fork](https://github.com/patrick-higgins/rtreego).\n\nGetting Started\n---------------\n\nGet the source code from [GitHub](https://github.com/dhconnelly/rtreego) or,\nwith Go 1 installed, run `go get github.com/dhconnelly/rtreego`.\n\nMake sure you `import github.com/dhconnelly/rtreego` in your Go source files.\n\nDocumentation\n-------------\n\n### Storing, updating, and deleting objects\n\nTo create a new tree, specify the number of spatial dimensions and the minimum\nand maximum branching factor:\n```Go\n    rt := rtreego.NewTree(2, 25, 50)\n```\nYou can also bulk-load the tree when creating it by passing the objects as\na parameter.\n```Go\n    rt := rtreego.NewTree(2, 25, 50, objects...)\n```\nAny type that implements the `Spatial` interface can be stored in the tree:\n```Go\n    type Spatial interface {\n      Bounds() *Rect\n    }\n```\n`Rect`s are data structures for representing spatial objects, while `Point`s\nrepresent spatial locations.  Creating `Point`s is easy--they're just slices\nof `float64`s:\n```Go\n    p1 := rtreego.Point{0.4, 0.5}\n    p2 := rtreego.Point{6.2, -3.4}\n```\nTo create a `Rect`, specify a location and the lengths of the sides:\n```Go\n    r1, _ := rtreego.NewRect(p1, []float64{1, 2})\n    r2, _ := rtreego.NewRect(p2, []float64{1.7, 2.7})\n```\nTo demonstrate, let's create and store some test data.\n```Go\n    type Thing struct {\n      where *Rect\n      name string\n    }\n\n    func (t *Thing) Bounds() *Rect {\n      return t.where\n    }\n\n    rt.Insert(\u0026Thing{r1, \"foo\"})\n    rt.Insert(\u0026Thing{r2, \"bar\"})\n\n    size := rt.Size() // returns 2\n```\nWe can insert and delete objects from the tree in any order.\n```Go\n    rt.Delete(thing2)\n    // do some stuff...\n    rt.Insert(anotherThing)\n```\nNote that ```Delete``` function does the equality comparison by comparing the\nmemory addresses of the objects. If you do not have a pointer to the original\nobject anymore, you can define a custom comparator.\n```Go\n    type Comparator func(obj1, obj2 Spatial) (equal bool)\n```\nYou can use a custom comparator with ```DeleteWithComparator``` function.\n```Go\n    cmp := func(obj1, obj2 Spatial) bool {\n      sp1 := obj1.(*IDRect)\n      sp2 := obj2.(*IDRect)\n\n      return sp1.ID == sp2.ID\n    }\n\n    rt.DeleteWithComparator(obj, cmp)\n```\nIf you want to store points instead of rectangles, you can easily convert a\npoint into a rectangle using the `ToRect` method:\n```Go\n    var tol = 0.01\n\n    type Somewhere struct {\n      location rtreego.Point\n      name string\n      wormhole chan int\n    }\n\n    func (s *Somewhere) Bounds() *Rect {\n      // define the bounds of s to be a rectangle centered at s.location\n      // with side lengths 2 * tol:\n      return s.location.ToRect(tol)\n    }\n\n    rt.Insert(\u0026Somewhere{rtreego.Point{0, 0}, \"Someplace\", nil})\n```\nIf you want to update the location of an object, you must delete it, update it,\nand re-insert.  Just modifying the object so that the `*Rect` returned by\n`Location()` changes, without deleting and re-inserting the object, will\ncorrupt the tree.\n\n### Queries\n\nBounding-box and k-nearest-neighbors queries are supported.\n\nBounding-box queries require a search `*Rect`. This function will return all\nobjects which has a non-zero intersection volume with the input search rectangle.\n```Go\n    bb, _ := rtreego.NewRect(rtreego.Point{1.7, -3.4}, []float64{3.2, 1.9})\n\n    // Get a slice of the objects in rt that intersect bb:\n    results := rt.SearchIntersect(bb)\n```\n### Filters\n\nYou can filter out values during searches by implementing Filter functions.\n```Go\n    type Filter func(results []Spatial, object Spatial) (refuse, abort bool)\n```\nA filter for limiting results by result count is included in the package for\nbackwards compatibility.\n```Go\n    // maximum of three results will be returned\n    tree.SearchIntersect(bb, LimitFilter(3))\n```\nNearest-neighbor queries find the objects in a tree closest to a specified\nquery point.\n```Go\n    q := rtreego.Point{6.5, -2.47}\n    k := 5\n\n    // Get a slice of the k objects in rt closest to q:\n    results = rt.NearestNeighbors(k, q)\n```\n### More information\n\nSee [GoDoc](http://godoc.org/github.com/dhconnelly/rtreego) for full API\ndocumentation.\n\nReferences\n----------\n\n- A. Guttman.  R-trees: A Dynamic Index Structure for Spatial Searching.\n  Proceedings of ACM SIGMOD, pages 47-57, 1984.\n  http://www.cs.jhu.edu/~misha/ReadingSeminar/Papers/Guttman84.pdf\n\n- N. Beckmann, H .P. Kriegel, R. Schneider and B. Seeger.  The R*-tree: An\n  Efficient and Robust Access Method for Points and Rectangles.  Proceedings\n  of ACM SIGMOD, pages 323-331, May 1990.\n  http://infolab.usc.edu/csci587/Fall2011/papers/p322-beckmann.pdf\n\n- N. Roussopoulos, S. Kelley and F. Vincent.  Nearest Neighbor Queries.  ACM\n  SIGMOD, pages 71-79, 1995.\n  http://www.postgis.org/support/nearestneighbor.pdf\n\nAuthor\n------\n\nWritten by [Daniel Connelly](http://dhconnelly.com) (\u003cdhconnelly@gmail.com\u003e).\n\nLicense\n-------\n\nrtreego is released under a BSD-style license, described in the `LICENSE`\nfile.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdhconnelly%2Frtreego","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdhconnelly%2Frtreego","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdhconnelly%2Frtreego/lists"}