Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Import shape file into MySQL

I need to import the spatial data in shape file into MySQL tables. I am able to import into PostGreSQL. Any pointers for MySQL. I need the data in MySQL table.

like image 987
PhantomM Avatar asked Feb 27 '13 22:02

PhantomM


People also ask

How do I import data into MySQL?

Importing a database from a fileFill in the fields with the connection information. Once connected to the database go to Data Import/Restore. Choose the option Import from Self-Contained File and select the file. Choose the destination database in Default Schema to be Imported To and then click on Start Import.

How do shape files work?

The shapefile format stores the geometry as primitive geometric shapes like points, lines, and polygons. These shapes, together with data attributes that are linked to each shape, create the representation of the geographic data.


2 Answers

try this with FWtool installed

ogr2ogr -f MySQL MySQL:database_name,host=localhost,user=root,password=1234 C:\route_path\line.shp -nln datatable_name -update -overwrite -lco engine=MYISAM

try install for a better result in any process Osgeo4w

http://trac.osgeo.org/osgeo4w/

like image 163
phipex Avatar answered Sep 20 '22 03:09

phipex


I have just used the ogr2ogr command line tool to import the shape file into the mysql database. Make sure that the database server allows external connections. If doesn't, then it throws all sorts of errors.

Once you have that you can use -

Select ASTEXT(Shape) POLYGON from world to get an array of the polygon coordinates etc

like image 39
user1464629 Avatar answered Sep 18 '22 03:09

user1464629