POST
|
Not sure how to rename batches of files with python, but there is a free software worth looking into called file renamer that I’ve used in the past. But it’s possible someone on here might be able to help out with the renaming. I think windows powershell can do simple stuff like replacing specified text with some other text which is probably what you want assuming you want to change MYD to MOD. If you use Windows, look up something along the line so if ‘powershell file renaming replace’ and you’ll find plenty of helpful pages.
... View more
11-28-2019
04:02 AM
|
1
|
0
|
882
|
POST
|
The clue to your problem is in the light grey text towards the bottom. You will notice that those file names do not match with the files you’re trying to retrieve. You need to make sure the ‘raster2 = ‘ command pieces together a name that matches your input data. It is making the wrong name and then it can’t find that file because of it so you get the error. It’s also possible to file names might be too long but give it a go and it might be fine. I can take a closer look at this later on as well. Let me know if that makes sense Get Outlook for iOS<https://aka.ms/o0ukef>
... View more
11-24-2019
06:34 AM
|
0
|
15
|
834
|
POST
|
Hi Raviteja, assuming you copied and pasted the error, I think the problem will involve the fact that '.tif.tif' is doubled up at the end of the file it is trying to retrieve from the input dataset. This suggests to me there could be a problem with your formatting or use of splittext as it is taking the full file name with .tif at the end and then adding another .tif. Could you post your code exactly as you entered it?
... View more
11-23-2019
06:49 PM
|
0
|
18
|
834
|
POST
|
Can you also post the full code that’s giving you this error? It can be easy to miss one tiny thing. A common cause of this error message is missing the parentheses after a function. In this case the problem could be the line ‘rasters = arcpy.ListRasters()’. If you don’t have the parentheses at the end of it or you don’t run it at the same time as the ‘for r in rasters’ line it won’t work. Get Outlook for iOS<https://aka.ms/o0ukef>
... View more
09-16-2019
06:42 PM
|
1
|
2
|
1335
|
POST
|
Are you running everything before the ‘for r in rasters:’ at the same time as everything after? Or are you running the first part and then the second part? I think some of it won’t work if it isn’t all run at the same time. Get Outlook for iOS<https://aka.ms/o0ukef>
... View more
09-16-2019
06:36 PM
|
0
|
0
|
1335
|
POST
|
I believe your last issue may be you’re missing the last line of code ‘mycalc.save(outraster)’ and because of this it is overwriting each output with each run leaving you with only the output of the final multiplication. If you include this last line and run it it should save them all. Get Outlook for iOS<https://aka.ms/o0ukef>
... View more
09-12-2019
11:25 PM
|
1
|
5
|
1335
|
POST
|
Hi Anna, your new problem is that the ‘raster2’ line has ‘outws’ in it instead of ‘inws’. You are telling it to look in your output folder for your second raster set (combined). Change it to inws and try it again. Get Outlook for iOS<https://aka.ms/o0ukef>
... View more
09-12-2019
07:06 PM
|
1
|
8
|
1335
|
POST
|
Hi Anna, please see my (hopefully helpful) explanation of the code I successfully used below with my data. Something of note is that how your files are named is extremely important to this code working which is why it is not working for you. For my answer I'll assume your first raster set is named date_ndvi.tif and your second raster set is named date_combined.tif. Because I don't know what you want your output rasters to be called I will assume it will be date_multiply.tif. Please read my hastily put together explanation in the attached image below before continuing. Okay, now make sure you have the correct filepaths specified in your code and then replace the following lines: Replace prefix1 = prefix.rstrip("1") with prefix1 = prefix.rstrip("ndvi") Replace raster2 = os.path.join(inws1, prefix1 + "3" + suffix) with raster2 = os.path.join(inws1, prefix1 + "combined" + suffix) Replace outraster = os.path.join(outws, prefix1 + "4") with outraster = os.path.join(outws, prefix1 + "multiply" + suffix) Now it should hopefully work. The code wasn't working originally because it couldn't find your second set of rasters. In the raster2 line you added a "3" to your file name and then it couldn't find any rasters with that name. This is why it says 20050318_ndvi3.tif doesn't exist because you accidentally added a 3 to it. I hope this helps. Let me know how it goes. I'm a beginner as well and I only know what this code means because I worked backwards and looked at it piece by piece after the code worked after having it given to me by the good samaritan Johannes Bierer.
... View more
09-12-2019
06:27 AM
|
1
|
12
|
2387
|
POST
|
Hi Anna, could you provide your code that you used? I can’t remember right now and I don’t want to make promises but I think I encountered a similar issue and I can look at it when I get home later today (approx 9 hours from now). Also is the error file the first one in the list? Get Outlook for iOS<https://aka.ms/o0ukef>
... View more
09-10-2019
05:37 PM
|
0
|
15
|
2387
|
POST
|
I have one folder (folder 1) with 200 or more rasters and another folder (folder 2) with the same number. The rasters in folder 1 are all named genus_species_01 (e.g. acan_rufo_01, lito_bico_01, and so on). The rasters in folder 3 are the same but end with _03 instead. Each raster needs to be multiplied with it's corresponding raster from the other folder and the output must retain the species name and be saved in another folder. I am completely inexperienced when it comes to Python but I believe it is the only way to achieve this task. The link below describes a possible solution to my problem only I am not proficient enough at formatting code (or understanding it) to be able to adapt it to my problem. python - How to use the math tool ("times") in ArcGIS modelbuilder to multiply two raster sets while using an iterator? … I understand what most steps do but in some cases I'm unsure of what I need to change. In particular some of it would need to be changed based on the fact my rasters are located in separate folders rather than all within the same geodatabase as it is in the linked solution. Another part I am unsure about is prefix = r.split("_")[0] + "_" . To my understanding, this will split the raster name at the '_' character in order to retrieve the identifying first part of the name. But as far as I know the [0] refers to the first file in the specified workspace. So if my folder has over 200 rasters would I need to include r.split("_")[0] through to [200]? Another potential issue is that I need both the abbreviate genus and species so it can only split the name at the second '_' and not the first. Is anyone able to offer some guidance?
... View more
03-21-2019
12:12 AM
|
1
|
48
|
8075
|
POST
|
I am trying to run various tools on a large number of rasters beginning with Project Raster but the last raster is always missed and so the output has one less raster in it. The model appears to run successfully with no errors given. All rasters were previously defined successfully using the raster iterator. Below is my model I am using to project my rasters and also convert them from ASCII to Esri Grid in the process. Because I want to maintain the names of the rasters I am using in-line substitution. Normally I would use the %name% in-line substitution but this also includes the .asc file extension which prevents converting to Esri Grid as this output format is specified by a lack of an extension. So instead I am using Parse Path with name chosen as the Parse Type so that %value% can be used as in-line substitution for the original file name without the extension. All seems well at this point, but when I run the model all but the last raster are output by the model (all rasters are named with four numbers, e.g. 1457). I was able to successfully project the missing rasters individually but then I discovered that all the rasters outputted by the model had been given the wrong names. It seems that the name is applied to raster that's next on the list instead of the actual raster it belongs to. Biggest clue I've found so far is that it only occurs when using Parse Path. But as I mentioned above, if I just use %name% without Parse Path I won't be able to convert to Esri Grid, and if I choose another format such as TIFF my file names will be exampleraster.asc.tif which causes more problems down the line because of the double file extension. I have been able to reproduce this problem with multiple folders of rasters and when I remove the 'problem raster' that was skipped and run the model again it then repeats the problem again and skips the next last raster. The same issue occurs with other tools I need to use such as Raster to Polygon. I have had the exact same problem using ArcMap 10.6.1 and 10.4.1. Not sure if this is useful or not but the problem doesn't occur if the folder only contains one raster, but does occur when it contains two. Summary: Trying to project multiple raster in one folder using iterate rasters in Model Builder. Original files in ASCII format. Output in Esri Grid Prior to this step all rasters were defined using raster iterator. Using in-line substitution to maintain original raster names. Model runs successfully with no errors or obvious issues. Last raster missing from output and other rasters have been misnamed - all names applied to next raster in line instead. Issue is reproducible for other data, other tools, and across multiple versions of ArcMap (10.6.1 and 10.4.1). Issue only occurs when using Parse Path Does anyone know what might be going on or any workarounds? I am a relative beginner to GIS so I have no experience with Python at present but I suspect I may have to teach myself soon.
... View more
02-12-2019
09:20 PM
|
0
|
2
|
1382
|
Title | Kudos | Posted |
---|---|---|
1 | 11-28-2019 04:02 AM | |
1 | 09-12-2019 11:25 PM | |
1 | 09-16-2019 06:42 PM | |
1 | 09-12-2019 07:06 PM | |
1 | 09-12-2019 06:27 AM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|