I am trying to convert lots of xyz file to raster, using gdal.Translate in Spyder. But I came across several problems.
I first try with convert only one xyz file. Code is like:
import os
from osgeo import gdal,osr
xyz = '1x1m_678494.xyz'
xyzraster = '1x1m_678494.tif'
translateoptions = gdal.TranslateOptions(projWin='EPSG:3879')
gdal.Translate(xyzraster,xyz,options=translateoptions)
the result is i can get a tif file, but without spatial reference. And there was no error or warning message. Then i thought it might relate to the gdal package. i found some similar issues here https://gis.stackexchange.com/questions/142215/gdal-translate-projection-errorhttps://github.com/conda/conda/issues/4050,I did set the GDAL_DATA to the path 'C:\Program Files\Anaconda3\Library\share\gdal'. This didn't solve my problem. checked my gdal version is 2.3.3 with python 3.7.3. I am trying to remove this gdal and install the newest version gdal 3.0.4 using conda. But there seems to be a incompatible issue.
In the same time, i found there is also independent install for GDAL, http://cartometric.com/blog/2011/10/17/install-gdal-on-windows/. This tutorial has one step to set the GDAL_DATA and GDAL_DRIVER_PATH, but the paths are different from the GDAL_DATA installed by conda. I am very confused. Will the independent installed gdal works different from the conda installed gdal? Or i just need one of them?
Then i leave the spatial reference issue behind, and tried convert multiple xyz to a geotiff. But got some other issues. code is like:
import os
import gdal
import glob
path = 'D:\\Data\\1m\\'
gdal.BuildVRT(path+'out.vrt',glob.glob(path+'\\*.xyz'))
gdal.Translate(path+'out.tif',path+'out.vrt')
The error is ValueError: Received a NULL pointer.
Can anyone help me out, please?
** gdal.TranslateOptions(projWin=(zip(ulx,uly,lrx,lry)),projWinSRS='EPSG:3879')
Is where the first part went wrong.
Related
Working with R in Python using rpy2 on windows 7.
I need to open some rasters as RasterLayer using the function raster() from the raster package. I manage to install the package, but not to use its function.
I install the packages that I need (rgdal, sp, raster, lidR, io) using
utils.install_packages(StrVector(names_to_install))
names_to_install is a list of the packages that are still not installed. This works fine.
I know how to try the "basic" functions, like sum, and it works:
import rpy2.robjects as robjects
function_sum = robjects.r['sum']
But the same doesn't seem to work with the raster function from the raster package:
function_raster = robjects.r['raster']
since I get the error:
LookupError: 'raster' not found
I also tried the following:
raster_package = importr('raster')
with the intention to be able to run the next and load my raster file:
raster_package.raster(my_raster_file)
but the first line (import('raster')) causes the crash of python and I get the error:
Process finished with exit code -1073741819 (0xC0000005)
This doesn't happen with other loaded packages like rgdal, but with the raster package and with the lidR package I get the error.
I looked up this error, seems to be access violation, but I don't know what I can do about it and why it only happens with certain packages.
I expect to be able to call the raster function from the package raster.
Edit
I tried it on a computer with windows 10 and the error doesn't show anymore when running
raster_package = importr('raster')
Still would be nice to know what is the problem with Windows 7 and if there is any solution.
rpy2 does not currently have Windows support. This is not a final situation, most of what is likely needed is contributions to finalize this: https://github.com/rpy2/rpy2/blob/master/rpy2/rinterface_lib/embedded_mswin.py
I am trying to learn the linearmodels package for python.
I want to do this by practicing with the data sets, as can be seen here.
Example code:
import numpy as np
from linearmodels.iv import IV2SLS
from linearmodels.datasets import mroz
data = mroz.load()
But my code breaks when i run data = mroz.load()
error message:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\...\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\linearmodels\\datasets\\mroz\\mroz.csv.bz2'
I have pip version: 19.1.1
Conda can't find the package at all
and i have the latest version of linearmodels package: 4.13
The folder specified in the error message i can find, i.e. datasets\mroz but not the csv.bz2 file.
The same holds for every other data set i try to open.
Why am i not able to open the datasets?
let me know if you need additional information.
This is a bug in the package. If you download and unpack the source distribution you would find it lacks all *.csv.bz2.
I see two problems in the package. First, MANIFEST.in lists *.csv.bz. It must be *.csv.bz2 or *.csv.bz*.
Second, they tried to add the datasets in setup.py but also failed, not sure why. Perhaps the files must be declared as belonged to different subpackages, not to the main package.
Please report the bugs to the issue tracker.
I have installed spacepy using the following command (MacOS Mojave):
pip install git+https://github.com/spacepy/spacepy.git
But I keep getting this error while trying to from spacepy import pycdf:
Exception: Cannot load CDF C library; checked . Try 'os.environ["CDF_LIB"] = library_directory' before import.
I have tried following the directions from their website, but it seems like those directions are a bit outdated.
You can do something like:
import os
os.environ["CDF_LIB"] = "~/CDF/lib" # Give the path of the cdf library
# e.g. in this case the library is in your home directory.
Before doing:
from spacepy import pycdf
Source of the error can be found on this SpacePy website.
The cdf library is available here.
Basically, you need to set up the CDF_LIB (if pycdf has a trouble finding it) before importing the module. You can read the documentation here.
trying to import scipy.interpolate but it can’t import _fblas.pyd. It keeps throwing the following error
File "C:\cygwin64\lib\python2.7\site-packages\scipy/linalg/blas.py", line 155, in <module>
from scipy.linalg import _fblas
ImportError: cannot import name _fblas
My online research suggested that this is because I had the wrong version of numpy installed, and I need to install numpy+mkl. So I uninstalled the version I had and pip installed numpy 1.10.4, which includes mkl.
This did not fix the original problem with _flbas.pyd.
I would reinstall scipy but I can't remember where I got the version I have, and when I pip install scipy 0.17.1.tar.gz it throws an error saying that it has no blas resources, which are necessary. I've also tried to download it from here: https://github.com/scipy/scipy/releases, but they don't include _fblas.pyd in the first place.
I’m not sure where to go from here. I'm not even entirely sure why it won't import the _fblas.pyd file.
This looks like you tried to manually comply to your needed packages. Even though I take my hat off at your effort, keep in mind that this is not an simple task at all.
I might also add that this kind of work is not meant for a developer ("the person who writes the code"), but a full time maintainer. Specially with your particular Cygwin environment
So, what can you do? Alternatively, you can use one of Continuum's mkl-ready python-and-many-tools-including-mkl+scipy distribution or Enthought's Canopy. Hopefully, this will avoid you lots of hours of staring at the screen wondering what's wrong
so I'm on a Windows 8 and I'm doing some image analysis for my research. It requires running this python script (I did not write it) called "calculate_distances.py". I am also using CellTool (http://pantheon.yale.edu/~zp2/Celltool/) and Numpy which I have successfully installed.
When I try to run my calculate_distances script, I get this error:
Traceback (most recent call last):
file "calculate_distances.py" line 4, in <module>
import celltool.simple_interface as si
ImportError: No module named celltool.simple_interface
Here is my calculate_distances.py script:
#!/Library/Frameworks/Python.framework/Versions/2.5/bin/python
# Import various celltool modules
import celltool.simple_interface as si
import celltool.contour.contour_class as contour_class
from celltool.utility.path import path
import celltool.utility.datafile as datafile
import numpy
# Designate your working directory - ie, replace '/parent_directory/' with the path that contains your contour files
#parent_dir=path('/parent_directory/')
parent_dir=path('./')
# Identify and load all of the contour files
contour_files=parent_dir.files('*.contour')
contours=si.load_contours(contour_files)
all_distances=numpy.arange(len(contours[0].points))
# Calculate the normal displacement of the cell boundary at every contour point.
n=1
while n<len(contours):
contour_class.Contour.global_reorder_points(contours[n],contours[n-1])
displacement_vectors = contours[n-1].points - contours[n].points
normals = contours[n-1].inward_normals()
distances = (normals * displacement_vectors).sum(axis=1)
all_distances=numpy.vstack((all_distances,distances))
n=n+1
# Save a csv file with the normal displacement of the boundary at each contour point (columns) at each time point (rows)
datafile.write_data_file(all_distances,parent_dir/'distances.csv')
I have no idea what the error means, as I'm a first-time programmer. First I thought I needed to install a C++/fortran compiler, so I installed Simple Fortran, but it still does not work. Everything works fine on Mac system (after I installed GNU fortran) but for some reason it's not working on Windows. Is it because my CellTool is not installed in the right location? Or is it something with the script?
Any ideas? Thanks very much for your help!!
You have two options then.
Try adding CellTool installation directory to your PYTHONPATH environment variable, if you haven't already (create this variable if necessary).
Search for something like celltool.dll or libcelltool.dll (or even celltool.py). See if it helps. If not :
Compile the source by following those few steps... Install MinGW (installer here), checking C/C++ (gcc/g++) and Fortran when asked by the installer. Then add C:/MinGW/bin (or whereever you installed MinGW) to your PATH environment variable. Download and unpack CellTool source package from the web site. Finally open a command shell (search for cmd program), change directory to the newly unpacked directory and build by typing :
python setup.py install
This should properly compile and install the celltool python package to the site-packages directory of your Python installation.
Option 2 is the sure/safe (but not easiest, I agree) way to get it work.