首先,我是编程的新手,所以这可能是一个简单的问题,但我无法在任何地方找到解决方案。
我一直在使用此代码从一组堆叠的栅格中提取值:
raster.files <- list.files()
raster.list <- list()
raster.files <-list.files(".",pattern ="asc")
for(i in 1: length(raster.files)){
raster.list[i] <- raster(raster.files[i])}
stacking <- stack(raster.list)
coord <- read.csv2("...")
extract.data <- extract(stacking,coord,method="simple")
到目前为止,我已经多次使用过此代码而没有任何问题。每次运行提取行时,都会出现此错误:
Error in .doCellFromXY(object@ncols, object@nrows, object@extent@xmin, :
Not compatible with requested type: [type=character; target=double].
coord文件包含一个包含2列(分别为X和Y)的data.frame。
答案 0 :(得分:0)
我设法找到了一种绕过这个错误的方法,它在技术上并不是一个解决方案,因为我无法理解为什么R在第一时间将我的数据视为文本。
基本上我将X和Y列分开并单独处理它们,然后再将它们绑定在一个新的data.frame中:
create or replace PACKAGE BODY gecm_t360_po_extraction_pk
ASPROCEDURE gecm_po_extraction_prc(
p_errbuf OUT VARCHAR2,
p_retcode OUT VARCHAR2,
p_from_date IN VARCHAR2,
p_to_date IN VARCHAR2 )
IS
TYPE g_po_outbond_feed_rec
IS
RECORD
(
po_number po_headers_all.segment1%TYPE,
vendor_number ap_suppliers.segment1%TYPE,
vendor_name ap_suppliers.vendor_name%TYPE,
vendor_site ap_supplier_sites_all.vendor_site_code%TYPE,
);
TYPE g_po_outbond_feed_table
IS
TABLE OF g_po_outbond_feed_rec;
g_po_outbond_feed_tbl g_po_outbond_feed_table;
--
v_legal_entity_name xle_entity_profiles.name%TYPE;
v_segment_val gl_code_combinations.segment1%TYPE;
v_req_distribution_id po_distributions_all.req_distribution_id%TYPE;
v_requisition_num po_requisition_headers_all.segment1%TYPE;
v_requestor_emp_num po_requisition_lines_all.to_person_id%TYPE;
v_requestor_sso_id per_all_people_f.employee_number%TYPE;
v_preparer_emp_num po_requisition_headers_all.preparer_id%TYPE;
v_preparer_sso_id per_all_people_f.employee_number%TYPE;
-- Start of changes as per v1.7
/*v_directory gecm_intf_param_tbl.parameter_value%TYPE;
v_file_name gecm_intf_param_tbl.parameter_value%TYPE; */
v_directory VARCHAR2(4000);
v_file_name VARCHAR2(4000);
-- End of changes as per v1.7
v_from_date DATE;
v_to_date DATE;
--
--Version 1.1 Code Changes Start
v_process_control_id NUMBER;
v_legal_entity_id NUMBER;
v_ledger_id NUMBER;
--Version 1.1 Code Changes End
v_filehandle UTL_FILE.FILE_TYPE;
p_record VARCHAR2(32000);
BEGIN
fnd_date.initialize('YYYY/MM/DD', 'YYYY/MM/DD HH24:MI:SS');
v_from_date := fnd_date.displayDT_to_date(p_from_date);
v_to_date := fnd_date.displayDT_to_date(p_to_date);
BEGIN
v_file_name := <getting file name>
EXCEPTION
WHEN OTHERS THEN
v_file_name:=NULL;
g_message := 'WHEN OTHERS: '||SQLERRM;
apps.fnd_file.put_line(apps.fnd_file.log,g_message);
p_retcode:=2;
END;
BEGIN
v_directory := <getting directory>
EXCEPTION
WHEN OTHERS THEN
v_directory:=NULL;
g_message := 'WHEN OTHERS: '||SQLERRM;
apps.fnd_file.put_line(apps.fnd_file.log,g_message);
p_retcode:=2;
END;
IF v_file_name IS NOT NULL AND v_directory IS NOT NULL THEN
--
BEGIN
SELECT * BULK COLLECT
INTO g_po_outbond_feed_tbl
FROM
(SELECT poha.segment1
AS po_number,
aps.segment1
AS vendor_number,
aps.vendor_name
AS vendor_name,
apss.vendor_site_code
AS vendor_site,
from
<tables>
--------------------------------
BEGIN
--
IF g_po_outbond_feed_tbl.COUNT < 1 THEN
g_message :='There is no POs to extract and file would not be
generated if there is no POs';
apps.fnd_file.put_line(apps.fnd_file.log,g_message);
ELSE
v_filehandle := UTL_FILE.FOPEN(v_directory, v_file_name, 'W',32767);
p_record:='PO_NUMBER|VENDOR_NUMBER|VENDOR_NAME|VENDOR_SITE|VENDOR_SITE_CODE';
UTL_FILE.PUT_LINE(v_filehandle, p_record);
FOR i IN g_po_outbond_feed_tbl.FIRST .. g_po_outbond_feed_tbl.LAST
LOOP
p_record:=NVL(g_po_outbond_feed_tbl(i).po_number,'');
p_record:=p_record||'|'||NVL(g_po_outbond_feed_tbl(i).vendor_number,'');
p_record:=p_record||'|'||NVL(g_po_outbond_feed_tbl(i).vendor_name,'');
p_record:=p_record||'|'||NVL(g_po_outbond_feed_tbl(i).vendor_site,'');
p_record:=p_record||'|'||NVL(g_po_outbond_feed_tbl(i).vendor_site_code,'');
UTL_FILE.PUT_LINE(v_filehandle, p_record);
END LOOP;
END IF;
这是最优雅的方式,但它只是有效。