Skip to content

Instantly share code, notes, and snippets.

@JeroenSteen
Last active May 29, 2020 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JeroenSteen/c09b526d7f8d4c2953eb857da656a611 to your computer and use it in GitHub Desktop.
Save JeroenSteen/c09b526d7f8d4c2953eb857da656a611 to your computer and use it in GitHub Desktop.
Omnistreets select data
<?php
/*
Find houses from postcode, split by odd and even, simply order by geolocation
With help from Lukasz Szozda, https://stackoverflow.com/questions/59490951/query-to-split-even-and-odd-numbers-with-group-concat
*/
$find_houses_from_postcodes_split_sql = "
SELECT street
,GROUP_CONCAT(DISTINCT CASE WHEN MOD(CAST(housenumber AS int),2) = 0 THEN CAST(housenumber AS int) END ORDER BY housenumber ASC) AS housenumbers_even
,GROUP_CONCAT(DISTINCT CASE WHEN MOD(CAST(housenumber AS int),2) = 1 THEN CAST(housenumber AS int) END ORDER BY housenumber ASC) AS housenumbers_odd
FROM streets
WHERE postcode LIKE '3031%'
GROUP BY street
ORDER BY lat,lon;
";
/*
Find stops from routes table, route-file import sample:
postcode,housenumber
3031PP,18C
3031AH,28
*/
$find_stops_from_route_sql = "
SELECT *
FROM streets
WHERE postcode IN (SELECT postcode FROM route)
AND housenumber IN (SELECT housenumber FROM route)
GROUP BY street
ORDER BY lat,lon;
";
$find_stops_in_radius_sql = "
SELECT *,
111.045 * DEGREES(ACOS(LEAST(1.0, COS(RADIANS(latpoint))
* COS(RADIANS(lat))
* COS(RADIANS(longpoint) - RADIANS(lon))
+ SIN(RADIANS(latpoint))
* SIN(RADIANS(lat))))) AS distance_in_km
FROM streets
JOIN (
SELECT 51.92745 AS latpoint, 4.48922 AS longpoint
) AS p ON 1=1
-- HAVING MAX(distance_in_km) < 10
ORDER BY distance_in_km ASC
LIMIT 15";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment