I'm new to GIS. I'm trying to determine whether a list of GPS points are within a highway/road (in terms of meters). I have downloaded a OSM file and populated my database using osm2pgsql.
I have the following tables:
List of relations
Schema | Name | Type | Owner
--------+----------------------------+----------+----------
public | geography_columns | view | map_user
public | geometry_columns | view | map_user
public | planet_osm_line | table | map_user
public | planet_osm_point | table | map_user
public | planet_osm_polygon | table | map_user
public | planet_osm_roads | table | map_user
public | raster_columns | view | map_user
public | raster_overviews | view | map_user
public | spatial_ref_sys | table | map_user
public | gps_coordinates | table | map_user
public | gps_coordinates_id_seq | sequence | map_user
My coordinates table looks like so:
id | longitude | latitude | geom
I populated my table with a few longitude/latitude points, then ran the following function to generate a geometry value:
UPDATE vehicle_coordinates SET geom = ST_SetSRID(ST_MakePoint(longitude, latitude), 4326);
I initially tried using the PostGIS function ST_DWITHIN like so:
SELECT gps_coordinates.id, highway.name
FROM gps_coordinates, planet_osm_line highway
WHERE highway.highway IS NOT NULL
AND ST_DWITHIN(gps_coordinates.geom, highway.way, 5);
But no results were returned. I don't think I can just use meters in this function as I'm using latitude/longitude as my base unit. I'm stuck and not sure where to go from here. Can I use St_Distance in my WHERE clause? It states that it returns the distance in meters. But I'm not getting any rows returned:
SELECT gps_coordinates.id, highway.name
FROM gps_coordinates, planet_osm_line highway
WHERE highway.highway IS NOT NULL
ST_DistanceSphere(vehicle_coordinates.geom, highway.way) <= 5;
It could be that my data is bad (I got it from GEOFABRIK, so should be good) or that I'm confusing my units here.