简体   繁体   English

不存在简单的要素几何:返回表的 data.frame 或 tbl_df 问题

[英]No simple feature geometries present: returning a data.frame or tbl_df problem with a table

I hava a task for my college in which I need to transform coordinates from a table.我的大学有一项任务,我需要从表格中转换坐标。 So I had one table which had bad typed coordinates and the code worked and those coordinates got succesfully transformed.因此,我有一张坐标类型错误的表格,代码可以正常工作,并且这些坐标已成功转换。 A friend sent me a new table which had the right coordinates,but when I tried to transform it the R studio console got me this message: no simple feature geometries present: returning a data.frame or tbl_df一位朋友给我发了一张坐标正确的新表,但当我尝试对其进行转换时,R 工作室控制台给我这条消息:不存在简单的特征几何:返回 data.frame 或 tbl_df

I can't transform the data.frame or tbl.df with st.transform function我无法使用 st.transform function 转换 data.frame 或 tbl.df

The code for transformation:转换代码:

tabela1=st_read("table6.csv",
                  options=c("X_POSSIBLE_NAMES=Lon","Y_POSSIBLE_NAMES=Lat"),
                  crs=4326)
 tabela1_t=st_transform(tabela1, crs="+proj=merc +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +units=m")
 st_write(tabela1_t,"tacke1_trans.csv",layer_options="GEOMETRY=AS_XY")

when I run the first code for st_read function the program gives me the message that no simple geometries are present,but the tables are the same.当我运行 st_read function 的第一个代码时,程序给我的消息是不存在简单的几何图形,但表格是相同的。

Can someone give me the ansfer for why my code doesn't work?有人可以告诉我为什么我的代码不起作用吗? Sorry for bad english.抱歉英语不好。 I would be very thankful if someone knows what is the problem.如果有人知道问题出在哪里,我将不胜感激。 Bye, Aleksandar.再见,亚历山大。

I tried changing the format of the table but R studio only imported the.csv format.我尝试更改表格的格式,但 R 工作室仅导入了 .csv 格式。 I don't know what to do next.我不知道下一步该怎么做。

The code after running dput(head(tabela1)):运行 dput(head(tabela1)) 后的代码:

> dput(head(tabela1))
structure(list(Lon.lambda. = c("37.7", "-0.178", "30.25", "13.32757", 
"-3.69097", "12.52"), Lat.fi. = c("55.75", "51.48791", "59.91666", 
"52.51627", "40.44222", "41.88"), CITY_NAME = c("Moscow", "London", 
"Saint Petersburg", "Berlin", "Madrid", "Rome"), CNTRY_NAME = 
c("Russia", 
"U?", "Russia", "Germany", "Spain", "Italy"), N = c("6392773.83432", 
"6391248.57034", "6394182.05569", "6391622.66588", "6387139.33402", 
"6387672.51982"), m = c("1.77275", "1.60267", "1.98997", "1.63982", 
"1.3121", "1.3411"), p = c("3.14263", "2.56854", "3.95998", 
"2.68901", 
"1.72162", "1.79854"), Lon.rad = c("0.65799", "-0.00311", "0.52796", 
"0.23261", "-0.06442", "0.21852"), Lat.rad = c("0.97302", "0.89863", 
"1.04574", "0.91658", "0.70585", "0.73094"), M = c("6379156.04643", 
"6374591.09111", "6383372.63993", "6375710.51824", "6362303.41551", 
"6363896.88615")), row.names = c(NA, 6L), class = "data.frame")

You have a couple of options:你有几个选择:

  1. Ask whoever made table6.csv to export it as a "geometry" file (eg .shp , .gpkg ).请制作table6.csv的人将其导出为“几何”文件(例如.shp.gpkg )。 This will maintain the geometry data, and therefore can be read directly by sf::st_read()这将维护几何数据,因此可以直接由sf::st_read()读取

  2. Convert your data.frame to a spatial object in r将您的data.frame中的空间 object

## After reading your data in to R you can create an `sf` object from `tablea1`
sf <- sf::st_as_sf(tablea1, coords = c("Lon.lambda.", "Lat.fi."))

## You need to set the coordinate reference system (CRS)
## THe `Lon.lambda.` and `Lat.fi` columns already look like 
## they're in CRS 4326, so there's no need to use `st_transform()`, you only need to set the CRS
sf::st_crs(sf) <- 4326 

At this point you can do whatever you want with the data.此时,您可以对数据做任何您想做的事情。 But you probably don't want to但你可能不想

st_write(tabela1_t,"tacke1_trans.csv",layer_options="GEOMETRY=AS_XY")

Because you'll just be saving another.csv file, so you'll loose the geometry component.因为您将只保存另一个 .csv 文件,所以您将丢失几何组件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用循环时tbl_df和data.frame的区别 - tbl_df and data.frame difference when using loops 无法将 `spec_tbl_df/tbl_df/tbl/data.frame` 对象转换为函数 - Can't convert a `spec_tbl_df/tbl_df/tbl/data.frame` object to function 使用R将类&#39;tbl_df&#39;,&#39;tbl&#39;和&#39;data.frame转换为数据帧 - Convert Classes ‘tbl_df’, ‘tbl’ and 'data.frame into dataframe with R 错误 - “自动绘图不支持 tbl_df/tbl/data.frame 类型的对象。” - Error - "Objects of type tbl_df/tbl/data.frame not supported by autoplot." R 中的错误:无法将 `tbl_df/tbl/data.frame` object 转换为 function - Error in R of: Can't convert a `tbl_df/tbl/data.frame` object to function dplyr显示tbl_df中的小data.frame的所有行和列 - dplyr show all rows and columns for small data.frame inside a tbl_df 怪异:sapply无法在dplyr :: tbl_df()本地data.frame上工作 - WEIRD: sapply not working on dplyr::tbl_df() local data.frame 如何转换从“tbl_df”“tbl”“data.frame”中的 excel 导入的数据集。 到“xts”? - How do I convert a data set imported from excel from a ""tbl_df" "tbl" "data.frame"." to "xts"? 请确保结果列是一个因素或数字。 列的类别:'tbl_df'、'tbl'、'data.frame' - Please make sure that the outcome column is a factor or numeric. The class(es) of the column: 'tbl_df', 'tbl', 'data.frame' R 分组时间index_by()。 index_by() 无法处理 object 类型 'tbl_df'、'tbl'、'data.frame'、'mts'、'ts' - R grouping time index_by(). index_by() fails to work on object types 'tbl_df', 'tbl', 'data.frame', 'mts', 'ts'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM