conveyal / gtfs-validator

A Java framework for GTFS validation and statistics.
MIT License
38 stars 18 forks source link

Find stops that appear to be misplaced #14

Open mattwigway opened 10 years ago

mattwigway commented 10 years ago

We want to find stops that are a long way away from the nearest stop. A good way to do this would be to compute the G function of all the stops and then see if this stop lies far from the distribution.

This seems like it would be slow, but this takes an imperceptible amount of time using one core of my machine, computing the G function for 14,000 randomly distributed stops (which is about how many there are in Chicago, the largest GTFS feed I know of).

library(spatstat)

# generate some random points
x <- runif(14000)
y <- runif(14000)

the.pp <- ppp(x, y)

est <- Gest(the.pp)

plot(est)
mattwigway commented 10 years ago

Also, we don't have to do coordinate transforms; we can just multiply all of the longitudes by (radius of earth at equator)/(length of chord at agency latitude), and units will be invariant enough.

mattwigway commented 8 years ago

K-function might be better to find groups of misplaced stops.

laidig commented 8 years ago

How do you define misplaced?

mattwigway commented 8 years ago

I was thinking more of stops that are not near the rest of the stops in the entire feed, e.g. reversed lat/lon or at null island (0 lat 0 lon, due to math errors).

laidig commented 8 years ago

Using the number of stops in of a cluster or iterative k-means are good formulations.

If machine learning approaches seem a bit confusing, I have a suggestion: If you know the overall precision you want to target, use geohashes as a heuristic. If you spot something that does not have the same prefix, calculate the adjacent hashes and compare with those.

https://en.wikipedia.org/wiki/Geohash

This library has a method for calculating adjacent hashes. https://github.com/davidmoten/geo

If you're interested in a test set, I have a copy of the Amtrak feed from 2013. I'm not able to think of a GTFS for a bigger region.