我正在尝试将多多边形边界加载到mysql。我已经试过了,
安装了gdal和mysql驱动程序。核对 ogrDrivers()
在r中,它返回驱动程序列表中的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"
2条答案
按热度按时间wqlqzqxt1#
查看此链接时,参数必须用逗号分隔。所以也许这会奏效:
或者你试过
sf
包裹?或改变
host <- '127.0.0.1'
至host <- "localhost"
?kadbb4592#
首先,感谢@sega的不断帮助,我终于可以加载数据了。但有一些修正,这就是为什么我要详细说明它作为一个单独的答案。
dsn必须与上述内容完全相同,其中没有“dbname”字符串。而且,顺序必须和这个一模一样。因为,格达尔希望,如果你看看这个链接-http://www.gdal.org/drv_mysql.html
我试过用mysql连接,但没用,但给mysql dsn就行了。唯一的问题是,这会在数据库中创建一些额外的表(geometry\u columns、spatial\u ref\u sys)。
再次感谢您对世嘉的帮助。