gpt4 book ai didi

mysql - writeOGR 层创建失败 - MySQL

转载 作者:行者123 更新时间:2023-11-29 05:54:50 25 4
gpt4 key购买 nike

我正在尝试将多边形边界加载到 mysql。到目前为止,这是我尝试过的,

  1. 用 mysql 驱动程序安装了 gdal。在 R 中使用 ogrDrivers() 检查,它在驱动程序列表中返回 MySQL。

    db <- 'testdb'
    user <- 'testuser'
    pwd <- '****'
    host <- '127.0.0.1'

    DSN = paste0('MySQL:',db ,',user=', user, ',host=', host, ',password=', pwd)

    data_2013 <- readOGR(dsn = "/Path/to/shapefile", layer = "testinglayer")

    writeOGR(data_2013, dsn=DSN, driver='MySQL',layer='testinglayer', layer_options='ENGINE=Aria', overwrite_layer = TRUE)

但是我得到了这个错误,

Error in writeOGR(data_2013, dsn = DSN, driver = "MySQL", layer = "testinglayer",  : 
Layer creation failed

或者有没有其他方法可以将空间多边形数据从 R 加载到 MySQL?

编辑:根据要求,

> ogrDrivers()$name
[1] "AeronavFAA" "AmigoCloud" "ARCGEN" "AVCBin" "AVCE00"
[6] "BNA" "CAD" "Carto" "Cloudant" "CouchDB"
[11] "CSV" "CSW" "DGN" "DXF" "EDIGEO"
[16] "ElasticSearch" "ESRI Shapefile" "Geoconcept" "GeoJSON" "Geomedia"
[21] "GeoRSS" "GFT" "GML" "GMLAS" "GPKG"
[26] "GPSBabel" "GPSTrackMaker" "GPX" "HTF" "HTTP"
[31] "Idrisi" "Interlis 1" "Interlis 2" "JML" "JP2OpenJPEG"
[36] "JPEG2000" "KML" "LIBKML" "MapInfo File" "Memory"
[41] "MSSQLSpatial" "MySQL" "NAS" "netCDF" "ODBC"
[46] "ODS" "OGR_DODS" "OGR_GMT" "OGR_PDS" "OGR_SDTS"
[51] "OGR_VRT" "OpenAir" "OpenFileGDB" "OSM" "PCIDSK"
[56] "PGDUMP" "PGeo" "PLSCENES" "REC" "S57"
[61] "SEGUKOOA" "SEGY" "Selafin" "SQLite" "SUA"
[66] "SVG" "SXF" "TIGER" "UK .NTF" "VDV"
[71] "VFK" "Walk" "WAsP" "WFS" "XLS"
[76] "XLSX" "XPlane"

最佳答案

看着这个link , 参数必须以逗号分隔。所以也许这会起作用:

DSN = paste0('MYSQL:dbname=',db ,', user=', user, ', host=', host, ', password=', pwd, ', port=', port)

或者您是否尝试过 sf包?

DSN = paste0('MYSQL:dbname=',db ,' user=', user, ' host=', host, ' port=', port, ' password=', pwd)

library(sf)
data(meuse)
st_write(st_as_sf(meuse, coords = c("x","y")), dsn = DSN, layer = "testinglayer")

或更改 host <- '127.0.0.1'host <- "localhost"

关于mysql - writeOGR 层创建失败 - MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50559801/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com