Please review any and all PUBLIC repositories, groups and associate files. These allow anyone on the Internet to access without authentication. Repository and group owners are responsible for their content and permission settings. Go to your project(s), click on Settings > General and expand the "Visibility, project features, permissions" to change this setting.

Commit 112611c6 authored by Wigal, Jacob (CIV)'s avatar Wigal, Jacob (CIV)

Initial commit

parent 83e7ca7e
import os
import geopandas as gpd
import re
def convert2geojson():
# Ask user for filepath of folder containing files to convert
def enterfilepath():
while True:
filepath=(input("Enter filepath of the folder containing your files: "))
if os.path.exists(filepath):
print("Not a valid filepath.")
print("Converting all files in" , os.getcwd(), 'to geojson.')
# Make a geojson folder if it doesn't exist
current_directory = os.getcwd()
geojson_directory = current_directory + '/geojson'
if not os.path.exists(geojson_directory):
print('Will place all converted files in new "geojson" folder.' + '\n')
print('Will place all converted files in existing "geojson" folder.' + '\n')
# Iterate over files and attempt to convert all to geojson
for file in os.listdir(current_directory):
# Skip folders and listed filetypes
if os.path.isdir(file):
if not file.lower().endswith(('txt','jpg','jpeg','geojson','ds_store','pdf',\
print('Converting ' + file + '...')
# Load data
file = str(current_directory) + '/' + str(file)
data = gpd.read_file(file)
# Alert user if CRS is changing with conversion
if['init'] != 'epsg:4326':
match ='epsg:.[^\']*', str( #use regex to split each dms string into integer components to input in the dms_to_decimal function
crs = str(
print('Original CRS was ' + crs + '...will be converted to epsg:4326')
# Create new filepath with geojson folder and extension
head, tail = os.path.split(file)
filename = head + '/geojson/'+ tail
filename_ext = os.path.splitext(filename)[0] + '.geojson'
data.to_file(filename_ext, driver = 'GeoJSON')
#Print success message
print('Success: ' + file + ' was converted to GeoJSON' + '\n')
# Alert user if file conversion failed
print('EXCEPTION: '+ file + ' is not a geopandas readable filetype')
print(file + ' could not be converted.' + '\n')
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment