I'm trying to create a shapefile of points from a coordinate list. But, when I use fiona to create the shapefile Arc Catalog is showing that there is no CRS. I tried to add the CRS with Geopandas and got the same result. I have my code below with file paths removed but it works with the files I use.
# import
import os
from PIL import Image, ExifTags
import geopandas as gpd
import fiona
from fiona.crs import from_epsg
from shapely.geometry import Point
from shapely.geometry import mapping
import shapely
from collections import defaultdict
# define functions
def dms_to_dd(d, m, s):
dd = d + float(m)/60 + float(s)/3600
return dd
pathforresult = r"Result.shp"
NCDict = {}
WCDict = {}
# opening files and extracting exif
Path = r"final project pics"
filelist = os.listdir(Path)
for f in filelist:
if f.endswith(".jpg"):
with open(Path + "/" + f, 'r') as I:
print(I)
img = Image.open(Path + "/" + f)
exif = {ExifTags.TAGS[k]: v for k, v in img._getexif().items() if k in ExifTags.TAGS}
print(exif)
meta = exif['GPSInfo'][2]
meta = [x[0] for x in meta]
d = meta[0]
m = meta[1]
s = meta[2]
NCDict[os.path.basename(I.name)] = dms_to_dd(d=d,m=m,s=s)
# Ncoords = {I:dms_to_dd(d=d, m=m, s=s)}
# print(Ncoords)
meta2 = exif['GPSInfo'][4]
meta2 = [b[0] for b in meta2]
d = meta2[0]
m = meta2[1]
s = meta2[2]
WCDict[os.path.basename(I.name)] = dms_to_dd(d=d,m=m,s=s)
print("North Coordinate List " + str(NCDict))
print("West Coordinate List: " + str(WCDict))
# writing xy coords to new file
corddict = [NCDict, WCDict]
dd = defaultdict(list)
for d in (NCDict, WCDict): # you can list as many input dicts as you want here
for key, value in d.items():
dd[key].append(value)
print(dd)
schema = {'geometry': 'Point', 'properties': {'name': 'str:10'}}
# create and save the resulting shapefile
with fiona.open(pathforresult, 'w', crs=from_epsg(4326), driver='ESRI Shapefile', schema=schema) as output:
for key, value in dd.items():
point = Point(value[0],value[1])
prop = prop = {'name': key}
output.write({'geometry': mapping(point), 'properties': prop})
print(output)
result = gpd.read_file(pathforresult)
print(result.crs)
result.crs = {'init': 'epsg:4326'}
print(result.crs)
result.to_file(r"Result2.shp", driver="ESRI Shapefile", schema=schema)