I'm trying to get GeoPandas to give me the distance between suburbs (polygons) and the city centre (a point). However, no matter what coordinate reference system I use for the distance measurement (DIST_CRS), I keep getting the wrong results.
What am I doing wrong? I manually verified using espg.io that the coordinates were being converted correctly, so I don't understand why GeoPandas isn't outputting the correct distance.
This is just a visualization project; I'm not a GIS expert. I don't understand why GeoPandas doesn't offer a simpler way for calculating the great circle distance (given some intermediary CRS). It seems simpler to use the haversine function, but I'd like to use the proper method.
import geopandas def read_file(filepath): with open(filepath, encoding="utf-8") as fh: return fh.read() def add_dist_to_city(suburbs): suburbs = suburbs.to_crs(DIST_CRS) city_center = geopandas.GeoDataFrame(geometry=geopandas.points_from_xy([MELBOURNE[0]], [MELBOURNE[1]]), crs=GOOGLE_MAPS_CRS).to_crs(DIST_CRS) return suburbs["geometry"].apply(lambda suburb: suburb.distance(city_center).mean()) SUBURBS_COLUMN = "vic_loca_2" GEOMETRY_COLUMN = "geometry" GOOGLE_MAPS_CRS = "EPSG:3857" # Since we took cordinates from google maps DIST_CRS = "EPSG:32755" # We're use UTM zone 55 MELBOURNE = [144.96255859257582, -37.813600753509064] # Use x, y suburbs_raw = geopandas.read_file(read_file("data/suburb-2-vic.geojson")) # Check what CRS the json use print(suburbs_raw.crs) # Geographic 2D CRS: EPSG:4326 # Extract suburb name and geometry (note geopandas expect a "geometry" column) suburbs = suburbs_raw[[SUBURBS_COLUMN, GEOMETRY_COLUMN]].rename(columns={SUBURBS_COLUMN: "suburb", GEOMETRY_COLUMN: "geometry"}) # Capitalize suburb names suburbs["suburb"] = suburbs["suburb"].map(str.title) # Calculate distance to city suburbs["distanceFromCity"] = add_dist_to_city(suburbs) # Print results test = suburbs.sort_values(by=["distanceFromCity"]) # Outputs ~16,000 instead of ~234 km test[test["suburb"]=="Nurran"]["distanceFromCity"].values[0]/1000 In the last line, I'm getting a result of ~16,000 km instead of the actual distance, which is around 234 km. The distances appear to be scaled incorrectly.
I'm using EPSG:32755 to calculate the distances.
Link to datafile: https://github.com/tonywr71/GeoJson-Data/blob/master/suburb-2-vic.geojson