kalmanfans's Blog

模式识别 非线性预测 复杂网络 Following your heart

图解将shape file导入MySQL数据库中

本文介绍通过网上流传的《将shp文件导入到mysql的命令.rar》将shp文件导入到MySQL数据库中。

 

首先下载《将shp文件导入到mysql的命令。rar》并解压。将文件名改为字符的吧,省去不必要的麻烦。(如果不能下载,email至shchen.lmars@live.cn, 标题:《求<将shp文件导入到mysql的命令。rar>》)

第二部:准备文件。

一个shp文件有多个文件组成, .dbf, .sbn, .sbx, .shp, .shx.

将shp以及shp的相关文件和DOShere文件放在同一目录下。

第三:执行生成sql的命令。

shp2MySQL shp文件名.shp 表名 数据库名 > 生成的sql文件名.sql

 

进入该文件目录, 

 

第四:修改生成的sql文件:

修改table表的字段名;

  1. ALTER TABLE 表名 ADD the_geom GEOMETRY; 

add必须为:the_geom GEOMETRY。我的情况是,生成的sql中,有

ALTER TABLE 表名 ADD ogc_geom GEOMETRY;

只需要修改字段名为 the_geom。

替换所有的,-1) );为) );  就是说去掉“,-1”。

第五:到MySQL数据库导入sql文件即可

 

我碰到的新问题:

Cygwin1.dll的处置。

在DOshere命令窗口中执行命令时,弹出错误信息:

 

计算机中丢失cygwin1l.dll。尝试重新安装该程序以解决此问题

 

解决之道,下载cygwin1l.dll (http://www.dll-files.com/dllindex/dll-files.shtml?cygwin1)

并解压到相应的目录。

Open the zip-file you downloaded from DLL-files.com.

Extract cygwin1.dll to a location on your computer. We recommend you to unzip it to the directory of the program that is requesting cygwin1.dll.

If that doesn't work, you will have to extract cygwin1.dll to your system directory. By default, this is:

  • C:\Windows\System (Windows 95/98/Me)
  • C:\WINNT\System32 (Windows NT/2000)
  • C:\Windows\System32 (Windows XP, Vista, 7)

If you use a 64-bit version of Windows, you should also place cygwin1.dll in C:\Windows\SysWOW64\

Make sure overwrite any existing files (but make a backup copy of the original file).

Reboot your computer.

If the problem still occurs, try the following:

  1. Open Windows Start menu and select "Run...".
  2. Type CMD and press Enter (or if you use Windows ME, type COMMAND)).
  3. Type regsvr32 cygwin1.dll and press Enter.

INSERT INTO signal_strength_table VALUES('0','10045','26374','1.84194519856e+005','0',GeometryFromText('MULTIPOLYGON(((3474163.683371824212372 5503441.758485510945320 ,3474163.532771822530776 5503410.121985509991646 ,3474317.550171823706478 5503441.905285511165857 ,3474163.683371824212372 5503441.758485510945320 )))',-1) );

__________________________________________________________________________________________________

i have got new version of SHP2MySQL software from Köbben (ITC, GIP) from the website of: http://home.lijbrandt.nl/bjkobben/RIMapper/

it is more convenient to import the shape file data into MySQL database.   

write to me: shchen.lmars@live.cn, if possible.