-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshape2geojson.py
More file actions
36 lines (25 loc) · 899 Bytes
/
shape2geojson.py
File metadata and controls
36 lines (25 loc) · 899 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import geopandas as gpd
import pandas as pd
def shape2geojson(infile: str):
try:
infile.split(".")[-1] != 'shp'
except:
return ("Incorrect input file!\n%s is not a shapefile." % infile)
else:
try:
open(infile, 'r')
except FileNotFoundError:
return ("File %s not found!" % infile)
else:
shpfile = gpd.read_file(infile).to_crs("EPSG:4326")
outfile = infile.replace('.shp', '.geojson')
shpfile.to_file(outfile, driver='GeoJSON')
return True
def multishape2geojson(shapefiles: list, outfile: str):
#folder = Path(path)
#shapefiles = folder.glob("*.shp")
gdf = pd.concat([
gpd.read_file(shp).to_crs("EPSG:4326")
for shp in shapefiles
]).pipe(gpd.GeoDataFrame)# .to_crs("EPSG:3395")
gdf['geometry'].to_file(outfile, driver='GeoJSON')