Skip to content
This repository has been archived by the owner on Apr 20, 2020. It is now read-only.

failure on qgis:intersection call #72

Closed
jamgreen opened this issue Jun 24, 2017 · 3 comments
Closed

failure on qgis:intersection call #72

jamgreen opened this issue Jun 24, 2017 · 3 comments

Comments

@jamgreen
Copy link

I'm attempting to intersect census block groups with a city polygon layer using the intersection algo.

The call fails due to the inability to create a raster file.


find_algorithms(search_term = "intersection")
get_usage(alg = "qgis:intersection")

params <- get_args_man(alg = "qgis:intersection")

params$INPUT <- mult_cbg
params$INPUT2 <- pdx
params$OUTPUT <- "pdx_bg_2015.geojson"

out <- run_qgis(alg = "qgis:intersection",
                params = params,
                load_output = TRUE)```

The output error:

```$OUTPUT
[1] "C:\\Users\\elmue\\AppData\\Local\\Temp\\Rtmp0AW5LT/pdx_bg_2015.geojson"


Error in .local(.Object, ...) : 

Error in .rasterObjectFromFile(x, band = band, objecttype = "RasterLayer",  : 
  Cannot create a RasterLayer object from this file.```

Both input files are simple features from the census bureau and have the same projection. 
@jannes-m
Copy link
Collaborator

Can you provide a reproducible example, please? Secondly, I am not sure, if QGIS can save to geojson. But check it out by setting load_output to FALSE and look in the directory if the file was created, in your case tempdir(). Also try "pdx_bg_2015.shp" as output name, that should probably work.

@jamgreen
Copy link
Author

It was the JSON issue. I mistakenly believed because QGIS can read it that it could also export. If you would prefer a reproducible example still, then I can provide one, but the issue is resolved on my end.

@jannes-m
Copy link
Collaborator

Well, you are right that QGIS supports geojson as pointed out here. Therefore, RQGIS should support this, too. Accordingly, I have changed run_qgis in commit 0ba5e14. So now you can also use run_qgis to load geojson-files (and other GDAL-supported drivers depending on your system set up).

library("sp")
library("raster")
coords_1 <- matrix(data = c(0, 0, 1, 0, 1, 1, 0, 1, 0, 0),
                              ncol = 2, byrow = TRUE)
coords_2 <- coords_1 + 2
# convert the coordinates into polygons
polys <- list(Polygons(list(Polygon(coords_1)), 1), 
                    Polygons(list(Polygon(coords_2)), 2)) 
polys <- as(SpatialPolygons(polys), "SpatialPolygonsDataFrame")
alg <- "qgis:polygoncentroids"
params <- get_args_man(alg)
params$INPUT_LAYER <- polys
params$OUTPUT_LAYER <- file.path(tempdir(), "coords.geojson")
out <- run_qgis(alg, params = params, load_output = TRUE)

Thanks for the heads-up!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants