I'd like to know if it's possible to read/write GML files (or even KML files) using Fiona.
Fiona documents don't specify what drivers we can use. I read some answers about the drivers that are avalaible but I still haven't figured out the right answer.
These two different sentences print a different number of drivers. The first one doesn't include GML o KML (in fact there are very few formats supported).
print(fiona.supported_drivers)
vs
print('\n'.join(sorted(fiona.drivers().drivers())))
I know how to do it using GDAL/OGR but I want to do the same using Fiona if it's possible.
In order to read both KML and GML file formats the OGR binaries distributed with the Fiona implementation you're using need to be compiled against libexpat or Xerces (XML parsers). If these libraries exist in the same installation where the ogr.dll (Windows), ogr.so (Linux) used by Fiona is, then read support is most probably available. If no, then only write support will be available.
I've just found out that the newest version of Fiona added support to read and write GML files.
Related
How to read cgns file contain mesh in python?
I found one package Pymesh but this package only deal with (read/write 2D and 3D mesh in .obj, .ply, .stl, .mesh).
Does anyone knows any package?
If the CGNS file is written with hdf5 (instead of the older ADF versions) you can open them with the python libraries h5py or tables. I use these to read my CGNS files and access them like any other hdf5 file. The same could be said for matlab or any other language... if you can read hdf5 you can read CGNS. I believe CGNS versions 3+ default to hdf5.
PyCGNS libraries for CGNS end-users and Python application developpers. Here is link - http://pycgns.sourceforge.net/
meshio now has initial support for CGNS.
I have successfully installed Python and GDAL with guidance from this link
Installation instructions
I've seen some web tools that can convert to and fro the formats I mentioned above. I decided to install ogr2ogr locally. I need some simple instructions to bring up the command tool and convert my files. Most important is the switch to preserve properties or id of the geometries.
According to the GDAL webpage for the GeoJSON driver, GDAL supports reading TopoJSON as of OGR 1.11. It says nothing about writing TopoJSON, so I am assuming writing is not supported.
From the TopoJSON readme, the binary geo2topo will convert GeoJSON to TopoJSON in-place. It looks like that is the tool you should be using, not ogr2ogr.
The workflow would therefore be as follows:
shapefile translated to GeoJSON with ogr2ogr
GeoJSON updated to TopoJSON with geo2topo
Is there any way to import SPSS dataset into Python, preferably NumPy recarray format?
I have looked around but could not find any answer.
Joon
SPSS has an extensive integration with Python, but that is meant to be used with SPSS (now known as IBM SPSS Statistics). There is an SPSS ODBC driver that could be used with Python ODBC support to read a sav file.
Option 1
As rkbarney pointed out, there is the Python savReaderWriter available via pypi. I've run into two issues:
It relies on a lot of extra libraries beyond the seemingly pure-python implementation. SPSS files are read and written in nearly every case by the IBM provided SPSS I/O modules. These modules differ by platform and in my experience "pip install savReaderWriter" doesn't get them running out of the box (on OS X).
Development on savReaderWriter is, while not dead, less up-to-date than one might hope. This complicates the first issue. It relies on some deprecated packages to increase speed and gives some warnings any time you import savReaderWriter if they're not available. Not a huge issue today but it could be trouble in the future as IBM continues to update the SPSS I/O modules to deal new SPSS formats (they're on version 21 or 22 already if memory serves).
Option 2
I've chosen to use R as a middle-man. Using rpy2, I set up a simple function to read the file into an R data frame and output it again as a CSV file which I subsequently import into python. It's a bit rube-goldberg but it works. Of course, this requires R which may also be a hassle to install in your environment (and has different binaries for different platforms).
gretl claims to import SPSS and export in a variety of formats, as does the R statistical suite. I've never dealt with SPSS data so cannot speak to their relative merits.
You could have Python make an external call to spssread, a Perl script that outputs the content of SPSS files in the way you want.
Maybe this will help:
Python reader + writer for spss sav files (Linux, Mac & Windows)
http://code.activestate.com/recipes/577811-python-reader-writer-for-spss-sav-files-linux-mac-/
To be clear, the SPSS ODBC driver does not require an SPSS installation.
Maybe this will be helpful for someone:
http://sourceforge.net/search/?q=python+SPSS
good luck!
Michal
How to read/write a .sit archive using Python in Linux?
For dealing with older library formats I tend to fall back on command line utilities. You should be able to find sit manipulation tools such as this one:
http://ctan.binkerton.com/ctan.readme.php?filename=tools/unstuff/unsit.c
As to making them, I'd suggest using an alternative format. You probably have a specific purpose in mind, but it's a fairly outdated format and you'd be better off with ZIP or TAR.GZ.
I'm looking for a way to read specific files from a rar archive into memory. Specifically they are a collection of numbered image files (I'm writing a comic reader). While I can simply unrar these files and load them as needed (deleting them when done), I'd prefer to avoid that if possible.
That all said, I'd prefer a solution that's cross platform (Windows/Linux) if possible, but Linux is a must. Just as importantly, if you're going to point out a library to handle this for me, please understand that it must be free (as in beer) or OSS.
See the rarfile module:
http://grue.l-t.ee/~marko/src/rarfile/README.html
http://pypi.python.org/pypi/rarfile/
https://github.com/markokr/rarfile
The real answer is that there isn't a library, and you can't make one. You can use rarfile, or you can use 7zip unRAR (which is less free than 7zip, but still free as in beer), but both approaches require an external executable. The license for RAR basically requires this, as while you can get source code for unRAR, you cannot modify it in any way, and turning it into a library would constitute illegal modification.
Also, solid RAR archives (the best compressed) can't be randomly accessed, so you have to unarchive the entire thing anyhow. WinRAR presents a UI that seems to avoid this, but really it's just unpacking and repacking the archive in the background.
The pyUnRAR2 library can extract files from RAR archives to memory (and disk if you want). It's available under the MIT license and simply wraps UnRAR.dll on Windows and unrar on Unix. Click "QuickTutorial" for usage examples.
On Windows, it is able to extract to memory (and not disk) with the (included) UnRAR.dll by setting a callback using RARSetCallback() and then calling RARProcessFile() with the RAR_TEST option instead of the RAR_EXTRACT option to avoid extracting any files to disk. The callback then watches for UCM_PROCESSDATA events to read the data. From the documentation for UCM_PROCESSDATA events: "Process unpacked data. It may be used to read a file while it is being extracted or tested without actual extracting file to disk."
On Unix, unrar can simply print the file to stdout, so the library just reads from a pipe connected to unrar's stdout. The unrar binary you need is the one that has the "p" for "Print file to stdout" command. Use "apt-get install unrar" to install it on Ubuntu.
It seems like the limitation that rarsoft imposes on derivative works is that you may not use the unrar source code to create a variation of the RAR COMPRESSION algorithm. From the context, it would appear that it's specifically allowing folks to use his code (modified or not) to decompress files, but you cannot use them if you intend to write your own compression code. Here is a direct quote from the license.txt file I just downloaded:
The UnRAR sources may be used in any software to handle RAR
archives without limitations free of charge, but cannot be used
to re-create the RAR compression algorithm, which is proprietary.
Distribution of modified UnRAR sources in separate form or as a
part of other software is permitted, provided that it is clearly
stated in the documentation and source comments that the code may
not be used to develop a RAR (WinRAR) compatible archiver.
Seeing as everyone seemed to just want something that would allow them to write a comic viewer capable of handling reading images from CBR (rar) files, I don't see why people think there's anything keeping them from using the provided source code.
RAR is a proprietary format; I don't think there are any public specs, so third-party tool and library support is poor to non-existant.
You're much better off using ZIP; it's completely free, has an accurate public spec, the compression library is available everywhere (zlib is one of the most widely-deployed libraries in the world), and it's very easy to code for.
http://docs.python.org/library/zipfile.html
The free 7zip library is also able to handle RAR files.
Look at the Python "struct" module. You can then interpret the RAR file format directly in your Python program, allowing you to retrieve the content inside the RAR without depending on external software to do it for you.
EDIT: This is of course vanilla Python - there are alternatives which use third-party modules (as already posted).
EDIT 2: According to Wikipedia's article my answer would require you to have permission from the author.