Python + Mysql:将geojson多边形值插入mysql sptial列

时间:2017-10-19 13:08:00

标签: python mysql geometry polygon spatial

我有一个包含多边形数据的geojson文件。以下是它的例子。

[[[127.00733253963132, 37.583203339216226], 
 [127.00884131783923, 37.58045263873488], 
 [127.00861398800201, 37.57670881432089],
 [127.00783306341832, 37.57663511179821], 
 [126.99967765278153, 37.57589728327857], 
 [126.9971834726848, 37.57693224535312], 
 [126.99675796489285, 37.578422160319896], 
 [126.99660663904614, 37.579345394336194], 
 [126.99641172469617, 37.580645880422686], 
 [126.99649978451932, 37.581022567729896], 
 [126.99823026308687, 37.581266540341], 
 [127.00180462191403, 37.58253031283794], 
 [127.00172112834049, 37.583133635452405], 
 [127.00272082947205, 37.583723680505784], 
 [127.00580459526145, 37.584756278282704],
 [127.00618219538146, 37.58396129485959], 
 [127.00733253963132, 37.583203339216226]]]

我在mysql中有空间表。我正在尝试使用行sql将此多边形数据插入到多边形列中,但是,请继续失败。后来,我发现在mysql db中插入的多边形数据看起来与我的有点不同。这是我从互联网教程中看到的数据。

((126.97688884274817 37.575650779448786,  
126.9770344988775 37.569194530054546,  
126.97597472821249 37.569336299425764,   
126.97537470991254 37.569315567021562,   
126.97433193562325 37.569261800517531,  
126.96904837001854 37.568194417708312,  
126.96854493603384 37.568427679612753,  
126.9666499598212 37.569491655206569,  
126.96628175024485 37.569700734798701,  
126.9660973270804 37.569856509723699,  
126.96572852922577 37.570183936115114,   
126.96592699822128 37.570318805686199,   
126.96601094018429 37.57154839557748,   
126.96365922052196 37.575174660660359,   
126.96308600434513 37.576485920015529,   
126.96284099051198 37.576661586092726,   
126.96281041047263 37.579448809656768,  
126.96742431584332 37.579601537124489,   
126.96742176302651 37.579263521441646,   
126.9674300601846 37.579192577998612,   
126.96745709009561 37.578975250585444,   
126.96806604699626 37.578246780467865,   
126.96895511695477 37.577935262340283,  
126.96921284296906 37.577935299309395,   
126.96941453886579 37.578121124142172,   
126.96966442669471 37.578531136682209,  
126.96966721914872 37.578736205134923,   
126.96966877353309 37.578992879009881,   
126.96966949910363 37.579112526749597,  
126.96990457361626 37.579301753628719,   
126.97135197544759 37.579513277939817,   
126.97381925784454 37.579372140302631,  
126.97391736338342 37.578487073041011,   
126.97393961998088 37.578240429978088,   
126.97433153835757 37.575749906299862,   
126.97580378997804 37.575649468824203,  
126.97688884274817 37.575650779448786 ))'

所以我的想法是将多边形数据制作成字符串,然后使用正则表达式替换括号。但是这种方法需要很多时间。所以,我想知道是否有任何解决方案可以将这些数据插入到mysql的多边形字段中。

1 个答案:

答案 0 :(得分:1)

如果您使用的是PostgreSQL和PostGIS,则可以使用GeoAlchemy2库。但我认为目前没有对MySQL的支持,如果我错了,有人会纠正我。