|
POST
|
Randy, Thanks, that helped. As it stands, it only reads the first JPG, which has the date 04/27/2018. It isn't printing the dates of the numerous other files? im = r"path\to\DOT_SignInventory"
for root, dirnames, filenames in os.walk(im):
for fname in filenames:
if fname.endswith('.JPG'):
with open(os.path.join(root, fname), 'rb') as image: #file path and name
exif = exifread.process_file(image)
dt = str(exif['EXIF DateTimeOriginal'])#get JPG 'Date taken'
st = '2018:04:27 09:30:59'
date = time.strptime(st, '%Y:%m:%d %H:%M:%S')
print(time.strftime("%m/%d/%Y",date)) 04/27/2018
04/27/2018
04/27/2018
04/27/2018
04/27/2018
04/27/2018
etc... It seems the first part of the code involving exif (up to line 😎 works fine. If I put a print statement after line 8: print(dt) it gives me: 2018:04:27 09:30:59
2018:04:27 09:36:30
2018:04:27 09:40:00
2018:04:27 09:41:03
2018:04:27 09:42:03
2018:04:27 09:47:00
etc...
... View more
04-12-2019
09:07 AM
|
0
|
1
|
3536
|
|
POST
|
I'm attempting to extract the Date Taken from jpgs within a directory. And then I want to have the date printed as such: mo/day/year Here's an example of a JPG's Properties menu: This code runs with no error but the output isn't what I want. import exifread
from exifread import exif
import os
import time
im = r"path\to\DOT_SignInventory"
for root, dirnames, filenames in os.walk(im):
for fname in filenames:
if fname.endswith('.JPG'):
with open(os.path.join(root, fname), 'rb') as image: #file path and name
exif = exifread.process_file(image)
dt = str(exif['EXIF DateTimeOriginal']) #get Date Taken from JPG
date = time.strptime(dt, '%Y:%m:%d %H:%M:%S')
print("Photo:{} Date Taken:{}".format(fname, date)) Photo:0710100.JPG Date Taken:time.struct_time(tm_year=2018, tm_mon=6, tm_mday=5, tm_hour=13, tm_min=49, tm_sec=40, tm_wday=4, tm_yday=166, tm_isdst=-1) Ideally, I want the output to look as such: Photo:0710100.JPG Date Taken:06/05/2018 For line 14, I can't find the right format. I've also tried the datetime module but couldn't get that to work right either.
... View more
04-11-2019
02:08 PM
|
0
|
3
|
3689
|
|
IDEA
|
I have a directory full of JPGs which need to go in a raster field of a feature class table. You can do this manually by adding raster datasets as attributes in a feature class. But I guess there is no automated way to do it, and automation speaks for itself. Using a cursor to do this is not supported.
... View more
03-27-2019
01:41 PM
|
1
|
3
|
1280
|
|
POST
|
For what it's worth, it looks like I can convert the rasters to a FGDB. arcpy.env.workspace = r'\pathTo\jpgs'
#Convert Multiple Raster Dataset to FGDB
arcpy.RasterToGeodatabase_conversion("0100030.jpg;0100040.jpg", r"\pathTo\Data.gdb") Of course, this is just a sample. I'll have to set the script up to iterate through the directory and convert thousands of jpgs to the FGDB. But, after I do that I'm still stuck wondering how to get the raster into the Raster Field via Python.
... View more
03-26-2019
12:09 PM
|
0
|
0
|
3296
|
|
POST
|
Any intent I did with code to load the raster resulted in an error. Since I could not find any documentation on doing this in Python I assume it is not supported. Xander, Is this supported in arcpy for ArcGIS Pro? I'm currently looking for a way to update raster fields in FC table with Python. I have a script that uses the updatecursor to populate a text field with a path to the directory where the rasters are stored. But, what I really need is to update the raster field with the image itself. And apparently you can't use cursors for this. I started a thread the other day: https://community.esri.com/thread/231019-raster-fields-not-supported-using-cursors
... View more
03-26-2019
08:46 AM
|
0
|
0
|
3132
|
|
POST
|
Dan, Adding raster datasets as attributes is exactly what I need. But is there a way to automate this? I'm dealing with 1000s of rasters. I started out on this page and because there was no mention of Arcpy I moved on to looking into cursors.
... View more
03-26-2019
06:41 AM
|
0
|
0
|
3296
|
|
POST
|
So creating a separate table (using an insertcursor) for joining isn't a possibility? How to use an insertcursor on a Raster Field is pretty much my question. There's a Raster Field in a FC that I want populated with rasters. But, as I was reading how to access that type of field with a cursor it says it's not possible:
... View more
03-25-2019
01:44 PM
|
1
|
2
|
3296
|
|
POST
|
How do I update a Raster Field using a cursor? I'm attempting to write a script that uses a cursor to update this field with rasters from a directory. It's a stand-alone script using arcpy for ArcGIS Pro 2.3.1. arcpy.da.InsertCursor, arcpy.da.SearchCursor and arcpy.da.UpdateCursor state that as a field_name, "Raster fields are not supported."
... View more
03-25-2019
01:17 PM
|
0
|
7
|
3658
|
|
POST
|
I couldn't get the os.walk portion of the code you provided to get to the jpgs. If I ran that portion of the script to test it (left out the cursor portion) it would iterate a folder in that same directory that had a jpg, but then stop there. It didn't find any other jpgs. So I changed those lines to this: ws = r'C:\path\to\jpegs\root'
jpgs = {} # empty dictionary
for dirName, subdirList, fileList in os.walk(ws):
for fname in fileList:
jpgs[fname[:-4]] = os.path.join(dirName,fname) Anyway, thanks to all of your help this does what I want: import arcpy, os
ws = r'C:\path\to\jpegs\root'
jpgs = {} # empty dictionary
for dirName, subdirList, fileList in os.walk(ws):
for fname in fileList:
jpgs[fname[:-4]] = os.path.join(dirName,fname)
fc = r'pathto\Projects\DOT_SignInventory\Data.gdb\WCDOT_Signs'
fields = ['OID@', 'Post_Number', 'Photo']
with arcpy.da.UpdateCursor(fc, fields) as cursor:
for row in cursor:
try:
row[2] = jpgs[row[1]]
cursor.updateRow(row)
except KeyError:
print("No photo for: {}".format(row[1]))
del cursor
... View more
03-21-2019
01:52 PM
|
1
|
0
|
617
|
|
POST
|
Randy, Thanks for that. To answer your assumptions, yes, the 'Post_Number' field is text and the 'Photo' field length is 150--so, plenty long. If I try your code word for word it runs with no error, but in the 'Photo' field it doesn't give the path. Here's an example of what it puts there: Thumbs.db\0110030.jpg Not sure why it does this? There's no 'Thumbs' file in the directory.
... View more
03-21-2019
10:10 AM
|
0
|
2
|
2999
|
|
POST
|
Curtis, Thanks, that almost got me there. But, for the jpg_dir variable, however this string looks is how it's updated in the table. For example, if it's like this in the variable: jpg_dir = r'P:\GIS_Highway_Dept\Applications\Sign Inventory\Photos\CH01' then it's updated like this in the table: P:\GIS_Highway_Dept\Applications\Sign Inventory\Photos\CH01\2410765.jpg The problem is 2410765.jpg is County Highway 24, as the first two digits in the ID is the highway number. So, that jpg isn't linked correctly, and neither will any be unless they begin with 01 (in the CH01 folder). Do I have to iterate the Photos directory first and create a list or library, as Randy pointed out?
... View more
03-20-2019
07:53 AM
|
0
|
1
|
2999
|
|
POST
|
Randy, That's correct. The first two digits of the 7 digit unique ID are based on the highway number and it's respective directory. For example: P:\GIS_Highway_Dept\Applications\Sign Inventory\Photos\CH01\0110930.jpg P:\GIS_Highway_Dept\Applications\Sign Inventory\Photos\CH19\1910930.jpg P:\GIS_Highway_Dept\Applications\Sign Inventory\Photos\CH84\8410930.jpg Etc... A dictionary is something I have to get to know how to utilize better. So, thanks, that gives me something to chew on.
... View more
03-19-2019
12:24 PM
|
0
|
4
|
2999
|
|
POST
|
Mitch, Thanks for the reply. There are multiple folders, actually. The folders have JPGs of signs of a certain highway. And there are as many folders containing these JPGs as there are county highways (CH01, for example). EDIT: I tried the code you provided on a copy, but it didn't seem to get updated. I put a print statement in after updateRow() and the directory is actually being called because it printed out all the JPGs. cursor.updateRow(row)
print(path_to_jpg)
... View more
03-19-2019
09:11 AM
|
0
|
3
|
2999
|
|
POST
|
I've been tasked with updating attribute table fields with file paths to image files in a folder based on a unique ID. I'm having trouble thinking up a script that will do this? I'm working on a standalone script in ArcGIS Pro 2.3.1 Arcpy. This is an example of how the table should look. Every JPG has a unique ID that matches the Post_Number field unique ID. Currently, the paths to the JPGs are entered manually into the table, and there are 1000s of them. All I've done so far is create a cursor that searches the Post_Number and Photo fields. import arcpy, os
fc = r'pathto\Projects\DOT_SignInventory\Data.gdb\WCDOT_Signs'
fields = ['Post_Number', 'Photo']
with arcpy.da.SearchCursor(fc, fields) as cursor:
for row in cursor:
print(u"{0}, {1}".format(row[0], row[1]))
... View more
03-19-2019
08:10 AM
|
0
|
11
|
3868
|
|
POST
|
Aaron, What comes to mind is something with the graphics. When you share/export the layout is your resolution set too low? I keep mine at 300 dpi.
... View more
03-11-2019
12:38 PM
|
0
|
0
|
3067
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 2 weeks ago | |
| 1 | a month ago | |
| 1 | 07-24-2025 01:27 PM | |
| 1 | 11-13-2025 08:22 AM | |
| 1 | 11-12-2025 08:37 AM |
| Online Status |
Offline
|
| Date Last Visited |
yesterday
|