I'm trying to take an image out of a KMZ file. I currently have the local path of the kmz and the path of the file inside its respective kml file (relative, not global), and what I need is to get the path to load the file to a database. Is there a way to get it using basic string-type paths?
A KMZ is just Zip archive (with a .kmz extension instead of .zip), so you should be able to unzip it and access all the files with "zipfile" or similar.
Related
I am wondering if there is an easy way to access 'parallel' directories (See photo for what I am talking about... I don't know what else to call them, please correct me if they are called something else!) from a Python file without having to input the string path.
The basic structure I intend to use is shown in the picture. The structure will be used across different computers, so I need to avoid just typing in "C:\stuff_to_get_there\parent_directory\data\file.txt" because "C:\stuff_to_get_there" will not be the same on different computers.
I want to store the .py files in their own directory, then access the data files in data directory, and save figures to figures directory. I was thinking of trying os module but not sure if that's the correct way to go.
parent directory
scripts
.py files
figures
save files here
data
.txt files stored here
Thanks for any help!
i am working on a new assingment where i have asked to bulit a CNN classification model .how to handel when data is given in Gz file type and have diffent folders with images.
Before now have only worked on csv type file but currently i am not able to how to handel this type of data having only images in different folder and that folder contains in gz type of file.
Before going further you need to know what .gz is. It's a file format like zip. In order to uncompress the file, you can follow the following commands on linux
tar -xvzf file.tar.gz
On Windows - Use winrar or winzip.
I have a program in Python (Python 3 on Ubuntu 16.04) that checks for new files in a directory (.mp4 files are the result of segmenting a live video stream). I use os.listdir(path) to get the new files in my iterations. The problem is that when a new .mp4 file is created, first an empty file is created while the contents are being appended incrementally, so the file is not yet finalized/finished/playable (usually if you look at a folder, these files are shown like no extension).
Is it possible to ignore such non-finalized files at the Python level when getting the list of files in directory? Maybe some functions or API exists for that?
Using glob.glob('*.mp4', root_dir=path) should be just fine.
https://docs.python.org/3/library/glob.html
This might be a general programming question but since I am doing it from within an Add-In therefore asking here at GIS forum. I have a project folder with sub-folders containing several files on my hard disk which I read from within my Python Add-In, its hard coded e.g.:
dem = r'C:/project/raster/dem'
and Add-In is in
r'C:/project/Add-In'
folder. I tried doing '../raster/dem' to define path of input raster layer but it failed to read. Please suggest how can I make it generic so that if I move project folder to D drive then Add-In would still be able to read data.
You can reference materials that are located within the add-in, everything that's included within the 'Install' directory will be copied into the appropriate location within AssemblyCache. You can then reference this by doing something like:
local_path = os.path.abspath(os.path.basename(__file__))
raster_path = os.path.join(local_path, 'rasters')
And from there, treat raster_path as a nomral path.
You could read in a configuration file stored under the user's profile. Because ArcGIS add-ins overwrite themselves every time the host application is opened, you don't want to store user-specific configuration information inside the add-in itself.
The configuration file can be in any format you want (e.g. XML, plain text), but the ConfigParser class makes reading and writing to an INI-like file format easy.
Hi i am having a one xml file and some image files, i am making my one concatenate file (ie as like tar file) from all these file (i am having my own scripts for tarring and untarring).
before i describe what exactly i want you have to look the current situation.
As of now i have to untar the all files into a directory then i am able to read the xml file which is part of the tar file.Then i read the data from xml file and then i am able to draw image mention in xml ( image names are mention in xml attribute value) on corresponding panels.
Now i want when someone click on my tar file, i should able to read the xml file and then i am able to read all the other images ( data) and i can draw on the corresponding panel with extract specifically in to a directory.
Is any method or any help really help me alot.
Thanks in advance.
The tarfile module gives you access to tarballs. It won't be random access, but you can read out any files you need and put them in a temporary directory, or just store them in strings.