Skip to content

Instantly share code, notes, and snippets.

@jwass
Last active December 17, 2015 22:33
Show Gist options
  • Save jwass/e958227fa34145dd29a5 to your computer and use it in GitHub Desktop.
Save jwass/e958227fa34145dd29a5 to your computer and use it in GitHub Desktop.
Example script using Pandas/GeoPandas to help @jqtrde. See https://gist.github.com/jacquestardie/ba32c3304bbe7d8e85b5
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import pandas as pd
import geopandas as gpd
import fiona.crs
from shapely.geometry import Point
# Open the file as a table. Name the two columns as x and y
df = pd.read_csv('raw.txt', header=None, names=['x', 'y'], sep=' ')
# Convert to shapely Points and to a GeoDataFrame with epsg 26919
geoms = df.apply(lambda row: Point(row['x'], row['y']), axis=1)
gdf = gpd.GeoDataFrame({'geometry': geoms}, crs=fiona.crs.from_epsg(26919))
# Convert to lon/lat
gdf.to_crs(epsg=4326, inplace=True)
# Store GeoJSON
with open('converted.geojson', 'w') as f:
f.write(gdf.to_json())
613105 4975798
612517 4975332
618438 4976478
618116 4976792
612186 4974863
607978 4982238
617011 4980265
617490 4980715
573541 4965659
570290 4977544
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment