TransWikia.com

GeoPandas/Geoplot losing first row when reprojecting

Geographic Information Systems Asked by Crimsoneer on February 23, 2021

I’m trying to work with the London Borough borders file (https://data.london.gov.uk/dataset/statistical-gis-boundary-files-london) in geopandas/geoplot.

It comes in National Grid Easting/Northing coordinates (epsg="7405" I think) and I’m trying to convert to Lat Longs to be able to map, but the first row of any dataframe I convert keeps being changed to an "INF INF" polygon!

No idea why it’s happening. I’ve tried doing different rows, only one row, changing the CRS….same issue.

all_border = geopandas.read_file("boroughsLondon_Borough_Excluding_MHW.tab")


lsoa_border.to_crs(epsg=4327)

enter image description here

One Answer

I think I've figured out what is going on...for some reason, the first time I run the re-project, it doesn't finish the first row. A workaround is doing it via Shapely, and re-inserting it into the new DF. Even then, weirdly it doesn't seem to work the first time...some sort of memory bug?

Anyway, running the below twice seems to work.

import pyproj
from shapely.ops import transform

def fix_df(old_df, new_df):
    OSGB = pyproj.CRS.from_epsg(27700 )
    lat_long = pyproj.CRS.from_epsg(4326)
    project = pyproj.Transformer.from_proj(OSGB, lat_long)
    g1 = old_df.iloc[0].geometry
    g2 = transform(project.transform, g1 )  # apply projection
    new_df.loc[0, "geometry"] = g2
    return new_df

EDIT: This looks likely connected to this pyproj bug: https://stackoverflow.com/questions/55390492/runtimeerror-bno-arguments-in-initialization-list

Answered by Crimsoneer on February 23, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP