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

function toRaster() #28

Closed
wants to merge 42 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
8fcb608
WIP
nyalldawson Sep 22, 2022
ddf5ff0
Vendor rinside
nyalldawson Sep 22, 2022
a8c9480
Dock widget
nyalldawson Sep 22, 2022
e5195c1
Fix object name
nyalldawson Sep 22, 2022
4b74cae
Inject some functions
nyalldawson Sep 22, 2022
8da8f8f
Monospace font
nyalldawson Sep 22, 2022
f7ca9b0
Cmake cleanup
nyalldawson Sep 23, 2022
cf53d5b
Fix linking to RCpp
nyalldawson Sep 23, 2022
0677583
Run R session in a background thread to avoid blocking ui
nyalldawson Sep 24, 2022
f54f18b
Don't accept new commands while session is busy
nyalldawson Sep 24, 2022
64748f9
Fix error handling
nyalldawson Sep 24, 2022
5cc6696
Fix result handling
nyalldawson Sep 24, 2022
10fb9ca
add functions to convert from SEXP to std::string
JanCaha Oct 4, 2022
34366aa
when command is evaluated, send result to console, formatted by R
JanCaha Oct 4, 2022
fc83c20
only return value if there is 1, otherwise return nothing for now
JanCaha Oct 4, 2022
eb36576
on command finished, do not add string to output, it is handled elsew…
JanCaha Oct 4, 2022
ed8a71a
Add QgsCodeEditorR code editor subclass for R scripts
nyalldawson Oct 3, 2022
d68f6f8
Remove unused code
nyalldawson Oct 4, 2022
53a2d6b
Formatting
nyalldawson Oct 4, 2022
e62d37c
Use R code editor
nyalldawson Oct 4, 2022
421f95e
Minor cleanup and add no-return execCommand method
nyalldawson Oct 4, 2022
22ea294
Cleanup error handling and some crash fixes
nyalldawson Oct 5, 2022
e07b433
Code shuffle
nyalldawson Oct 5, 2022
d9da2fb
Show startup message
nyalldawson Oct 5, 2022
3f84fd7
Nicer ui
nyalldawson Oct 5, 2022
421b9e0
Move some common code to base class
nyalldawson Oct 5, 2022
732fc19
functions to get data from QGIS to R
JanCaha Oct 6, 2022
e24063b
Setup test framework
nyalldawson Oct 6, 2022
a407190
Handle list values during conversion, add tests
nyalldawson Oct 7, 2022
28235a5
Add variant to SEXP methods
nyalldawson Oct 7, 2022
423074d
Support cancelation in QgsScopedProxyProgressTask
nyalldawson Oct 7, 2022
1fd1ab7
Fix some crashes
nyalldawson Oct 7, 2022
3665168
Lots of stuff!
nyalldawson Oct 7, 2022
33b4f70
Minor optimisations
nyalldawson Oct 8, 2022
7850f7b
[ogr] Optimise attribute population during feature iteration
nyalldawson Oct 8, 2022
766ee50
Add "selectedOnly" argument to QGIS$toDataFrame
nyalldawson Oct 8, 2022
96017ba
Scroll to end of output automatically
nyalldawson Oct 8, 2022
b32e3aa
Cleanups
nyalldawson Oct 8, 2022
0e350cd
Adapt activeLayerNumericField and readActiveLayerToSF to generic thre…
nyalldawson Oct 8, 2022
f152959
Fix some crashes
nyalldawson Oct 10, 2022
d8f422d
Fix initialization
nyalldawson Oct 10, 2022
7091976
function toRaster()
JanCaha Oct 11, 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