Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am newbie in PostGIS and also GIS particularly.

I need to check that a vehicle is outside of a route. This route has been defined in advance, and of course it stores in a table: RROUTEDETAIL. This table contains: ROUTE_ID, LONGITUDE and LATITUDE.

So, when vehicle leaves the route they should be on, the system will give a warning message and then record it into other table.

I imagine to check the point I get with every point store in the RROUTEDETAIL, one by one with ST_DWITHIN. If all check get FALSE value, then the system give a warning message.

Is this the best approach or is there a better idea ?

Thank you very much.

Best regards, Dion.

thank you.

For example, this is the point where vehicle leaves: -7.539079, 109.322891 with value tolerance: 0.5. Then I write:

    select st_dwithin((select st_makeline(ST_Point(-7.539079, 109.322891))),
        (select st_makeline(ST_Point(foo."TRACKERDATA_LATITUDE",foo."TRACKERDATA_LONGITUDE"))
            from (select ht."TRACKERDATA_LATITUDE", 
                        from "HTRACKERDATA" ht
                        left join "RVEHICLE" rv on ht."VEHICLE_ID" = rv."VEHICLE_ID"
                        where ht."VEHICLE_ID" = 106 and 
                        ht."TRACKERDATA_GPSTIME" BETWEEN '2012-01-01 08:00'
                        AND '2012-01-01 17:00'
                        order by ht."TRACKERDATA_GPSTIME", ht."TRACKERDATA_REPORTTIME") as foo), 

It always return FALSE. Then I check again with ST_DISTANCE, it gives 99999999999.9 (double precision).

How to fix that ?

Thank you.

share|improve this question

I'd suggest connecting all the route points in RROUTEDETAIL to one line geometry. This way only one ST_DWITHIN comparison will be necessary instead of a series of comparisons between points.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.