Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6707865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:41:24+00:00 2026-05-26T07:41:24+00:00

I have a table named coords with the following columns |name|lat|lon|und| import sqlite3 database

  • 0

I have a table named coords with the following columns |name|lat|lon|und|

import sqlite3
database = sqlite3.connect('geoida.db')
cursor = database.cursor()
cursor.execute("select lat, lon, und  from coords")
results = cursor.fetchall()

every line in table stores coordinates of one point of g r i d and distance from point to point is always in decimal 0.041667,
what is equal to 2.5”.
What I would like to achieve is to find 4 nearest adjacent points around given latitude and longitude in decimal.
We have to keep in mind that latitude and longitude of these four points have to fill quite simple condition:
excess between lat, lon of adjacent point and lat, lon
of given point must be less/equal 0.041667 on + or –
or we can treat this value as max radius divisive sought neighboring points from the given one.

for example:

for given point 56.02050000 13.02040000
4 nearest adjacent points taken from my coords table are:

56.000000   13.000000
56.000000   13.041667
56.041667   13.000000
56.041667   13.041667

Given points are stored in another database, where C1 is latitude and C2 is longitude

database = sqlite3.connect('F.tsj')
cursor = database.cursor()
cursor.execute("select C1, C2 from tblSoPoints")
results = cursor.fetchall()

How can I put such query using python?
Sorry for code but there’s something wrong with formating.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:41:25+00:00Added an answer on May 26, 2026 at 7:41 am
    def find_adjacent_coords(db, lat, lon, step=0.041667):
        """Find coords that are in a +/- step range of lat, lon."""
        #XXX disregard values near +/- 90 latitude, +/- 180 longitude
        coords_range = lat-step, lat+step, lon-step, lon+step
        return db.execute("""select lat, lon from coords where 
    lat > ? and lat < ? and
    lon > ? and lon < ?""", coords_range).fetchall()
    

    full example with rtree index

    Note: this code doesn’t include boundaries.

    For very efficient range queries if there are millions of coordinates you might need SQLite R-Tree index.

    For 1000000 entries the above approach takes ~0.16 seconds, but the function that uses rtree requires less than 1ms. For 10000 entries it is 800 µs vs. 20 µs for rtree-based solution for the data from the test. DISCLAIMER: The numbers are for the code I’ve posted that I run on my machine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table named categories, which contains ID(long), Name(varchar(50)), parentID(long), and shownByDefault(boolean) columns.
I have a table named with Sales having the following columns: Sales_ID|Product_Code|Zone|District|State|Distributor|Total_Sales Now i
I have a database table named call with columns call_time, location, emergency_type and there
I have a database table (named Topics) which includes these fields : topicId name
I have a table named scores with the columns id and score . I
I have table named 'testing' of 3 columns i.e. user,score,time in that 'time' is
I have table named 'Dictionary' with columns as follow: ID bigint TYPE varchar (200)
I have a table named Books which contains 3 columns. TableName: Books Columns: BookId
Suppose I have a table named [ProductPriceHistory] like the following: HistoryID..ProductCode..EffectDate.... Price.... IsActive...ProductName 1----------11-----------1
--I have a Table named CLASS with the Following Records in it (PK) ClassID

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.