SQLite: Query for Latitude/Longitude Delta - sqlite

I have a SQLite table with fields Latitude and Longitude (neg and pos numbers)
I have a latitude *delta* and a longitude *delta* of (for example '23') based on a Latitude of 50 and a longitude of 75 (again, for example)
How do I query the table for a list of all records which are + or - 23 latitudes and + or - 23 longitudes when there are both positive and negative latitude and longitude values in the table.
The lat/long fields are of type NUMERIC and are indexed ASC.
select [fields]
from [table]
where latitude of 50 -+23 and
longitude of 75 -+23

Lookup the delta and stating values first
Calculate the +/- values based on the delta and the starting values per-record
Use the "BETWEEN operator" to get the result (scroll down on that link to find the info)
If you're using an ORM between you and the database, or a programming language on top of the DB, you might be able to do steps 1 and 2 on the fly, thereby only executing one DB query in step 3.

Related

PostGIS - Finding aggregated counts on dissolved polygons

I have set this WITH query to get dissolved polygons where polygons overlap:
CREATE TABLE public.dissolve_intrsct AS
( WITH dissolved AS(
SELECT ST_Union(pt.geom) as geom, count(geom) as buff_ct,
count(pt.count) as intrsct_ct
FROM public.intrsct_buff as pt
)
SELECT (ST_DUMP(geom)).geom::geometry(POLYGON, 2263), intrsct_ct, buff_ct
FROM dissolved);
My output returns the geometry(good), but also returns the total count of all geometries before the query(59144) for both intrsct_buff and buff_ct
I want the query to return the number of polygons that were dissolved to create the new polygon. (i.e. If three polygons overlap, after this query I want buff_ct to return 3, along with intrsct_ct just returning the original count I had in public.intrsct_buff)
I found what needed to be done..
After creating this table and adding a PRIMARY KEY ID, I then used ST_Intersects to find where my dissolved polygons intersected with the original buffer, and counted the number of intersecting polygons.
See code below:
`
CREATE TABLE dissolve_ct AS(
SELECT ds.id, ds.geom, count(pt.geom) AS
buff_ct
FROM public.dissolve_intrsct as ds
LEFT JOIN public.intrsct_buff as pt
ON ST_Intersects(ds.geom, pt.geom)
GROUP BY ds.id
);
`

Aggregate geolocation data [long / lat]

I have a big dataset with a lot of geolocation data (long / lat), which I want to map dependent on the frequency. I just want to show the frequencies of the cities and areas, not of each exact location. Since the geo data might vary a little bit for each city, the data has to be aggregated / clustered.
Unfortunately, just rounding the number does not work. I have already tried to create a matrix to measure the distance of each point, but my vector memory is not sufficient. Is there a simpler way?
This is how the original data looks like:
$long $lat
12.40495 52.52001
13.40233 52.50141
13.37698 52.51607
13.38886 52.51704
13.42927 52.48457
9.993682 53.55108
9.992470 53.55334
10.000654 53.55034
11.58198 48.13513
11.51450 48.13910
... ...
The result should look like this:
$long $lat $count
13.40495 52.52001 5
9.993682 53.55108 3
11.58198 48.13513 2
... ... ...
EDIT 1:
To cluster the points to one single point, a range of 25-50 km is fine.
EDIT 2:
This is how the map looks like, if I don't aggregate the points. I want to prevent the overlapping of the circles.

Distance between latitude and longitude in two separate datasets

I would like to look at aid effectiveness, by looking at whether 1) the aid projects are placed were the child mortality is the highest and 2) If a respondents geographical proximity to a project reduces child mortality. I have two datasets. Dataset1 contains the latitude and longitude of aid-projects, and dataset 2 contains the latitude and longitude of the respondents (they are put inside clusters in order to not reveal their identity). I would like to set a radius of 25km from each respondent (data2) and see how many projects are within this radius, and the name of these projects. I have seen tips on how to calculate distances within the same dataset (R - Finding closest neighboring point and number of neighbors within a given radius, coordinates lat-long), but not a good tip on how to calculate the distance between two datasets. Does anyone have any insights as to how I might solve this problem? I have some experience with R, but I´m still pretty newbie! The datasets contains 1593 aid-projects and 267 respondent-clusters. Examples of tree longitude/latitude-coordinates are given below:
Dataset 1 - Aid projects - Latitude, longitude (0.75 , 34.08333 ; 2.85604 , 32.43001 ; 1.78481 , 33.59432)
Dataset 2 - Respondents data (clusters)- latitude, longitude (2.34240627, 32.64138 ; 2.18839338, 32.65868; 2.04988464, 32.87160)
Any help would be very much appreciated!!
Best regards,
Synnøve

get nearest coordinate from sqlite database

I have a point coordinate based on two double values x0,y0 both in this format: xx.x (point as decimal separator)
In a database I have a list of lines that are defined by the coordinates x1,y1 as startpoint and x2,y2 as endpoint. Among other columns, (such as line thickness and so on) in the database there are these columns:
id | x1 | y1 | x2 | y2
What I would need is a query that returns whatever line has either the starpoint(x1,y1) or the endpoint(x2,y2) nearest to my basepoint (x0,y0). So the line that starts or ends nearest to my current position.
Thanks
SQLite has no square root function, but for comparing distances, we can just as well use the square of the distance:
SELECT *
FROM MyTable
ORDER BY min((x1-x0)*(x1-x0) + (y1-y0)*(y1-y0),
(x2-x0)*(x2-x0) + (y2-y0)*(y2-y0))
LIMIT 1

Retrieving latitude & longitude values from database and mapping them using Google Map API in asp

I have two fields Hospital Name & City. When I click on the submit button a new page will be shown displaying the location of the specified hospital. How can I achieve this task?
A location table already exists which contains hospital name,longitude & latitude values. On the basis of inputted hospital name, I want to retrieve its respective latitude & longitude values and map them on the next page displaying a google map.
See Here : -> https://www.daniweb.com/web-development/javascript-dhtml-ajax/threads/346407/getting-latitude-and-longitude-info-into-text-boxes>
Find your Lat Long coordinates on Click and open it in new window.
Assuming your database is either MS SQL or MySQL
The following SQL query uses Spherical Law of Cosines to calculate the distance between a coordinate and coordinates in a table. It limits result to 10 and orders by distance.
d = acos( sin(lat1).sin(lat2) + cos(lat1).cos(lat2).cos(lng2-lng1) ).R
Were R = earth’s radius (mean radius = 3,959 miles or 6,371km)
SELECT hospital name,latitude,longitude, (3959 * acos(cos(radians(center_latitude))
* cos(radians(latitude)) * cos(radians(longitude)
- radians(center_longitude)) + sin(radians($center_latitude))
* sin( radians( latitude )))) AS distance FROM table
ORDER BY distance LIMIT 0 , 10
Where center_latitude & center_longitude are coordinates of location.

Resources