|
@@ -35,24 +35,44 @@ def get_db():
|
|
|
def get_db_local():
|
|
|
return SessionLocal()
|
|
|
|
|
|
-from database import engine
|
|
|
-from models.geojson_base import *
|
|
|
-from shapely.geometry import shape
|
|
|
-import json
|
|
|
-db = get_db_local()
|
|
|
-with open('/home/python3/xh_twapi01/utils/spatial/zj_geojson.json', 'r', encoding='utf-8') as file:
|
|
|
- geojson = json.load(file)
|
|
|
-
|
|
|
-for feature in geojson:
|
|
|
- name = feature['properties'].get('NAME', '')
|
|
|
- geom = shape(feature['geometry']).__geo_interface__ # 将Shapely对象转换为GeoJSON
|
|
|
- properties = feature['properties']
|
|
|
- db.add(TpZjGeoJSONData(name=name, geometry=geom, properties=properties))
|
|
|
+# from database import engine
|
|
|
+# from models.geojson_base import *
|
|
|
+# from shapely.geometry import shape
|
|
|
+# import json
|
|
|
+# import pymysql
|
|
|
+# # db = get_db_local()
|
|
|
+# conn = pymysql.connect(host=settings.MYSQL_SERVER,
|
|
|
+# user=settings.MYSQL_USER,
|
|
|
+# password=settings.MYSQL_PASSWORD,
|
|
|
+# database=settings.MYSQL_DB_NAME,
|
|
|
+# port=settings.MYSQL_PORT,
|
|
|
+# charset='utf8mb4')
|
|
|
+# cur = conn.cursor()
|
|
|
+# with open('/home/python3/zj_geojson.json', 'r', encoding='utf-8') as file:
|
|
|
+# geojson = json.load(file)
|
|
|
+# features = geojson.get('features', [])
|
|
|
+# for feature in features:
|
|
|
+# # print(feature)
|
|
|
+# name = feature['properties'].get('NAME', '')
|
|
|
+# geom = shape(feature['geometry']).__geo_interface__ # 将Shapely对象转换为GeoJSON
|
|
|
+# # print(geom)
|
|
|
+# properties = json.dumps(feature['properties'], ensure_ascii=False)
|
|
|
+# pac = feature['properties'].get('PAC', '')
|
|
|
+# sql = """
|
|
|
+# INSERT INTO tp_geojson_data_zj (name, geometry, properties,pac)
|
|
|
+# VALUES (%s, ST_GeomFromGeoJSON(%s), %s,%s)
|
|
|
+# """
|
|
|
+# # 执行插入操作
|
|
|
+# cur.execute(sql, (name, json.dumps(geom), properties,pac))
|
|
|
+# conn.commit()
|
|
|
+ # 提交事务
|
|
|
|
|
|
+ # break
|
|
|
# 提交事务
|
|
|
-db.commit()
|
|
|
-# 关闭会话
|
|
|
-db.close()
|
|
|
+
|
|
|
+# db.commit()
|
|
|
+# # 关闭会话
|
|
|
+# db.close()
|
|
|
|
|
|
#from models.oneshare_base import Base
|
|
|
#from models.knowledge_base import Base
|