Hi Frendz,
In my vehicle tracking system, I have got the latitude and longitude points of the vehicle for every 30 secs while the vehicle moving. Now i need to get the report of the vehicles when it crosses from one state to another state and one district to another district. How to find it using latitude and longitude points? If anybody doing the projects like this then guide me.

Dani AI

Generated

Building on 's suggestion (mentioned as Ardav): the reliable way is to map each GPS sample to an administrative polygon (state/district) and treat a change of polygon ID as the crossing event. For 's 30‑second samples this is best done locally with a spatial index (faster, private, no API costs) or with occasional reverse‑geocode lookups only when needed.

Recommended workflow:

  • Obtain official admin boundaries for the target country (census/TIGER, GADM, or OSM extracts).
  • Load polygons into a spatial store (PostGIS, SpatiaLite) or into memory via GeoPandas/GeoJSON with an R-tree index.
  • For each GPS point do a point-in-polygon lookup and assign an area_id (state/district).
  • Detect transitions where area_id != previous_area_id and record timestamp, previous area, new area, speed/bearing.
  • Debounce border noise: require N consecutive samples (or a minimum dwell time/distance) inside the new polygon before emitting a crossing event; optionally treat a small buffer along borders as “ambiguous” to reduce flicker.

Example (Python + GeoPandas):

import geopandas as gpd
from shapely.geometry import Point

gps = gpd.read_file('gps_points.csv')   # columns: ts,lat,lon
gps['geometry'] = gps.apply(lambda r: Point(r.lon, r.lat), axis=1)
states = gpd.read_file('states.shp').to_crs(gps.crs)
joined = gpd.sjoin(gps, states[['STATE_NAME','geometry']], how='left', predicate='within')
joined['state_change'] = joined['STATE_NAME'] != joined['STATE_NAME'].shift()
crossings = joined[joined['state_change']]

Simple PostGIS pattern:

SELECT g.*, s.name AS state
FROM gps_points g
JOIN states s ON ST_Contains(s.geom, ST_SetSRID(ST_Point(g.lon,g.lat),4326));
-- then use window LAG(state) to find changes per vehicle

Operational tips: create spatial indexes (GIST), cache last-known area per vehicle, and avoid per-sample external geocoding. For borderline cases add a small buffer or require 2–3 consecutive confirms to avoid false positives from GPS jitter. Useful data/tools: PostGIS (https://postgis.net), GeoPandas (https://geopandas.org), OSM/Nominatim (https://nominatim.openstreetmap.org) or national boundary datasets.

Recommended Answers

All 3 Replies

Member Avatar for Member #120589

Can lang/lat give you state or district? If drive is in Newport - the DB or whatever you're using to store the data will hold Newport. If the driver moves into Cardiff, the value will change, so do something (eg alert). If no change e.g. 80 updates while in Newport - no alert. Is that what you wanted?

commented: useful post. +4

Can lang/lat give you state or district? If drive is in Newport - the DB or whatever you're using to store the data will hold Newport. If the driver moves into Cardiff, the value will change, so do something (eg alert). If no change e.g. 80 updates while in Newport - no alert. Is that what you wanted?

Yes Ardav, I got a hint from this post. Thanks a lot.

Thanks Ardav for your valuable post. I have done this process with your idea.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.