2014-12-05 59 views
0

我正在嘗試使用phpMyAdmin導入CSV。這是我的CSV樣子:在phpMyAdmin中導入CSV與多邊形數據

1,1,1,'POLYGON ((879350.00000000012 4542950.0,882236.75134594808 4547950.0,888010.25403784448 4547950.0,890897.00538379245 4542950.0,888010.25403784448 4537950.0,882236.75134594808 4537950.0,879350.00000000012 4542950.0))','POINT (885123.50269189617 4542950.0)' 
2,1,2,'POLYGON ((879350.00000000012 4552950.0,882236.75134594808 4557950.0,888010.25403784448 4557950.0,890897.00538379245 4552950.0,888010.25403784448 4547950.0,882236.75134594808 4547950.0,879350.00000000012 4552950.0))','POINT (885123.50269189617 4552950.0)' 
3,1,3,'POLYGON ((879350.00000000012 4562950.0,882236.75134594808 4567950.0,888010.25403784448 4567950.0,890897.00538379245 4562950.0,888010.25403784448 4557950.0,882236.75134594808 4557950.0,879350.00000000012 4562950.0))','POINT (885123.50269189617 4562950.0)' 

我的列名和類型如下:

CellId  int(11), 
Type  int(1), 
Name  varchar(255), 
Geometry polygon, 
Centroid point 

無論我怎麼努力,我總是似乎得到錯誤

'Invalid column count in CSV input on line 1' or 'Cannot get geometry object from data you send to the GEOMETRY field' 

我可以更改爲CSV或phpMyAdmin中的導入設置以使其正常工作?

回答

2

無法輕鬆導入幾何類型。我建議創建臨時表

CREATE TABLE IF NOT EXISTS `tmptbl` (
    `a` int(11), 
    `b` int(11), 
    `c` varchar(255), 
    `d` text, 
    `e` text 
) 

導入CSV到該表中,然後使用

INSERT INTO mytable (CellId,Type,Name,Geometry,Centroid) 
    SELECT a,b,c,GeomFromText(d),PointFromText(e) FROM tmptbl 
+0

工作完全得益於它轉換成你的表! – stuthemoo 2014-12-05 21:31:25

+0

非常好的主意, 我首先添加1個varchar列並導入數據[data format =「POINT(10 100)」]。那麼,使用update [table name] set [point column] = GeomFromText([varchar column])。 – 2015-01-10 02:30:03