POST
|
Hi, I would like use it, but I can`t just copy e value. I tried replace 5 spaces for a broke line; but its doesn`t worked yet. I appreciate a help here. I'm using ArcGIS Desktop 10.4 Best Regards import os, arcpy, glob
def combinePDFs(out_pdf, pdf_path_or_list):
'''
uses arcpy mapping module to combine pdf documents
out_pdf -- output pdf document (.pdf)
pdf_path_or_list -- list of pdf documents or folder
path containing pdf documents.
'''
# Create new PDF document
out_path, pdf_name = os.path.split(out_pdf)
pdfDoc = arcpy.mapping.PDFDocumentCreate(out_pdf)
# set workspace to get pdfs
if isinstance(pdf_path_or_list, list):
for pdf in pdf_path_or_list:
pdfDoc.appendPages(pdf)
print 'Added "%s" to "%s"' %(pdf, os.path.basename(out_pdf))
elif isinstance(pdf_path_or_list, str):
if os.path.exists(pdf_path_or_list):
# if path, use glob to find all pdf's in folder
for pdf in sorted(glob.glob(os.path.join(pdf_path_or_list, '*.pdf'))):
pdfDoc.appendPages(os.path.join(pdf_path_or_list, pdf))
print 'Added "%s" to "%s"' %(pdf, os.path.basename(out_pdf))
# Save and close pdf document
pdfDoc.saveAndClose()
del pdfDoc
print 'Created: %s' %out_pdf
return out_pdf if __name__ == '__main__':
# test function with path
out_pdf = r'C:\Users\calebma\Desktop\test.pdf'
path = r'C:\Users\calebma\Desktop\pdfTest'
combinePDFs(out_pdf, path)
# test functino with list
pdf2 = r'C:\Users\calebma\Desktop\test2.pdf'
pdfs = [r'C:\Users\calebma\Desktop\pdfTest\Mailing_Labels5160.pdf',
r'C:\Users\calebma\Desktop\pdfTest\Mailing_Taxpayer.pdf',
r'C:\Users\calebma\Desktop\pdfTest\stfr.pdf']
combinePDFs(pdf2, pdfs)
... View more
03-05-2022
09:38 AM
|
0
|
0
|
1826
|
POST
|
Every week the file's name chenges. The last part of name came's from a data. Both Features Classes at the script are diferente (name and content). You are right that was confusing about Features Classes, so I explained it better at line 11 I tried your suggest too import arcpy ... ... # Local variables: ... arcpy.env.workspace = r'C:\Teste_Auto_CLEIA\Auto_Classi\Dinamica_GDB.gdb' ... ... #List FC # line 6 ... FC = arcpy.ListFeatureClasses("S_pol_Din*") ... Feature = FC[0] ... print"Feature: "+str(Feature) ... ... #List AnotherFC # line 11 ... FCName = arcpy.ListFeatureClasses("pol*") ... FC_Name = FCName[1] ... print"FC_Name: "+str(FC_Name) ... FCNameCut = FC_Name[19:36] # Isn't original lane ... print"FCNameCut "+FCNameCut ... ... #Calculate field (D2clust200m) #Line 18 ... with arcpy.da.UpdateCursor(Feature, ('D2clust200m')) as curs: ... for row in curs: ... row[0] = row[0].replace(FCNameCut, "test") ... curs.updateRow(row) ... print"Bakker try" ... Feature: S_pol_Din_DepL82270692015146eAnt015130 FC_Name: pol_Din_DepL82270692015178eAnt015146 FCNameCut 2015178eAnt015146 Runtime error Traceback (most recent call last): File "<string>", line 21, in <module> AttributeError: 'NoneType' object has no attribute 'replace'
... View more
02-19-2018
03:07 PM
|
0
|
8
|
1032
|
POST
|
I tried, but it doesn't works. I tried similar version, none works. import arcpy ... ... # Local variables: ... arcpy.env.workspace = r'C:\Teste_Auto_CLEIA\Auto_Classi\Dinamica_GDB.gdb' ... ... #List FC # line 6 ... FC = arcpy.ListFeatureClasses("S_pol_Din*") ... Feature = FC[0] ... print"Feature: "+str(Feature) ... ... #List AnotherFC # line 11 ... FCName = arcpy.ListFeatureClasses("pol*") ... FC_Name = FCName[1] ... print"FC_Name: "+str(FC_Name) ... FCNameCut = FC_Name[19:36] # Isn't original lane ... print"FCNameCut "+FCNameCut ... ... #Calculate field (D2clust200m) #Line 18 ... print("FCNameCut is: {}".format(FCNameCut)) ... if FCNameCut is not None: ... expr = FC_Name.replace(str(FCNameCut), "test") #I tried with FCNameCut and not with FC_Name too ... arcpy.CalculateField_management (Feature, "D2clust200m", expr,"PYTHON_9.3") ... print"Done" ... Feature: S_pol_Din_DepL82270692015146eAnt015130 FC_Name: pol_Din_DepL82270692015178eAnt015146 FCNameCut 2015178eAnt015146 FCNameCut is: 2015178eAnt015146 Runtime error Traceback (most recent call last): File "<string>", line 22, in <module> File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\management.py", line 3129, in CalculateField raise e ExecuteError: ERROR 000539: Error running expression: pol_Din_DepL8227069test Traceback (most recent call last): File "<expression>", line 1, in <module> NameError: name 'pol_Din_DepL8227069test' is not defined Failed to execute (CalculateField).
... View more
02-19-2018
02:54 PM
|
0
|
1
|
771
|
POST
|
It works fine! And the first (and original) script didn't worked to "n" scene(s) just because one line import arcpy, os
#Define the workspace that contains all of the folders with the Landsat imagery
arcpy.env.workspace = r'C:\Teste_Auto_CLEIA\Ima_compactadas'
#Specify where you would like the output to go
outws = r'C:\Teste_Auto_CLEIA\Imagem'
#List all of the workspaces in the previously defined workspace
folders = arcpy.ListWorkspaces("L8*", "Folder") #Filter to retrieve just the folder(s) with Landsat's bands
#Iterate through this list of workspaces and create a new list within each iteration of unstacked raster bands e.g. ['LC80260272014159LGN00_B1', 'LC80260272014159LGN00_B2',...]
#Landsat files follows this form: LC80260272014159LGN00_B1.tif, so we need to strip off anything after the "_" and use the first basename as the output name. You can do this with various slicing methods and string manipulation in Python.
for folder in folders:
arcpy.env.workspace = folder
rasters = arcpy.ListRasters("L*2*0*_B*.tif")# Filter and does that just the Landsat scenes with path/row from my ROI will be used
name = os.path.join(outws, rasters[1].split("_")[0] + ".tif")
arcpy.CompositeBands_management(rasters, name)
print(rasters)#Line which allows composite bands for "n" scene(s)
# Ao completar, por a frase:
print "Processing complete" Thank you.
... View more
12-26-2017
12:35 PM
|
0
|
1
|
1964
|
POST
|
Can you give more instructions? I inserted some "prints lines" to show the steps executed correctly and I saw the script finds the first folder and him bands. Besides, I don't understand how the original script is fine and this one isn't. import arcpy, os
...
... arcpy.env.workspace = r'C:\Teste_Auto_CLEIA\Ima_compactadas'
...
... # list all folders in a directory
... folders = arcpy.ListWorkspaces("L8*", "Folder") # Inside main directory, already have other folders, but the bands are always inside folders that begin with "L8", e.g. "L8227069".
... print "folders: "+str(folders) #To see if the search above finds a result
...
... #The output files place
... outws = r'C:\Teste_Auto_CLEIA\Imagem' # Line 10
...
... for folder in folders:
... arcpy.env.workspace = folder
... images = arcpy.ListRasters("L*2*0*_B*.tif") #I changed the user word for an exclusive. This line keeps the bands that I will use
... print "images: "+str(images)
... chk4 = ['band{0}.tif'.format(i) for i in range(0, 7)] # I changed the range
... print "chk4: "+str(chk4)
... rasters = [a for a in images if a[-9:] in chk4]
... print "rasters: "+str(rasters)
... name = os.path.join(outws, rasters[1].split("_")[0] + ".tif") # I wrote "outws"
... arcpy.CompositeBands_management(rasters, name) # I put it
... print(rasters)
... print "Finished" #23
... folders: [u'C:\\Teste_Auto_CLEIA\\Ima_compactadas\\L8227068', u'C:\\Teste_Auto_CLEIA\\Ima_compactadas\\L8227069'] images: [u'LO82270682017183CUB00_B1.TIF', u'LO82270682017183CUB00_B2.TIF', u'LO82270682017183CUB00_B3.TIF', u'LO82270682017183CUB00_B4.TIF', u'LO82270682017183CUB00_B5.TIF', u'LO82270682017183CUB00_B6.TIF', u'LO82270682017183CUB00_B7.TIF'] chk4: ['band0.tif', 'band1.tif', 'band2.tif', 'band3.tif', 'band4.tif', 'band5.tif', 'band6.tif'] rasters: [] Runtime error Traceback (most recent call last): File "<string>", line 20, in <module> IndexError: list index out of range Kind regards.
... View more
12-25-2017
07:11 PM
|
0
|
1
|
1964
|
POST
|
I tried it. I saw that my line #18 was inside "for folder in folders", while the original wasn't, but none change happens when I fix it. ... print(rasters) #18 The message error still the same. Runtime error Traceback (most recent call last): File "<string>", line 16, in <module> IndexError: list index out of range Thanks!
... View more
12-25-2017
01:29 PM
|
0
|
3
|
1964
|
POST
|
Xander Bakker, I appreciate your help. Right now, I've 2 scenes (some times are more), the folder from a scene (227/068) is showed below. *I didn't receive the e-mail about your comments, I will set my account to fix it. Thankful
... View more
12-25-2017
12:02 PM
|
0
|
3
|
1964
|
POST
|
Mitch, I'm grateful for your help. I tried do it, but the same line (now is 14) is with trouble. >>> import shutil ... import os ... ... source = r'C:\Test\Landsat'# I shorted it to easier - The folder with all files. ... dest1 = r'C:\Test\L8227068'# I shorted it to easier ... dest2 = r'C:\Test\L8227069'# I shorted it to easier ... file1 = 'LO82270682016229*'# I changed it to work with all bands ... file2 = 'LO82270692016229*'# I changed it to work with all bands ... ... files = os.listdir(source) ... ... for f in files: ... if (f.startswith("LO8227068") or f.startswith("LC8227068")): ... shutil.move(source+'/'+file1, dest1)#14 line ... elif (f.startswith("LO8227069") or f.startswith("LC8227069")): ... shutil.move(source+'/'+file2, dest2) ... Runtime error Traceback (most recent call last): File "<string>", line 14, in <module> File "C:\Python27\ArcGIS10.4\Lib\shutil.py", line 302, in move copy2(src, real_dst) File "C:\Python27\ArcGIS10.4\Lib\shutil.py", line 130, in copy2 copyfile(src, dst) File "C:\Python27\ArcGIS10.4\Lib\shutil.py", line 82, in copyfile with open(src, 'rb') as fsrc: IOError: [Errno 22] invalid mode ('rb') or filename: 'C:\\Test\\Landsat/LO82270682016229*' Thanks!
... View more
02-10-2017
04:20 PM
|
0
|
4
|
3285
|
POST
|
Hi, I would like move automatically files witch are scenes of Landsat 8 (each scene has 9 bands/files + MTL) inside a folder, to folders which have the same name from initial name's files (these directories need be created). Each band file is Ziped separately, beyond the metadata (.txt). Next line shows a instance from the files names that already exist and a good name for a directory. e.g. LO82270682016229CUB00_B1.tif.zip, LO82270682016229CUB00_B2.tif.zip to directory LO82270682016229. I tried too a script which needs imports the module RE, see web page <moving multiple files>. But, unsuccessfully, the python doesn't works - It not even shows RE module when I type import RE + enter. The CPU's softwares are Arcmap 10.1 - Python 2.7.2 - Windows 8. >>> import shutil ... import os ... ... source = 'C:\Teste_Auto_CLEIA\Ima_compactadas\Landsat' ... dest1 = 'C:\Teste_Auto_CLEIA\Ima_compactadas\L82270682016229' ... dest2 = 'C:\Teste_Auto_CLEIA\Ima_compactadas\L82270692016229' ... ... files = os.listdir(source) ... ... for f in files: ... if (f.startswith("LO82270682016229") or f.startswith("LC82270682016229")): ... shutil.move(source, dest1) #12 line ... elif (f.startswith("LO82270692016229") or f.startswith("LC82270692016229")): ... shutil.move(source, dest2) ... Runtime error Traceback (most recent call last): File "<string>", line 12, in <module> File "C:\Python27\ArcGIS10.1\Lib\shutil.py", line 298, in move copy2(src, real_dst) File "C:\Python27\ArcGIS10.1\Lib\shutil.py", line 127, in copy2 copyfile(src, dst) File "C:\Python27\ArcGIS10.1\Lib\shutil.py", line 81, in copyfile with open(src, 'rb') as fsrc: IOError: [Errno 2] No such file or directory: 'C:\\Teste_Auto_CLEIA\\Ima_compactadas\\Landsat' Thanks in advance!
... View more
02-10-2017
08:24 AM
|
0
|
9
|
6723
|
POST
|
I sorry to have came late, but... It Works, Thanks for helping Jeff!!!
... View more
01-12-2012
02:11 PM
|
0
|
0
|
3325
|
POST
|
I`m trying export multiple files created by DDP to ".mxd" once each page has the file name defined by the "page name" or by a "field name". Some what the ArcGis already does to export to ".pdf" whereas it exports single-page documents using the page name for the output file name. I saw a script from Ideas webpage: Export Data Driven Pages to MXD which is almost perfect to me, but the file name came from Page number. I`ve tried modify It considering all the information that I saw on another pages (Help, ArcGIS Ideas, Foruns), but it doesn`t works until now. I would like that somebody can helps me. I've made a copy from the last version of script: >>>import arcpy, os ... mxdPath = r"C:\...\Projeto_DataDrive.mxd" # The original path is too large ... mxd = arcpy.mapping.MapDocument(mxdPath) ... mxdDir = os.path.dirname(mxdPath) ... for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1): ... pageName = mxd.dataDrivenPages.pageRow.COD_APRT #This line wasn't here in the original script. The FieldName who is indexing the DDP is COD_APRT ... mxd.dataDrivenPages.currentPageID = pageNum ... mxdName = os.path.join(mxdDir, "DDPMap" + str(pageName) + ".mxd")# I just modified str(pageNum) to str(pageName) ... mxd.saveACopy(mxdName) ... del mxd ... I will appreciate any help.
... View more
01-10-2012
02:23 PM
|
1
|
11
|
10108
|
Title | Kudos | Posted |
---|---|---|
1 | 01-10-2012 02:23 PM |
Online Status |
Offline
|
Date Last Visited |
02-15-2023
03:01 AM
|