Oh too bad. Sure would be nice to have a function we can use to set those environments (and set them back). This would allow you to directly access gdal tools from within ArcGIS script tools. That's what I really want. We geonet-istas should definitely share such an animal if we come up with it. Steve Lynch could you pass this idea around the smoke (well,maybe chai-steam) -filled room in Redlands? Being able to easily run gdal tools would a great option for certain raster operations that are slower or aren't easily done in arcpy-raster land. This may be just an implementation issue - just show us how to do it - no work on your part beyond that.
Hi Curtis Price,
Yes and no and sort of.
I keep a separate Conda env for GDAL stuff and (conda create -n some_new_env -c conda-forge python=3.5 gdal) and keep my ArcGIS Pro env pristine (well pristine so far... )
I had some trouble with the old version of conda that ships with ArcGIS Pro 1.3 as it wouldn't run the GDAL pre and post activation batch files (that set and restore some environment vars). So I upgraded conda, broke ArcGIS Pro completely and had to reinstall... I then ended up installing a separate updated conda to muck around with and leaving ArcGIS Pro completely alone.
Hi Luke. Today I tried ArcGIS Pro's Conda setup to do this:
conda install Python=3.4.4 gdal
and it seemed to work, the python gdal tools seemed to all be there. Have tried this new approach?
Kludgy workaround no longer required (tested on ArcGIS 10.2.2). This simple script works fine as a script tool run multiple times in-process from a binary (tbx) toolbox:
import arcpy from osgeo import gdal path = r'/path/to/some/raster' ds = gdal.Open(path) ras = arcpy.Raster(path) arr = ds.ReadAsArray() arcpy.AddMessage(repr(arr)) arr = ds.GetRasterBand(1).ReadAsArray() arcpy.AddMessage(repr(arr)) arr = arcpy.RasterToNumPyArray(path) arcpy.AddMessage(repr(arr))
Curtis, I would think so, but haven't specifically tested. I haven't had any issues with a number of python toolboxes I've written that use gdal. If I get a chance, I'll test.
Luke, now in 10x/Pro we have RasterToNumpyArray - does that provide a method to get our rasters from the numpy array to gdal in-process without the kludgy workaround detailed here?
import osgeo import gdal from osgeo import ogr
import ogr2ogr import ogrinfo
string=str("ogr2ogr -f"+ ' "KML"'+" "+ 'throwthisaway.kml'+" "+'test.dgn')
cmd=["ogr2ogr", "-f", "KML", "throwthisaway.kml", "test.dgn"]
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,stderr=subprocess.PIPE) stdout,stderr=proc.communicate() exit_code=proc.wait() if exit_code: print stderr else: print stdout
import arcpy from subprocess import call Input = arcpy.GetParameterAsText(0) Output = arcpy.GetParameterAsText(1) OutType = arcpy.GetParameterAsText(2) String = "gdal_translate -of " + OutType + " " + Input + " " + Output call(String)
import arcpy from subprocess import call InputFolder = arcpy.GetParameterAsText(0) InType = arcpy.GetParameterAsText(1) OutputFolder = arcpy.GetParameterAsText(2) VRTName = arcpy.GetParameterAsText(3) String = "gdalbuildvrt " + OutputFolder + "\\" + VRTName + ".vrt " + InputFolder + "\\*." + InType call(String)
import arcpy from osgeo import gdal inputPath = arcpy.GetParamaterAsText(0) inputRaster = gdal.Open(inputPath) # do operations, etc., etc., etc.
サインインしたメンバーは投稿、更新のフォローなどができます。初めてですか?無料アカウントを登録してください。
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.