I am trying to convert a raster object to a polygon object using R but I am running into some problems using my Windows 7 machine.
I originally tried to use
rasterToPolygons (package: raster) but it kept crashing my computer so I opted to use the R port of
gdal_polygonize with directions found here
However, I cannot get this to work because I receive the error message:
ImportError: No module named site Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv) : Cannot open file In addition: Warning message: running command '"python" "C:/OSGeo4W64" "C:\Users\RDCERWAW\AppData\Local\Temp\1\RtmpGgkaqN\file1ddc84b56b5.asc" -f "ESRI Shapefile" "C:\Users\RDCERWAW\AppData\Local\Temp\1\RtmpGgkaqN\file1ddcbde726a.shp"' had status 1
The problem seems to be with the
system2() call. When I try to use it to call Python, I get the error
ImportError: No module named site Warning message: running command '"python" print hello' had status 1
(The above is probably incorrect, but I can't find out how to test the call to python using R)
Gdal is installed at
C:/OSGeo4W64 and the Path to both
gdal_polygonize and Python are in my PATH. I can run
gdal_polygonize from the console by typing
gdal_polygonize C:\GIS\temp.tif if 'ESRI Shapefile' C:\GIS\temp.shp
I ran the gdal_polygonizeR() function line by line and found out there were two problems. First, the raster that I was using as input had been created by cropping another raster and so the data source was a temporary file that no longer existed.
Secondly, the call to the directory for python (C:\OSGeo4W64\bin) was not able to import gdal, so I had to install gdal separately from the OSGeo4W installation (not sure why) and then I was able to import gdal from within OSGeo4W.