Fixing Railroad Crossings With Impossible Coordinates

On this page

Problem statement

Plot the FRA's crossings and a handful land in the Atlantic, in the Arctic or nowhere at all. The inventory's latitude and longitude are typed in by railroads and states, and they carry every kind of keying error: text in the number, latitude and longitude swapped, a decimal point in the wrong place. This page finds each kind among the 203,152 open crossings at grade on the 29 October 2026 copy and repairs what can be repaired: 7 swapped pairs and 15 shifted longitudes. It then tests every point against the state its record names, which finds 765 more in a neighbouring state.

Quick answer

Strip the stray characters, swap the pairs that are reversed, divide the longitudes shifted by a digit, and count what is left:

lat = pd.to_numeric(grade.latitude.str.strip("'Β°"), errors="coerce")
lon = pd.to_numeric(grade.longitude.str.strip("'Β°"), errors="coerce")
swap = lat.between(64, 180) & lon.between(-72, -13)
lat, lon = lat.where(~swap, -lon), lon.where(~swap, -lat)
shift = lon < -180
lon = lon.where(~shift, lon / 10)
print(f"swapped: {swap.sum()}; decimal shifted: {shift.sum()}; missing: {lat.isna().sum()}; still out of range: {(lat.notna() & ~(lat.between(13, 72) & lon.between(-180, -64))).sum()}")
swapped: 7; decimal shifted: 15; missing: 564; still out of range: 4

The repairs fix 7 swapped pairs and 15 longitudes shifted by a factor of ten. 564 crossings have no position to repair, and 4 positions are still out of range; set those to missing rather than guess.

Horizontal bars of bad crossing positions: no position 564, text in the number 4, latitude and longitude swapped 7, longitude shifted a decimal place 15, still out of range 4, inside a different state 765. Horizontal bars of bad crossing positions: no position 564, text in the number 4, latitude and longitude swapped 7, longitude shifted a decimal place 15, still out of range 4, inside a different state 765.
Bad positions by kind.

Four kinds of bad position

1. Text in a number column

for c in ["latitude", "longitude"]:
    v = pd.to_numeric(grade[c], errors="coerce")
    print(c, grade[c][v.isna() & grade[c].notna()].tolist())
latitude ["47.836319''''", "47.838013''''", '32.071635Β°']
longitude ['-81.059356Β°']

