mysql保存多边形,几何数据类型
我在MySQL表中有多边形几何数据。数据被存储为文本,我需要将数据保存为几何
datatype。
state_fips_code tract_ce tract_geom
6 576700 POLYGON((-118.169788 33.74847, -118.167625 33.747597, -118.165187 33.747139, -118.165741 33.739433, -118.162769 33.739184, -118.162638 33.73965, -118.162508 33.740117, -118.161791 33.742436, -118.161766 33.742512, -118.160742 33.746281, -118.160714 33.746387, -118.159262 33.751741, -118.158781 33.753463, -118.157518 33.757987, -118.156954 33.760101, -118.156884 33.760362, -118.156531 33.761425, -118.15616 33.76175, -118.155959 33.762416, -118.15577 33.763042, -118.155603 33.763596, -118.155444 33.764124, -118.155268 33.764727, -118.154575 33.764584, -118.154574 33.765026, -118.15458 33.766035, -118.154581 33.766266, -118.154584 33.767057, -118.154589 33.767951, -118.15459 33.768073, -118.155696 33.768074, -118.155904 33.768074, -118.156762 33.768076, -118.157844 33.768077, -118.158646 33.768078, -118.158925 33.768079, -118.159534 33.76808, -118.159557 33.76808, -118.160268 33.76808, -118.160584 33.768081, -118.161666 33.768076, -118.161683 33.768076, -118.162772 33.768078, -118.162938 33.768078, -118.163854 33.768079, -118.16421 33.76808, -118.164738 33.768074, -118.165013 33.768097, -118.165136 33.768129, -118.165204 33.768161, -118.165299 33.768232, -118.165379 33.768324, -118.165389 33.768291, -118.165424 33.768173, -118.165457 33.768062, -118.165463 33.768042, -118.165621 33.767529, -118.16568 33.767337, -118.165806 33.766926, -118.16599 33.766328, -118.166149 33.765794, -118.166308 33.76528, -118.166632 33.764199, -118.166191 33.764109, -118.166348 33.763579, -118.16643 33.763468, -118.166608 33.762587, -118.166728 33.761999, -118.16676 33.761851, -118.166769 33.761802, -118.166792 33.761705, -118.16816 33.755431, -118.168649 33.753374, -118.169788 33.74847))
在熊猫中,我做:
import pandas as pd
import geopandas as gpd
import shapely.geometry
from shapely import wkt
df['geometry'] = df['tract_geom'].apply(wkt.loads)
df_gdf = gpd.GeoDataFrame(df, geometry='geometry')
我尝试了:
ALTER TABLE geom MODIFY tract_geom Polygon;
我得到:
Error Code: 1416. Cannot get geometry object from data you send to the GEOMETRY field
如何更新mysql
表和列的数据类型为geamogogy
?
I have polygon geometries data in MySQL table. The data is stored as text and I need to save the data as geometry
datatype.
state_fips_code tract_ce tract_geom
6 576700 POLYGON((-118.169788 33.74847, -118.167625 33.747597, -118.165187 33.747139, -118.165741 33.739433, -118.162769 33.739184, -118.162638 33.73965, -118.162508 33.740117, -118.161791 33.742436, -118.161766 33.742512, -118.160742 33.746281, -118.160714 33.746387, -118.159262 33.751741, -118.158781 33.753463, -118.157518 33.757987, -118.156954 33.760101, -118.156884 33.760362, -118.156531 33.761425, -118.15616 33.76175, -118.155959 33.762416, -118.15577 33.763042, -118.155603 33.763596, -118.155444 33.764124, -118.155268 33.764727, -118.154575 33.764584, -118.154574 33.765026, -118.15458 33.766035, -118.154581 33.766266, -118.154584 33.767057, -118.154589 33.767951, -118.15459 33.768073, -118.155696 33.768074, -118.155904 33.768074, -118.156762 33.768076, -118.157844 33.768077, -118.158646 33.768078, -118.158925 33.768079, -118.159534 33.76808, -118.159557 33.76808, -118.160268 33.76808, -118.160584 33.768081, -118.161666 33.768076, -118.161683 33.768076, -118.162772 33.768078, -118.162938 33.768078, -118.163854 33.768079, -118.16421 33.76808, -118.164738 33.768074, -118.165013 33.768097, -118.165136 33.768129, -118.165204 33.768161, -118.165299 33.768232, -118.165379 33.768324, -118.165389 33.768291, -118.165424 33.768173, -118.165457 33.768062, -118.165463 33.768042, -118.165621 33.767529, -118.16568 33.767337, -118.165806 33.766926, -118.16599 33.766328, -118.166149 33.765794, -118.166308 33.76528, -118.166632 33.764199, -118.166191 33.764109, -118.166348 33.763579, -118.16643 33.763468, -118.166608 33.762587, -118.166728 33.761999, -118.16676 33.761851, -118.166769 33.761802, -118.166792 33.761705, -118.16816 33.755431, -118.168649 33.753374, -118.169788 33.74847))
In pandas, I do:
import pandas as pd
import geopandas as gpd
import shapely.geometry
from shapely import wkt
df['geometry'] = df['tract_geom'].apply(wkt.loads)
df_gdf = gpd.GeoDataFrame(df, geometry='geometry')
I tried:
ALTER TABLE geom MODIFY tract_geom Polygon;
I get:
Error Code: 1416. Cannot get geometry object from data you send to the GEOMETRY field
How do I update mysql
table and the datatype of the column to geometry
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 将WKT字符串几何列转换为几何列:
通过创建新表并用类似的内容插入所有行,这绝对可以更轻松地完成。
You can use
ST_GeomFromTxt
to convert a WKT string geometry column to a Geometry column:This is definitely more easily done by creating a new table and inserting all rows with something like:
您可以首先添加一个新列,然后使用st_polygonfromtext从文本列中设置该列的值
You can add a new column first of type POLYGON and then set values of that column using ST_PolygonFromText from your text column