Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add function to load raster from QGIS layer #30

Open
wants to merge 45 commits into
base: r_console
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
4c23236
WIP
nyalldawson Sep 22, 2022
b7c51e3
Vendor rinside
nyalldawson Sep 22, 2022
af144cc
Dock widget
nyalldawson Sep 22, 2022
b18df10
Fix object name
nyalldawson Sep 22, 2022
4a1235f
Inject some functions
nyalldawson Sep 22, 2022
87582b8
Monospace font
nyalldawson Sep 22, 2022
151bac7
Cmake cleanup
nyalldawson Sep 23, 2022
273fc87
Fix linking to RCpp
nyalldawson Sep 23, 2022
8968f44
Run R session in a background thread to avoid blocking ui
nyalldawson Sep 24, 2022
2aa294b
Don't accept new commands while session is busy
nyalldawson Sep 24, 2022
e6ec0b2
Fix error handling
nyalldawson Sep 24, 2022
9225332
Fix result handling
nyalldawson Sep 24, 2022
620d21a
add functions to convert from SEXP to std::string
JanCaha Oct 4, 2022
f3c7d45
when command is evaluated, send result to console, formatted by R
JanCaha Oct 4, 2022
d3b6c7d
only return value if there is 1, otherwise return nothing for now
JanCaha Oct 4, 2022
b8c9065
on command finished, do not add string to output, it is handled elsew…
JanCaha Oct 4, 2022
badf5d7
Add QgsCodeEditorR code editor subclass for R scripts
nyalldawson Oct 3, 2022
7341745
Remove unused code
nyalldawson Oct 4, 2022
6b57684
Formatting
nyalldawson Oct 4, 2022
d351050
Use R code editor
nyalldawson Oct 4, 2022
da78775
Minor cleanup and add no-return execCommand method
nyalldawson Oct 4, 2022
cbaf456
Cleanup error handling and some crash fixes
nyalldawson Oct 5, 2022
72ad628
Code shuffle
nyalldawson Oct 5, 2022
6d20f53
Show startup message
nyalldawson Oct 5, 2022
ddb4de5
Nicer ui
nyalldawson Oct 5, 2022
203d2cd
Move some common code to base class
nyalldawson Oct 5, 2022
e5f9f12
functions to get data from QGIS to R
JanCaha Oct 6, 2022
4f68404
Setup test framework
nyalldawson Oct 6, 2022
1bba99d
Handle list values during conversion, add tests
nyalldawson Oct 7, 2022
7a6bbff
Add variant to SEXP methods
nyalldawson Oct 7, 2022
b88d154
Support cancelation in QgsScopedProxyProgressTask
nyalldawson Oct 7, 2022
de6155a
Fix some crashes
nyalldawson Oct 7, 2022
405491a
Lots of stuff!
nyalldawson Oct 7, 2022
bb07da8
Minor optimisations
nyalldawson Oct 8, 2022
9671958
[ogr] Optimise attribute population during feature iteration
nyalldawson Oct 8, 2022
590d32c
Add "selectedOnly" argument to QGIS$toDataFrame
nyalldawson Oct 8, 2022
00b05ca
Scroll to end of output automatically
nyalldawson Oct 8, 2022
197c815
Cleanups
nyalldawson Oct 8, 2022
b0c9943
Adapt activeLayerNumericField and readActiveLayerToSF to generic thre…
nyalldawson Oct 8, 2022
fed803e
Fix some crashes
nyalldawson Oct 10, 2022
7706efa
Fix initialization
nyalldawson Oct 10, 2022
4c34723
Add a script language enum
nyalldawson Oct 12, 2022
60002cb
Move python console history handling to base QgsCodeEditor class
nyalldawson Oct 11, 2022
bceeda4
extend MapLayerWrapper with functions
JanCaha Oct 13, 2022
4074427
add conversions to terra and stars
JanCaha Oct 17, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,21 @@ if(WITH_CORE)
endif()
endif()

set (WITH_R FALSE CACHE BOOL "Determines whether the inbuilt R integration should be built")
if(WITH_R)
find_package(R)
if (NOT ${R_FOUND})
message(FATAL_ERROR "R library not found")
endif()

find_package(RCpp)
if (NOT ${RCpp_FOUND})
message(FATAL_ERROR "Rcpp library not found")
endif()

set(HAVE_R TRUE) # used in qgisconfig.h
endif()

# server disabled default because it needs FastCGI (which is optional dependency)
set (WITH_SERVER FALSE CACHE BOOL "Determines whether QGIS server should be built")
if(WITH_SERVER)
Expand Down
40 changes: 40 additions & 0 deletions cmake/FindR.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# CMake module to search for R
#
# Once done this will define
#
# R_FOUND - system has the R library
# R_INCLUDE_DIR - the R library include directories
# R_LIB - the R library
#
# Copyright (c) 2022, Nyall Dawson, <nyall dot dawson at gmail dot com>
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.

execute_process(COMMAND R CMD config --cppflags OUTPUT_VARIABLE R_INCLUDE_DIR_TMP)
string(REGEX REPLACE "^-I" "" R_INCLUDE_DIR_TMP "${R_INCLUDE_DIR_TMP}")
string(STRIP ${R_INCLUDE_DIR_TMP} R_INCLUDE_DIR_TMP)
set(R_INCLUDE_DIR "${R_INCLUDE_DIR_TMP}" CACHE STRING INTERNAL)

#message(STATUS "Found R include dirs: ${R_INCLUDE_DIR}")

execute_process(COMMAND R CMD config --ldflags OUTPUT_VARIABLE R_LDFLAGS)
if (${R_LDFLAGS} MATCHES "[-][L]([^ ;])+")
string(SUBSTRING ${CMAKE_MATCH_0} 2 -1 R_LIB_DIR)
string(STRIP ${R_LIB_DIR} R_LIB_DIR)
find_library(R_LIB
NAMES libR.so PATHS
"${R_LIB_DIR}"
)
endif()

INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(R DEFAULT_MSG
R_LIB R_INCLUDE_DIR)

if(R_FOUND)
message(STATUS "Found R library: ${R_LIB}")
endif()

mark_as_advanced(R_INCLUDE_DIR)
mark_as_advanced(R_LIB)
39 changes: 39 additions & 0 deletions cmake/FindRCpp.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# CMake module to search for RCpp
#
# Once done this will define
#
# RCpp_FOUND - system has the RCpp library
# RCpp_INCLUDE_DIR - the RCpp library include directories
# RCpp_LIB - the RCpp library
#
# Copyright (c) 2022, Nyall Dawson, <nyall dot dawson at gmail dot com>
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.

execute_process(COMMAND Rscript -e "Rcpp:::CxxFlags()"
OUTPUT_VARIABLE RCpp_INCLUDE_DIR_TMP)
string(REGEX REPLACE "^-I" "" RCpp_INCLUDE_DIR_TMP "${RCpp_INCLUDE_DIR_TMP}")
string(STRIP ${RCpp_INCLUDE_DIR_TMP} RCpp_INCLUDE_DIR_TMP )
string(REGEX REPLACE "^\"" "" RCpp_INCLUDE_DIR_TMP "${RCpp_INCLUDE_DIR_TMP}")
string(REGEX REPLACE "\"$" "" RCpp_INCLUDE_DIR_TMP "${RCpp_INCLUDE_DIR_TMP}")
set(RCpp_INCLUDE_DIR "${RCpp_INCLUDE_DIR_TMP}" CACHE STRING INTERNAL)

find_library(RCpp_LIB
NAMES Rcpp.so PATHS
"${RCpp_INCLUDE_DIR}/../libs"
)

INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(RCpp DEFAULT_MSG
RCpp_LIB RCpp_INCLUDE_DIR)

if(RCpp_FOUND)
message(STATUS "Found Rcpp library: ${RCpp_LIB}")
endif()

add_library(Rcpp UNKNOWN IMPORTED)
set_property(TARGET Rcpp PROPERTY IMPORTED_LOCATION "${RCpp_LIB}")

mark_as_advanced(RCpp_INCLUDE_DIR)
mark_as_advanced(RCpp_LIB)
2 changes: 2 additions & 0 deletions cmake_templates/qgsconfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,7 @@

#cmakedefine HAVE_CRASH_HANDLER

#cmakedefine HAVE_R

#endif

62 changes: 62 additions & 0 deletions external/r_inside/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
## RInside: Easy embedding of R inside C++ (and C)

[![CI](https://github.com/eddelbuettel/rinside/workflows/ci/badge.svg)](https://github.com/eddelbuettel/rinside/actions?query=workflow%3Aci)
[![License](http://img.shields.io/badge/license-GPL%20%28%3E=%202%29-brightgreen.svg?style=flat)](http://www.gnu.org/licenses/gpl-2.0.html)
[![CRAN](http://www.r-pkg.org/badges/version/RInside)](https://cran.r-project.org/package=RInside)
[![Dependencies](https://tinyverse.netlify.com/badge/RInside)](https://cran.r-project.org/package=RInside)
[![Debian package](https://img.shields.io/debian/v/r-cran-rinside/sid?color=brightgreen)](https://packages.debian.org/sid/r-cran-rinside)
[![Downloads](http://cranlogs.r-pkg.org/badges/RInside?color=brightgreen)](https://cran.r-project.org/package=RInside)
[![Last Commit](https://img.shields.io/github/last-commit/eddelbuettel/rinside)](https://github.com/eddelbuettel/rinside)

### About

The RInside package provides a few classes for seamless embedding of [R](https://www.r-project.org) inside of
C++ applications by relying on [Rcpp](https://www.rcpp.org/).

### Examples

Provided with the package itself are nine subdirectories with examples: from more than a dozen basic command-line examples (in directory
`standard`) to graphical user-interfaces (using both [Qt](https://www.qt.io/) and [Wt](https://www.webtoolkit.eu/wt)), linear algebra with
[Armadillo](http://arma.sourceforge.net/) and [Eigen](http://eigen.tuxfamily.org/index.php?title=Main_Page), parallel computing with MPI to a
sandboxed server, and (since release 0.2.16) a simple (and more limited) interface for embedding insice C applications.

The simplest example (modulo its header) is [examples/standard/rinside_sample0.cpp](inst/examples/standard/rinside_sample0.cpp)

```c++
#include <RInside.h> // for the embedded R via RInside

int main(int argc, char *argv[]) {

RInside R(argc, argv); // create an embedded R instance

R["txt"] = "Hello, world!\n"; // assign a char* (string) to 'txt'

R.parseEvalQ("cat(txt)"); // eval the init string, ignoring any returns

exit(0);
}
```
The [Qt example directory](https://github.com/eddelbuettel/rinside/tree/master/inst/examples/qt) produces
this application for showing how to use R (to estimate densities) inside a C++ executable (providing the GUI):

![](https://github.com/eddelbuettel/rinside/blob/master/local/qtdensitySVG.png)

The code is portable across operating systems. Similar, the
[Wt example directory](https://github.com/eddelbuettel/rinside/tree/master/inst/examples/wt)
contains this C++-based web application doing the same:

![](https://github.com/eddelbuettel/rinside/blob/master/local/wtdensity.png)


### See Also

The [RInside](http://dirk.eddelbuettel.com/code/rinside.html) web page has
some more details.

### Authors

Dirk Eddelbuettel, Romain Francois, and Lance Bachmeier

### License

GPL (>= 2)
Loading