我的服务器上有CSV文件,其中的数据如下所示;
16777216,17039359,"APNIC Debogon Project"
17367040,17432575,"Tmnet, Telekom Malaysia Bhd."
17435136,17435391,"APNIC Debogon Project"
17498112,17563647,"CJ-HELLOVISION"
17563648,17825791,"Beijing Founder Broadband Network Technology Co.,L"
17825792,18087935,"Allocated to KRNIC Member."
18153984,18154239,"Double Cast"
18157056,18163711,"FAMILY NET JAPAN INCORPORATED"
我正在尝试将其插入到我的表中,其结构如下;
ipoid INTEGER 11 NOT NULL PRIMARY KEY
beginip INTEGER 14 NOT NULL UNSIGNED
endip INTEGER 14 NOT NULL UNSIGNED
org VARCHAR 255
ip_poly POLYGON
我还在ip_poly字段
上创建了空间索引我正在尝试使用以下代码插入csv数据
LOAD DATA INFILE "/home/GeoIPOrg.csv"
INTO TABLE crm_geo_org
FIELDS
TERMINATED BY ","
ENCLOSED BY "\""
LINES
TERMINATED BY "\n"
(@beginIp,@endIp,@org)
SET
ipoid := NULL,
beginip := @beginIp,
endip := @endIp,
ip_poly := GEOMFROMWKB(POLYGON(LINESTRING(
/* clockwise, 4 points and back to 0 */
POINT(@beginIp, -1), /* 0, top left */
POINT(@endIp, -1), /* 1, top right */
POINT(@endIp, 1), /* 2, bottom right */
POINT(@beginIp, 1), /* 3, bottom left */
POINT(@beginIp, -1) /* 0, back to start */
))),
org:= @org;
然而,当我尝试这样做时,我收到此错误
错误1416(22003):无法从发送到GEOMETRY字段的数据中获取几何对象
有什么想法吗?
答案 0 :(得分:1)
在MySQL
的更高版本中,您不需要WKB
/ WKT
转换来构建几何对象。
此外,Polygon
在此处过分:MBR
也可以从单个LineString
构建。
将您的ip_poly
更改为iprange LINESTRING NOT NULL
并使用此功能:
LOAD DATA INFILE "/home/GeoIPOrg.csv"
INTO TABLE
crm_geo_org
FIELDS
TERMINATED BY
","
ENCLOSED BY
"\""
LINES
TERMINATED BY "\n"
(@beginIp, @endIp, @org)
SET ipoid := NULL,
beginip := @beginIp,
endip := @endIp,
iprange := GeomFromWKB(
LineString(
Point(@beginIp, -1),
Point(@endIp, 1)
)
),
org := @org;