Four values are text: two latitudes ending in a run of apostrophes, 47.836319'''', and a latitude and a longitude with a degree sign. pd.to_numeric stops at the first of them unless told to coerce. Coercing would turn them into missing values, but they are good positions with junk attached, so strip the characters first with .str.strip("'Β°").

2. Outside any possible range

raw_lat = pd.to_numeric(grade.latitude.str.strip("'Β°"))
raw_lon = pd.to_numeric(grade.longitude.str.strip("'Β°"))
out = grade[(raw_lat > 72) | (raw_lon < -180) | (raw_lat < 13)]
print(f"outside the range of US crossings: {len(out)}")
print(out.assign(lat=raw_lat, lon=raw_lon)[["crossingid", "statename", "lat", "lon"]].head(8).to_string(index=False))
outside the range of US crossings: 24
crossingid    statename       lat         lon
   921989R    WISCONSIN 43.368610 -897.675000
   928720K     NEBRASKA 98.299461  -40.578494
   928721S     NEBRASKA 98.299625  -40.578480
   928722Y     NEBRASKA 98.299000  -40.578486
   928723F     NEBRASKA 98.298914  -40.578486
   928724M     NEBRASKA 98.298839  -40.578489
   930944H PENNSYLVANIA 75.401803  -41.243229
   931010B   CALIFORNIA 93.421722 -123.532779

24 crossings fall outside any range a US crossing can have. The Nebraska rows have latitude 98.3 and longitude -40.6: the two numbers swapped and their signs moved with them. Their true position is 40.6Β° N, 98.3Β° W. Wisconsin's -897.675 has its decimal point one place too late. The two rules change 22 of the 24, but 4 are still out of range afterwards: the two California rows with a latitude beyond the pole, and two Oregon crossings whose longitudes were mistyped rather than shifted. There is no rule to undo those; set them to missing.

Map of the lower 48 with the repaired crossings at their corrected positions: swapped pairs in Nebraska, Indiana and Pennsylvania, and shifted longitudes in Wisconsin, New Jersey, South Carolina and Texas. Map of the lower 48 with the repaired crossings at their corrected positions: swapped pairs in Nebraska, Indiana and Pennsylvania, and shifted longitudes in Wisconsin, New Jersey, South Carolina and Texas.
Where the repaired crossings belong.

3. Missing

print(f"no position: {raw_lat.isna().sum():,}; by state: {grade[raw_lat.isna()].statename.value_counts().head(4).to_dict()}")
print(grade.latlongsource.value_counts(dropna=False).to_dict())
no position: 564; by state: {'MISSOURI': 55, 'TEXAS': 52, 'ILLINOIS': 50, 'PENNSYLVANIA': 38}
{'Actual': 175752, 'Estimated': 18393, nan: 9007}

564 open crossings have no position, spread across the big rail states: Missouri 55, Texas 52, Illinois 50. 18,393 positions are marked Estimated and 9,007 carry no source. An estimated position may be at the centre of the road segment or the nearest town, which is why a point can sit a few hundred metres from its track.

Checking each point against its state

The data used on this page

The Federal Railroad Administration (FRA) publishes the Highway-Rail Crossing Inventory (Form 71, one current record for every crossing that is or was in use) and the highway-rail grade crossing incident reports (Form 57, every collision a railroad has reported since 1975) on the Department of Transportation's open data portal. The copies used here were downloaded on 29 October 2026 and saved on this site, because both tables are updated every day; they keep the columns these pages use and leave out the narratives and the contact telephone numbers. Public domain. State boundaries are the Census Bureau's 2024 cartographic boundary file, public domain.

from pathlib import Path
import zipfile

import geopandas as gpd
import pandas as pd
import requests

Path("data").mkdir(exist_ok=True)
# Federal Railroad Administration: the Highway-Rail Crossing Inventory (Form 71, the current record of every crossing,
# 47 of its 265 columns) and the highway-rail grade crossing incident reports (Form 57, 1975 on, 51 of 154 columns,
# without the narrative), with the Census Bureau's 2024 county estimates, counties and states.
# Saved 29 October 2026: both tables change every day.
# Live: https://data.transportation.gov/resource/m2f8-22s6.csv and https://data.transportation.gov/resource/7wn6-i5b9.csv
ARCHIVE = "fra-crossings-2026-10-29.zip"
if not Path(f"data/{ARCHIVE}").exists():
    Path(f"data/{ARCHIVE}").write_bytes(requests.get(f"https://data.spatialworkflow.io/{ARCHIVE}", timeout=600).content)
Z = zipfile.ZipFile(f"data/{ARCHIVE}")
Path("data/cb_2024_us_state_20m.zip").write_bytes(Z.read("cb_2024_us_state_20m.zip"))
xing = pd.read_csv(Z.open("fra-crossing-inventory-2026-10-29.csv"), dtype={"crossingid": str, "statecode": str, "countycode": str, "latitude": str, "longitude": str}, low_memory=False)
xing = xing.sort_values("revisiondate").drop_duplicates("crossingid", keep="last")   # ten ids appear twice
grade = xing[(xing.crossingclosed == "No") & (xing.crossingposition == "At Grade")].copy()
print(f"open crossings at grade: {len(grade):,}")
open crossings at grade: 203,152

Example 1: points in the wrong state

fixed = grade.assign(lat=lat, lon=lon).dropna(subset=["lat"])
pts = gpd.GeoDataFrame(fixed, geometry=gpd.points_from_xy(fixed.lon, fixed.lat), crs=4269)
states = gpd.read_file("data/cb_2024_us_state_20m.zip")[["STATEFP", "STUSPS", "geometry"]]
hit = gpd.sjoin(pts, states, how="left", predicate="within")
wrong = hit[hit.STATEFP.notna() & (hit.STATEFP != hit.statecode.str.zfill(2))]
print(f"in a state: {hit.STATEFP.notna().mean():.2%}; in a different state from the record: {len(wrong):,}")
print(wrong.groupby(["statename", "STUSPS"]).size().sort_values(ascending=False).head(6).to_string())
in a state: 99.92%; in a different state from the record: 765
statename      STUSPS
PENNSYLVANIA   NJ        77
OHIO           WV        72
WEST VIRGINIA  KY        50
VERMONT        NH        33
GEORGIA        AL        32
WEST VIRGINIA  OH        27

After the repairs, 99.92% of points fall inside a state, and 765 fall inside a different state from the one their record names. Most are crossings on or near a state line: Pennsylvania crossings plotted in New Jersey along the Delaware River, Ohio's in West Virginia along the Ohio River. The state boundaries here are the generalised cartographic file, and a river boundary drawn that coarsely can move a riverside crossing into the next state.

Map of crossings plotted in a different state from their record, most of them in green along state-line rivers such as the Ohio, the Mississippi and the Delaware, with a few dozen red points far from their own state. Map of crossings plotted in a different state from their record, most of them in green along state-line rivers such as the Ohio, the Mississippi and the Delaware, with a few dozen red points far from their own state.
Crossings in the wrong state.

Example 2: how far off

w = wrong.to_crs(5070)
b = states.set_index("STATEFP").to_crs(5070).geometry
d = w.apply(lambda r: r.geometry.distance(b[r.statecode.zfill(2)]), axis=1) / 1000
print(f"distance to the record's own state, km: median {d.median():.1f}; under 1 km: {(d < 1).mean():.1%}; over 100 km: {(d > 100).sum()}")
distance to the record's own state, km: median 0.7; under 1 km: 58.7%; over 100 km: 60

The median distance from a misplaced point to its own state is 0.7 km, and 58.7% are within 1 km: boundary noise, not errors. 60 are more than 100 km off, and those are wrong. Flag a point by its distance to its own state, not just by which state it falls in, and use a detailed boundary file before calling a riverside crossing misplaced (points in the ocean).