Last active
December 17, 2015 22:33
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"type": "FeatureCollection", "features": [{"geometry": {"type": "Point", "coordinates": [-67.5667647785632, 44.92662008087262]}, "type": "Feature", "id": "0", "properties": {}}, {"geometry": {"type": "Point", "coordinates": [-67.57431718872728, 44.92251968199407]}, "type": "Feature", "id": "1", "properties": {}}, {"geometry": {"type": "Point", "coordinates": [-67.49904975129168, 44.931871400375485]}, "type": "Feature", "id": "2", "properties": {}}, {"geometry": {"type": "Point", "coordinates": [-67.50305560217842, 44.93475062348244]}, "type": "Feature", "id": "3", "properties": {}}, {"geometry": {"type": "Point", "coordinates": [-67.57861402660917, 44.918351294222894]}, "type": "Feature", "id": "4", "properties": {}}, {"geometry": {"type": "Point", "coordinates": [-67.63033546770116, 44.98537313256866]}, "type": "Feature", "id": "5", "properties": {}}, {"geometry": {"type": "Point", "coordinates": [-67.5162499184765, 44.96618677405628]}, "type": "Feature", "id": "6", "properties": {}}, {"geometry": {"type": "Point", "coordinates": [-67.51007318842774, 44.97015722810917]}, "type": "Feature", "id": "7", "properties": {}}, {"geometry": {"type": "Point", "coordinates": [-68.069497177844, 44.84055111538136]}, "type": "Feature", "id": "8", "properties": {}}, {"geometry": {"type": "Point", "coordinates": [-68.10897598316643, 44.94785579668702]}, "type": "Feature", "id": "9", "properties": {}}]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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