{"id":21735127,"url":"https://github.com/caltech-ipac/spatialindex","last_synced_at":"2025-04-13T01:52:18.600Z","repository":{"id":56469985,"uuid":"265669822","full_name":"Caltech-IPAC/SpatialIndex","owner":"Caltech-IPAC","description":"Spatial indexing library for use with DBMSs, including both C and Python interfaces.","archived":false,"fork":false,"pushed_at":"2021-04-09T18:52:00.000Z","size":180,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-13T01:52:07.430Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Caltech-IPAC.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}},"created_at":"2020-05-20T19:39:06.000Z","updated_at":"2024-11-12T10:10:58.000Z","dependencies_parsed_at":"2022-08-15T19:20:38.513Z","dependency_job_id":null,"html_url":"https://github.com/Caltech-IPAC/SpatialIndex","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Caltech-IPAC%2FSpatialIndex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Caltech-IPAC%2FSpatialIndex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Caltech-IPAC%2FSpatialIndex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Caltech-IPAC%2FSpatialIndex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Caltech-IPAC","download_url":"https://codeload.github.com/Caltech-IPAC/SpatialIndex/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248654055,"owners_count":21140235,"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":[],"created_at":"2024-11-26T05:12:00.923Z","updated_at":"2025-04-13T01:52:18.570Z","avatar_url":"https://github.com/Caltech-IPAC.png","language":"C","readme":"# SpatialIndex\n\n## Spatial Indexing Library for Astronomy\n\nOne of the most common database searches in astronomy involves finding all the \nobjects in a region of the sky.  Basic DBMS engines provide efficient indexed \nsearches only for single column (i.e. something that can be sorted linearly).\nSome servers are starting to support true multidimensional indexing (e.g.,\nR-Trees) but this is neither universal nor uniform.\n\nIt is, however, possible to leverage the standard internal database indexing\n(B-Tree) to support impressively efficient 2D indexing.  If one tesselates the\nsky into a hierarchical, Z-ordered space (using a scheme like a Heirarchical\nTriangular Mesh (HTM)  or Hierarchical Equal Area isoLatitude Pixelization\n(HEALPix)), then any \"object\" (sky coordinate) belongs to a specific \ntesselation cell and each cell has a unique ID (number).  This number can\nbe stored in an integer column in the database table.\n\nThen when one wants to perform a spatial search, the region can be converted\nto a range (actually set of ranges) of spatial index cell numbers and\n(because of the Z-ordering) these ranges tend to be co-located and can be\naccessed efficiently.  For large tables, this can speed up queries by orders\nof magnitude.\n\nTo perform a spatial search, the region can be converted to a range of spatial\nindex cell numbers and, because of the Z-ordering,  these ranges tend to be \nco-located and can therefore accessed efficiently.  For large tables, this can\nspeed up queries by orders of magnitude. The resultant records are actually a\nsuperset of those desired, but a simple geometric filtering, performed as part\nof the database query, removes the extraneous records.\n\nThe spatal searches require that the DBMS table be augmented with four extra\ncolumns: a spatial index column at some pre-chosen HTM/HEALPix level and the\nthree-vector (x,y,z) coordinate of the point on the sky.\n\nOur library converts a geometric constraint into a pair of constraints that\ncan be added to  SQL to turn it into a spatially-indexed region query.  For\ninstance, if the DBMS table has been indexed at HTM level 7, a cone on the\nsky at latitude 43.7, longitude 129.4 with radius 0.5 degrees gets turned\ninto the following SQL constraints \n\n\u003e   WHERE (   (htm7 = 245093) \n\u003e          OR (htm7 = 245098) \n\u003e          OR (htm7 = 245100)\n\u003e          OR (htm7 = 245105) \n\u003e          OR (htm7 = 245110)\n\u003e          OR (htm7 = 245118))\n\u003e\n\u003e     AND (-0.45888930755155893*x)+(0.55866098617988125*y)+(0.69088241107685844*z)\n\u003e         \u003e=9.99975630705394747e-01\n\nThese constraints are inserted into the SQL statement  submitted to the DBMS.\n\nBuilding the Python library:\n\nThe C spatial index code needs to be wrapped for Python use.  This is taken care\nof in the Makefile and consists of using Cython to compile the spatial-index.pyx\ncode (Python with Cython directives) into \"spatial_index.c\", then building \na LINUX library from the result plus our C libraries (our C code plus tinyhtm).\nThis results in a library file \"spatial_index.cpython-37m-x86_64-linux-gnu.so\"\nwhich has the right content to be loadable by the Python runtime and accessed by \nPython calls.\n\nThe last step is to turn this into a Wheel file that can be pip-install in\nour Python distribution and/or uploaded to PyPI.  This file is\n(dist/spatial_index-0.9-cp37-cp37m-linux_x86_64.whl).  There is bookkeepping\nas well, but the primary files in this sequence are again\n\n  spatial_index.c\n  spatial_index.cpython-37m-x86_64-linux-gnu.so\n  dist/spatial_index-0.9-cp37-cp37m-linux_x86_64.whl\n\n*The NASA Exoplanet Science Institute is operated by the California Institute\nof Technology, under contract with the National Aeronautics and Space Administration\nunder the Exoplanet Exploration Program.*\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaltech-ipac%2Fspatialindex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcaltech-ipac%2Fspatialindex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaltech-ipac%2Fspatialindex/lists"}