POST
|
I have three Feature Classes and all them are at the same geodatabase. For help you, I send a screen grab that we are talking about. Good luck. *Addition info, I know the FeatureClass[1] has the piece's name that I'm looking for. And I don't know how to retrieve the records from the FeatureClass'field to use at the script.
... View more
02-21-2018
06:46 PM
|
0
|
1
|
720
|
POST
|
Interesting path, but I didn't find a way for switch a text (e.g. 2015178eAnt015146) for a result from a ListFeatureClass
... View more
02-19-2018
11:31 PM
|
0
|
0
|
720
|
POST
|
Script works successfully!!! Thanks Randy and everyone who helps. 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 Another FC # Line 11 ... FCName = arcpy.ListFeatureClasses("pol*") ... FC_Name = FCName[1] ... print"FC_Name: "+str(FC_Name) ... FCNameCut = FC_Name[19:36] # Isn't original line ... print"FCNameCut "+FCNameCut ... ... #Calculate field (D2clust200m) #Line 18 ... with arcpy.da.UpdateCursor(Feature, ('D2clust200m')) as curs: ... for row in curs: ... if row[0] is not None: ... row[0] = row[0].replace(FCNameCut, "test") ... curs.updateRow(row) ... print"Randy's try"
... View more
02-19-2018
10:48 PM
|
1
|
3
|
720
|
POST
|
Yes, I was using the line. I changed this line, accepted the Randy's tip and cleaned the script. I show the last version: 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 FC # line 11 ... FCName = arcpy.ListFeatureClasses("pol*") ... FC_Name = FCName[1] ... print"FC_Name: "+str(FC_Name) ... FCNameCut = FC_Name[19:36] # I changed now ... print"FCNameCut "+FCNameCut ... ... #Calculate field (D2clust200m) #Line 18 ... arcpy.CalculateField_management (Feature, "D2clust200m", '!D2clust200m!.replace(FCNameCut, \"test\")',"PYTHON_9.3") ... print"Randy 1 try Calculated" ... print"Done" ... Feature: S_pol_Din_DepL82270692015146eAnt015130 FC_Name: pol_Din_DepL82270692015178eAnt015146 FCNameCut 2015178eAnt015146 Runtime error Traceback (most recent call last): File "<string>", line 19, in <module> File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\management.py", line 3360, in CalculateField raise e ExecuteError: ERROR 000539: Error running expression: u"2015178eAnt015146".replace(FCNameCut, "test") Traceback (most recent call last): File "<expression>", line 1, in <module> NameError: name 'FCNameCut' is not defined Failed to execute (CalculateField). Something else to do?
... View more
02-18-2018
10:13 PM
|
0
|
13
|
992
|
POST
|
Randy, It didn't works #Calculate field (D2clust200m) #This one works if I don't use a list's word # Line 20 ... arcpy.CalculateField_management (Feature, "D2clust200m", '!D2clust200m!.replace(FCNameCut, \"test\")',"PYTHON_9.3") ... print"Randy 1 try Calculated" ... print"Done" ... Feature: S_pol_Din_DepL82270692015146eAnt015130 strFeature: S_pol_Din_DepL82270692015146eAnt015130 FC_Name: pol_Din_DepL82270692015178eAnt015146 FCNameCut 2015178eAnt015146 Runtime error Traceback (most recent call last): File "<string>", line 21, in <module> File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\management.py", line 3360, in CalculateField raise e ExecuteError: ERROR 000539: Error running expression: u"2015178eAnt015146".replace(FCNameCut, "test") Traceback (most recent call last): File "<expression>", line 1, in <module> NameError: name 'FCNameCut' is not defined Failed to execute (CalculateField). Is there some idea?
... View more
02-18-2018
09:33 PM
|
0
|
15
|
992
|
POST
|
Hi, I've Feature Class which keeps changing (e.g. S_pol_Din_DepL82270692015146eAnt015130) and I would like use Arcpy to replace a text (like 2015178eAnt015146) from him field (d2clust200m). Some rows are empty, e.g <Null>, and I don't want change them. But, I can't use replace with a text from ListFeatureClass, it shows that is done, But, isn't. The text that will be replaced is always the same from the last piece's name from the another FC (it always starts with "pol_din"). If it's too hard be done by arcpy, I can use MB. Or even replace just what isn't null. Next, I show all tries I've done. 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)
... strFeature = str(Feature)
... print"strFeature: "+strFeature
...
... #List FC # line 13
... FCName = arcpy.ListFeatureClasses("pol*")
... FC_Name = FCName[1]
... print"FC_Name: "+str(FC_Name)
... FCNameCut = FC_Name[-17:]
... print"FCNameCut "+FCNameCut
...
... #Calculate field (D2clust200m) #Line 20
... arcpy.CalculateField_management (Feature, "D2clust200m", "!D2clust200m!.replace('"'FCNameCut'"', \"test\")","PYTHON")
... print"Try 1 Calculated"
...
... #Calculate field (D2clust200m)
... #arcpy.CalculateField_management (Feature, "D2clust200m", "!D2clust200m!.replace(\"FCNameCut\", \"test\")","PYTHON")
... #print"2nd try Calculated"
...
... #Calculate field (D2clust200m)
... #arcpy.CalculateField_management (Feature, "D2clust200m", '!D2clust200m!.replace('"'FCNameCut'"', '"'test'"')',"PYTHON")
... #print"Try 3 Calculated"
...
... #Calculate field (D2clust200m) #This one works if I don't use a list's word
... #arcpy.CalculateField_management (Feature, "D2clust200m", '!D2clust200m!.replace(\"FCNameCut\", \"test\")',"PYTHON")
... #print"4th try Calculated"
... print"Done"
...
Feature: S_pol_Din_DepL82270692015146eAnt015130
strFeature: S_pol_Din_DepL82270692015146eAnt015130
FC_Name: pol_Din_DepL82270692015178eAnt015146
FCNameCut 2015178eAnt015146
Try 1 Calculated
Done Thanks *I'm using Arcmap 10.4 with Python 2.7, but I appreciate if it works on ArcMap 10.1
... View more
02-18-2018
05:27 PM
|
0
|
17
|
2132
|
POST
|
Branched from: Help: Batch - composite bands Arc-python Hi, I would like use this script, but it fails. Some hint? 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".
#The output files place
outws = r'C:\Teste_Auto_CLEIA\Imagem' # Line 9
for folder in folders:
arcpy.env.workspace = folder
rasters = arcpy.ListRasters("*.tif") # I already erased the bands which I won't use
chk4 = ['band{0}.tif'.format(i) for i in range(0, 7)] # I changed the range
rasters = [a for a in rasters if a[-9:] in chk4]
name = os.path.join(outws, rasters[1].split("_")[0] + ".tif") # I wrote "outws"
arcpy.CompositeBands_management(rasters, name) # I put it
print(rasters) I'm using ArcMap 10.1 and the bands names aren't the same, for instance, "LO82270682017183CUB00_B1", ... , "LO82270682017183CUB00_B7". Thanks!
... View more
12-21-2017
10:28 PM
|
0
|
11
|
3518
|
IDEA
|
I would like that Model Builder - MB and Python's sript have a friendly UI box message to shows the task is completed done. After MB or python'script is executed, the nowadays progress info isn't user-friend GUI to both, e.g. can shows the input datas and that 30 tools was performed. But, an usual user can just wish be noticed about an info from the created data or know if script/MB is done correctly. So, the popup must have the following option info: - with a Personal Text, e.g. All is done correctly!, - a Table (or him selected records) from a Feature Class created by the MB (or python) or - a Statistic from a Feature Class (e.g. The "Intersect_Polygon.shp" has 17 records with name "Vegetation" & 0 records with name "Water"). The user should choose the Feature Class and the Field that the record's statistic will be showed. Considering that popup is friendly GUI, will be great that it allows set how to close It. Could de automatically (after 30 seconds) or pushing "OK". *I don't know well ArcGIS Online or Add-in, but I saw that ESRI already has experience with Popup and should easier do It. Configure pop-ups and python addin modules. Below has a simple example to illustrate:
... View more
02-27-2017
06:17 PM
|
1
|
0
|
439
|
IDEA
|
I would like that Model Builder - MB and Python's sript have a friendly UI box message to shows the task is completed done. After MB or python'script is executed, the nowadays progress info isn't user-friend GUI to both, e.g. can shows the input datas and that 30 tools was performed. But, an usual user can just wish be noticed about an info from the created data or know if script/MB is done correctly. So, the popup must have the following option info: - with a Personal Text, e.g. All is done correctly!, - a Table (or him selected records) from a Feature Class created by the MB (or python) or - a Statistic from a Feature Class (e.g. The "Intersect_Polygon.shp" has 17 records with name "Vegetation" & 0 records with name "Water"). The user should choose the Feature Class and the Field that the record's statistic will be showed. Considering that popup is friendly GUI, will be great that it allows set how to close It. Could de automatically (after 30 seconds) or pushing "OK". *I don't know well ArcGIS Online or Add-in, but I saw that ESRI already has experience with Popup and should easier do It. Configure pop-ups and python addin modules. Below has a simple example to illustrate:
... View more
02-27-2017
06:17 PM
|
1
|
0
|
576
|
POST
|
Before script runs, it's all right. Is the script that creates the folder and moves the file. But, the script looks the path with the file that himself moved and see an error.
... View more
02-16-2017
06:36 AM
|
0
|
0
|
3182
|
POST
|
My best shot was do 1 script to create the folders and run it first. I avoid script it with the second one for precaution, I think that is possible the script moves the band's file to a directory and later, that this directory be replaced for a new empty folder. In the first script, I just wanna create path with the same basename onetime. Is there anyone who knows how to do it? >>> import fnmatch #This script create the folders ... ... source = r'C:\Test\Landsat' ... ... for file in os.listdir(source): ... if fnmatch.fnmatch(file, 'L?8*'): ... arcpy.CreateFolder_management(test, file[:16]) ... print file[:16]#This line is just to know which folders have been created ... LO82270682016229 LO82270682016229 LO82270692016229 LO82270692016229 And at the last script, it fails after move the first file to the right path. >>> import shutil ... import os, fnmatch #put fnmatch ... ... source = r'C:\Test\Landsat' ... dest1 = r'C:\Test\LO82270682016229'#put the same name from the folders created one step before ... dest2 = r'C:\Test\LO82270692016229'#put the same name from the folders created one step before ... file1 = 'LO82270682016229CUB00_B1.tif.zip'# I changed it to work with 1 band ... file2 = 'LO82270692016229CUB00_B1.tif.zip'# I changed it to work with 1 band ... ... files = os.listdir(source) ... ... for f in files:#12 line - This line is OK ... if (f.startswith("LO8227068") or f.startswith("LC8227068")): ... shutil.move(source+'/'+file1, dest1) ... 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 292, in move raise Error, "Destination path '%s' already exists" % real_dst Error: Destination path 'C:\Test\LO82270682016229\LO82270682016229CUB00_B1.tif.zip' already exists *I did a script that joined both of them, and It created the folders like the first. But it failed so soon it moved one file, by the same way that these two scripts above did. You can see the message error below: Runtime error Traceback (most recent call last): File "<string>", line 17, in <module> File "C:\Python27\ArcGIS10.4\Lib\shutil.py", line 292, in move raise Error, "Destination path '%s' already exists" % real_dst Error: Destination path 'C:\Test\LO82270682016229\LO82270682016229CUB00_B1.tif.zip' already exists So, if has someone to help, I will be thankful!
... View more
02-15-2017
09:00 PM
|
0
|
2
|
3182
|
POST
|
I ran the script and looks that later him remove the file, It doesn' find the file at the original path. I checked the file's name and the basename at statement, both of them match.
... View more
02-13-2017
05:40 PM
|
0
|
0
|
3182
|
POST
|
I aready replaced those lines for: ... file1 = 'LO82270682016229CUB00_B1.tif.zip'# I changed it to work with 1 band ... file2 = 'LO82270692016229CUB00_B1.tif.zip'# I changed it to work with 1 band But, the script stops after remove the "file1" to a file without extension with the same name from the folder that It should go. i.e. the scripts needs be shifted to create folders from the last piece of directory's destine. 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 2] No such file or directory: 'C:\\Test\\Landsat/LO82270682016229CUB00_B1.tif.zip' I'm looking for the python page from your link and think and trying the best way. Also, I should try do a script without the name from each file to avoid update (re-script) it every time that I will use it. I pretend put the best try here, when I find the best function. I'm considering too others python's pages.
... View more
02-12-2017
02:49 PM
|
0
|
2
|
3182
|
POST
|
It works!!! Thank you I just replaced: tarfile.TarFile(... for: tarfile.open(... 2017-01-30 16:43 GMT-03:00 Curtis Price <geonet@esri.com>: GeoNet <https://community.esri.com/?et=watches.email.thread> Re: How to unpack .tar.gz files with Python? reply from Curtis Price <https://community.esri.com/people/curtvprice?et=watches.email.thread> in Python - View the full discussion <https://community.esri.com/message/662700-re-how-to-unpack-targz-files-with-python?commentID=662700&et=watches.email.thread#comment-662700>
... View more
01-30-2017
01:23 PM
|
0
|
0
|
2413
|
POST
|
Hi, I would like do the same thing to multiple Giz and Tarfiles. I already replaced "zipfile" for "tarfile" at the script, but It doesn't works with Python 2.7.1 at ArcMap 10.1 (but will be good which It works with newer ArcMap) >>> import tarfile,fnmatch,os
... rootPath = r"C:\Teste_Auto_Unzip"
... pattern = '*.tar.gz'
... for root, dirs, files in os.walk(rootPath):
... for filename in fnmatch.filter(files, pattern):
... print(os.path.join(root, filename))
... tarfile.TarFile(os.path.join(root, filename)).extractall(
os.path.join(root, filename.split(".")[0]))
...
C:\Teste_Auto_Unzip\LC82270692015242LGN00.tar.gz
Runtime error
Traceback (most recent call last):
File "<string>", line 7, in <module>
File "C:\Python27\ArcGIS10.4\Lib\tarfile.py", line 1581, in __init__
self.firstmember = self.next()
File "C:\Python27\ArcGIS10.4\Lib\tarfile.py", line 2356, in next
raise ReadError(str(e))
ReadError: invalid header Thanks in advance!
... View more
01-30-2017
09:17 AM
|
0
|
2
|
26450
|
Title | Kudos | Posted |
---|---|---|
1 | 02-19-2018 10:48 PM | |
1 | 02-27-2017 06:17 PM | |
1 | 02-27-2017 06:17 PM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|