I'm attempting to use the magick R package to do some image editing. However, I am unable to read in GeoTIFF files. When I try this:
magick::image_read(RGBFile)
I get the following error message:
Error in magick_image_readpath(path, density, depth, strip) :
Magick: Unknown field with tag 34737 (0x87b1) encountered.
`TIFFReadDirectory' # warning/tiff.c/TIFFWarnings/912
After doing some research, I've concluded that the GeoTIFF tags are the issue.
I've written to the package maintainer to see if an update to the package might allow GeoTIFFs to be read, but in the meantime, is anyone aware of a way of an way of removing GeoTIFF tags without re-copying the entire file? (Or any other efficient workaround for dealing with large >1 GB images)
Thanks!
I have contacted the package maintainer and this bug has been fixed! It hasn't made it onto CRAN as of this posting but in the meantime installing magick with devtools::install_github("ropensci/magick") should do the trick.
Related
I have a 5.1 GB json file that I would like to read in R using rjson. I want afterwards to construct a dataframe from it, however it won't load because the size is too large.
Is there any way to work around it?
Thank you for your help =)
Nina, I would recommend you using jsonlite package instead of rjson.
library(jsonlite)
your_json <- "your_path.json"
unpacked_json <- jsonlite::stream_in(textConnection(readLines(your_json, n=100000)),verbose=F)
Here you limit the page size to let IDE correctly read your JSON file. For more information I would also recommend you to make some research on this topic:
https://community.rstudio.com/t/how-to-read-large-json-file-in-r/13486
Reading a huge json file in R , issues
I know for sure that it is sometimes really hard to cope with documentation (and as all other human beings we are lazy); and I don't like to read doc-n myself, but I highly recommend you to make yourself familiar with jsonlite documentation and vignettes. Here's the CRAN link: https://cran.r-project.org/web/packages/jsonlite/index.html
I am trying to convert this example pdf to png using the animation package the same way it´s done here Convert pdf to png in R
library("animation")
ani.options(outdir = "//Usuarios/Facturas")
pdf("Factura.pdf")
plot(1:10)
dev.off()
im.convert("Factura.pdf",
output = "Factura.png")
But I have this error:
Same error than here: Error using magick R to import PDF but that solution makes reference to an external software that I don´t find in the original post (and I haven´t installed). I red that Ghostscript do what I want (pdf to png), but isn´t what animation package suppose to do?
Or I messed up my brain?
Thanks
The animation package uses ImageMagick for some of its features (which is why ImageMagick is listed as a system requirement in the manual). ImageMagick in turn apparently uses Ghostscript for PDF rendering. So yeah: the Ghostscript issues discussed here are certainly worth looking into.
Finally I found the answer with another package, I am gonna explain if someone need it.
library(pdftools)
library(magick)
fichero="Factura.pdf"
png= pdftools::pdf_convert(fichero, dpi = 600)
# And if someone want to read it
png2 = image_read(png)
This doesn´t save any file .png, which is a perfect solution for my situation.
I have hundreds of PDFs that I want to crop. For each PDF, I have a unique set of coordinates around which to crop. I am trying to use the R's magick package (version ImageMagick 6.9.9.14), but I receive an error when importing a PDF.
This example from the magick documentation throws an error:
library(magick)
manual <- image_read('https://cran.r-project.org/web/packages/magick/magick.pdf', density = "72x72")
The error I receive is "Error in magick_image_readpath(path, density, depth, strip) : Magick: PDFDelegateFailed `The system cannot find the file specified.
' # error/pdf.c/ReadPDFImage/809"
When I check the config settings:
magick_config
I find that ghostscript is true. I am not sure if there are other settings required for reading in a PDF.
Has anyone else encountered a similar problem with magick? I am open to alternative packages with the ability to crop PDFs, if there are any.
I had the same problem on Windows. It was no R problem. In my case, I used ImageMagick 64-bit but had GhostScript 32-bit installed. After installing the 64-bit version of GhostScript it worked without any issues.
You could use tabulizer package.
library(tabulizer)
manual_url <- "https://cran.r-project.org/web/packages/magick/magick.pdf"
manual <- extract_text(manual_url)
For installing tabulizer follow exactly these steps.
I receive this message when I try to install "XLConnect" in R. I am trying to use some data from excel, and I don't know how else to load it into the program.
I'm completely new to R and programming, so any help is greatly appreciated!
This usually happens when there is a typo in the package name. The code below should work. My guess is that the capitalization might have been off when you tried it?
install.packages("XLConnect")
I'm reasonably sure that you had spaces on either side of term "XLConnect". At least that is what your error message is telling us. If trying what Mallick suggested does not succeed, then [edit] to include exact copies of any error message in the body of the question.
Other ways to transfer data from Excel to R include copying to the Clipboard or exporting as a '.csv' file. There must be hundreds of questions and answers about the Excel - to - R Highway Eternal Resurfacing Project. One more recent addition is the readxl package (function is read_excel) and that choice doesn't have the Java version dependencies that cause trouble for some XLConnect useRs.
I am new to R and was following the following tutorial on the ggplot2 package found here. However the readShapePoly() function throws an error whenever I try to load the basic shapefile. I have used the following code:
library("ggplot2")
library("gpclib")
library("maptools")
setwd("~/Documents/R Projects/Intro to ggplot2")
#Intro to ggplot 2 contains the .shp file and associated data
sport <- readShapePoly("london_sport.shp")
which gets me:
Error in getinfo.shape(filen) : Error opening SHP file
I have tried omitting the file extension. I have also tried downloading other .shp files which throw the same error too. I have also tried calling readShapePoly using the full file path, which doesn't work either. I am using R studio (mac OSX), but I get the same error using the standard R window. I have tried the suggestions on the previous closed threat "Error opening SHP file in Rstudio", but to no avail.
Edit: the error was with a missing .dbf file. Thanks to #Spacedman for the fix.
I had a similar issue, and it was because there were several other files along with the '*.shp' shape file in the zip package that I downloaded. Then I only moved the shape file to another folder and it didn't work. When including all files together, it was fine and I could readShapeSpatial() function okay.
Forget ggplot and gpcclib. Stick to maptools and rgdal that actually provide tools for reading a shapefile.
Don't just say you've tried "this and that", outline the details. For example, does `file.exists("london_sport.shp") return TRUE?
Also, what makes you think readShapePoly() is the right function? It only knows how to read polygon shapefiles, try readShapePoints() and readShapeLines() as well.
If you can, try readOGR which can read a shapefile despite many caveats (including the geometry type).
library(rgdal)
readOGR("~/Documents/R Projects/Intro to ggplot2", "london_sport")
If you can report on all of those things it's likely someone could help.
There is one more, but not much automatic solution which helped me:
file<- readShapePoly(file.choose())
Then just find your *.shp file and run it.
Include three of those files (extensions: dbf, shp, shx) in the same folder.
In case this helps anyone:
I had the same problem but none of the solutions worked. Worst, I the same was going on with an script that I'm 100% sure was working previously.
Turns out that it could also be that the shapefile gets damaged. Apparently this can happen while the file is being manipulated (or so that say my geographer friends), so next time you try to open it won't work for no apparent reason. Downloading it again worked fine, but makes me think to have a copy of the more precious ones just in case.
I just managed to fix this problem with a shapefile I was trying to read by typing:
file<- readShapeSpatial("filename.shp")
instead of typing in the full file path.
Before then, I tried all the suggestions, including making sure that the .dbf and .shx files were also present. Don't know why this should be the case.
I had the same problem. I found out that basically you need three of those files: .shp, .shx and .dbf