| 1. |
Solve : Seek help on how to use this batch file...? |
|
Answer» Hi there, Oh look! Somebody else with exactly the same question! What are the odds??At least he appears to be sharing information between the two. Can't fault him for covering his bases.Hey, I am back. Got tied up with a few other pressing issues. Yes, I did post this issue at a few different forums. Looking for options. Here is what I did with your latest script. Called it T2GT-CH.bat. I placed this in a workfolder I call Geotest along with the python script and the files I wish to process. They were the following files: ALBQ_T20.tif (has the geo info I need) ALBQ_T20_BM.tif (needs geo info) ALBQ_T20_LM.tif (needs geo info) ALBQ_T20_WM.tif (needs geo info) I tried running your bat inside the regular command window and also tried this using the OSGeo4W command window and had the same results. Nothing was processed. This was in the command window: S:\WORKFOLDER\Geotest>T2GT-CH.bat gdalcopyproj.py "ALBQ_T20.tif" "ALBQ_T20_.tif" gdalcopyproj.py "ALBQ_T20_BM.tif" "ALBQ_T20_BM_.tif" gdgdalcopyproj.py "ALBQ_T20_LM.tif" "ALBQ_T20_LM_.tif" gdalcopyproj.py "ALBQ_T20_WM.tif" "ALBQ_T20_WM_.tif" press any key to continue... An Update - the author of the original bat got back to me and I do have his bat file working. You weren't sure what he was up to with his file? I noticed there were some emoticons in there in this post for the "", was that why? Anywho, that was so he could determine how many characters for the filename to search for. I changed that number to match mine and the "....." as well. I placed that bat file in the same folder as the files to process along with the python script. Opening the OSGeo4W command window and to the path of the bat I was able to process successfully. But I like your idea in your bat file of changing the finished file to signify a change, the "_". Tell me, could that be optional say I want to add a small "g" at the end rather than a "_"? So That is why I am still trying to get you bat to work... or maybe just change his to add an optional character at the end? ClutchIt didn't process anything because I put a print statement to make sure you got the output you wanted before you messed with your files (It's a common batch practice). If the output are the commands you want to run, remove the 'echo' in the 6th line. Yes, you can use g instead of _, but it won't work as well, as it will then not process anything that ends in a g. This however could end up being a file you want processed. Instead, I'd do a '_g' if you still want the g. To do this, simply change all instances of _ to _g in my code. (even the one in line 6). I'm glad you got it working though. Quote from: Clutch Cargo on April 20, 2015, 11:27:34 AM Hey, I am back. Got tied up with a few other pressing issues. Yes, I did post this issue at a few different forums. Looking for options. Those of us that recall how to use the T word, and why giving feedback to your question is important, simply shake their head. Maybe the younger people think all this is typed by AI bots and there isn't a real person answering at all. HI foxidrive, Not sure I understand your last? Did I do something incorrect here? What is the "T" word?Hi Lemonilla, An update. I removed the "echo" as you instructed. It would not process. So I added "python" in front of the gdalcopyproj.py and there it appears it tried to process but got the following error message: <'Unable to open', 'ALBQ_T20_.tif', 'for writing'> then it said 'ALBQ_T20_BM_.tif' does not exist in the file system. It REPEATED that message for the _LM and _SH file as well. It sounds like the bat is trying to match up a one-to-one filename to process where the _BM, _LM, and _SH should be matching up only to the ALBQ_T20.tif which has the geo info I need transferred. Hope that makes sense. ClutchThe error you are getting is a python code error, and it is running on the _SH, _BM, and _LM files because I didn't know they were to be excluded. Change this line: for /f "delims=" %%a in ('dir /a-d /b *.tif ^| find /v "_." ') do ( to this: for /f "delims=" %%a in ('dir /a-d /b *.tif ^| find /v "_SH." ^| find /v "_BM." ^| find /v "_LM." ') do ( to EXCLUDE files ending in those characters. To fix your python error, try changing this line: dataset = gdal.Open( input ) to this: dataset = gdal.Open( input.replace("\"","") ) Make sure that you don't mess up the indentation, as that is how python interprets blocks of code. Or what might be the problem is that it is reading the arguments wrong. You can also try changing any instance of sys.argv
Ok, tired the latest. What I got was: <'Unable to open', 'ALBQ_T20_.tif', 'for writing'> Sounds like to me it is still trying to find a file that does not exist in the list?. Also, it sounds maybe the bat file is becoming too literal in the sense of only excluding/including certain filenames. I fear my range of filenames that can vary from "XX_XX.tif" to "XXXXX_XXXX.tiff" for the files with geo info, to "XX_XX_XX.tiff" to "XXXXXX_XXXX_XXXX.tif" for files that need info is making this quite cumbersome. The only constant character is that second "_" for files that would need geo info inserted. Since the first bat file I posted in my very first post now works, would it be easier on your part to just modify that one to allow me the option to add text of my choice (for example, like a "_" or a"g" or whatever), just before the ".tif"? I just don't want to have you continue to have to work on this while I am sure others are waiting for your expertise. So for example, if I have a file with geo called CA_T20.tif and the file I want to add geo is called CA_T20_LM, I would have the option to call the processed file CA_T20_LMg. It would not create a new file but just rename the file after being processe I really do appreciate you being so patient with me on this and you have put so much work already into this... that's why I'm thinking just modify the first. What do you think?I believe the isssue is somewhere between passing info from the batch file to the python script. Would it be possable for you to post the python acrtipt (in code brackets) along with any dependancies and test files so that i can do some teating on my end.OK,.... if you really want to do this Sorry for my ignorance but when you said in brackets I wasn't sure if you mean literally just put the code in brackets "[]". The python script is actually in my first post at the top. I have also attached the file as well and just gave it a txt suffix so I could upload it if that's easier for you. I have created some very-very small sample files for you to test with. Actual files we use run anywhere from 327MB to 4GB in size ( take awhile to upload!). Here is a list. As you can see the filenames that need geo can be quite different looking but the basic format convention is the same: SOCAL_DD66.tif SOCAL_DD66_BM3.tif SOCAL_DD66_LM.tif SOCAL_DD66_WM1.tif SOCAL_DD66_aSCC.tif 1. Any file that has only one underscore "_" would be the file that contains the geo information. 2. Any file that has a second underscore needs geo info. I guess if I had my "ultimate" bat file it would be able to drop a bunch of files into a folder like so: CA_A1.tif CA_A1_LM.tif CA_A1_BM.tif CA_A1_WM.tif CA_A1_aSSC.tif NV_AA3.tif NV_AA3_LM1.tif NV_AA3_BM2.tif NV_AA3_WM2a.tif NV_AA3_ATCC.tif SOCAL_DD66.tif SOCAL_DD66_BM3.tif SOCAL_DD66_LM.tif SOCAL_DD66_WM1.tif SOCAL_DD66_aSCC.tif From there I could just drop the folder onto the batch file and it would process automatically and results would be in the same directory. The bat file would allow me the option to add a single character or even text at the end of the processed file or to just leave the filename as is. Again, for example going from SOCAL_DD66_aSCC.tif to SOCAL_DD66_aSCCg.tif if I wish. The program I use OSGeo4W, is really just a collection of geographic tools for processing data. It is a free download. It can be a rather large download and I am really only using the Python portion of the toolset. You can choose which tools you wish to install during the install if you choose "advanced" if (I remember correctly), rather than an "auto" install. So that can make it a lot smaller and quicker to install should you care to give it a try. The link is: http://trac.osgeo.org/osgeo4w/ or just google OSGeo4W. I downloaded and installed the 32bit version. I did try just installing Python itself from the python website but I can't get it the python script to work that way. So I use OSGeo4W. Just was thinking that could save time rather than installing the toolset. Maybe not a big deal. Because of the severe size limitiations and types I am making several posts with attachments. Named them all TXT so they would upload. [attachment deleted by admin to conserve space] |
|