The highest ID value will be different for each type of object (nodes, ways and relations) and will change from day to day as people add more objects, so knowing what it is now is of little use.
The IDs are all 64 bit signed integers at the moment, so have a theoretical limit of 2^63-1 or 9,223,372,036,854,775,807 but I think it will take a while before we get to that number.
First of all, ST_Distance_Sphere returns in meters, so you are actually looking at 8km, which might be more reasonable. I suspect, also, that you have you lat/lon the wrong way round -- your point is somewhere off the coast of the Seychelles, not Carlisle, and there are not too many roads in the Indian Ocean.
Also, while the query planner will optimize this away, there is no need to repeatedly enter the same point. Instead, create it in a sub-query and reference it, eg:
SELECT
osm_id,
highway,
name,
ref,
ST_X(ST_ClosestPoint(ST_Transform(r.way, 4326), point.geom),
ST_Y(ST_ClosestPoint(ST_Transform(r.way, 4326), point.geom),
ST_Distance_Sphere(ST_ClosestPoint(ST_Transform(r.way, 4326), point.geom), point.geom)
FROM
planet_osm_roads r,
(Select ST_SetSRID(ST_MakePoint(-3.198706, 55.938627), 4326) as geom) point
ORDER BY 7 ASC
LIMIT 10;
However, this is still very inefficient. To make better use of a indexes, look at using ST_DWithin (r.way, point, distance) ORDER BY ST_Distance(r.way, point)
. If you look at the docs for ST_DWithin you will get an idea how it is used.
Best Answer
You can use OSM's regular API for fetching the OSM way via its ID. Example: https://www.openstreetmap.org/api/0.6/way/136322077/full
The
/full
is important for fetching all of its nodes, too. The nodes define the geometry of the way. The order of the nodes is defined by the<nd ref>
elements of the way. See OSM XML for more information.Also read about when not to use this API and the API usage policy. Since this is the editing API it is not meant for bulk queries.