Переглянути джерело

添加四县三种用电土地利用类型模型及其数据库迁移脚本,更新模型导入路径。

drggboy 5 днів тому
батько
коміт
c8617c1d13

+ 1 - 0
app/models/__init__.py

@@ -21,3 +21,4 @@ from app.models.agricultural import *
 from app.models.cross_section import *
 from app.models.province import *
 from app.models.city import *
+from app.models.land_use import *  # 导入四县三种用电土地利用类型模型

+ 90 - 0
app/models/land_use.py

@@ -0,0 +1,90 @@
+# coding: utf-8
+"""
+四县三种用电土地利用类型模型
+Four County Three Type Land Use Model
+"""
+
+from sqlalchemy import Column, Integer, String, Float, Numeric
+from geoalchemy2.types import Geometry
+from app.models.base import Base
+
+
+class FourCountyLandUse(Base):
+    """
+    四县三种用电土地利用类型表
+    Four County Three Type Land Use Table
+    """
+    __tablename__ = 'four_county_land'
+    __table_args__ = {'comment': '四县三种用电土地利用类型数据'}
+
+    # 主键
+    gid = Column(Integer, primary_key=True, autoincrement=True, comment='主键ID')
+    
+    # 对象标识
+    objectid = Column(Integer, name='objectid', comment='对象标识符')
+    
+    # 标识码
+    bsm = Column(String(18), name='bsm', comment='标识码')
+    
+    # 要素代码
+    ysdm = Column(String(10), name='ysdm', comment='要素代码')
+    
+    # 图斑编号
+    tbybh = Column(String(18), name='tbybh', comment='图斑预编号')
+    tbbh = Column(String(8), name='tbbh', comment='图斑编号')
+    
+    # 地类信息
+    dlbm = Column(String(5), name='dlbm', comment='地类编码')
+    dlmc = Column(String(60), name='dlmc', comment='地类名称')
+    
+    # 权属信息
+    qsxz = Column(String(2), name='qsxz', comment='权属性质')
+    qsdwdm = Column(String(19), name='qsdwdm', comment='权属单位代码')
+    qsdwmc = Column(String(60), name='qsdwmc', comment='权属单位名称')
+    
+    # 坐落单位
+    zldwdm = Column(String(19), name='zldwdm', comment='坐落单位代码')
+    zldwmc = Column(String(60), name='zldwmc', comment='坐落单位名称')
+    
+    # 面积信息
+    tbmj = Column(Numeric(19, 11), name='tbmj', comment='图斑面积')
+    kcdlbm = Column(String(5), name='kcdlbm', comment='扣除地类编码')
+    kcxs = Column(Numeric(19, 11), name='kcxs', comment='扣除系数')
+    kcmj = Column(Numeric(19, 11), name='kcmj', comment='扣除面积')
+    tbdlmj = Column(Numeric(19, 11), name='tbdlmj', comment='图斑地类面积')
+    
+    # 耕地信息
+    gdlx = Column(String(2), name='gdlx', comment='耕地类型')
+    gdpdjb = Column(String(2), name='gdpdjb', comment='耕地坡度级别')
+    xzdwkd = Column(Numeric(19, 11), name='xzdwkd', comment='线状地物宽度')
+    
+    # 图斑细化
+    tbxhdm = Column(String(6), name='tbxhdm', comment='图斑细化代码')
+    tbxhmc = Column(String(20), name='tbxhmc', comment='图斑细化名称')
+    
+    # 种植属性
+    zzsxdm = Column(String(6), name='zzsxdm', comment='种植属性代码')
+    zzsxmc = Column(String(20), name='zzsxmc', comment='种植属性名称')
+    
+    # 耕地等别
+    gddb = Column(Integer, name='gddb', comment='耕地等别')
+    
+    # 其他属性
+    frdbs = Column(String(1), name='frdbs', comment='非入等标识')
+    czcsxm = Column(String(4), name='czcsxm', comment='城镇村属性码')
+    sjnf = Column(Integer, name='sjnf', comment='数据年份')
+    mssm = Column(String(2), name='mssm', comment='模式识别码')
+    hdmc = Column(String(100), name='hdmc', comment='河道名称')
+    bz = Column(String(254), name='bz', comment='备注')
+    
+    # 形状信息
+    shape_leng = Column(Numeric(19, 11), name='shape_leng', comment='形状长度')
+    shape_le_1 = Column(Numeric(19, 11), name='shape_le_1', comment='形状长度1')
+    shape_area = Column(Numeric(19, 11), name='shape_area', comment='形状面积')
+    
+    # 几何信息 - 使用EPSG:4526坐标系
+    geom = Column(
+        Geometry('POLYGON', 4526, from_text='ST_GeomFromEWKT', name='geometry'), 
+        index=True, 
+        comment='几何位置信息-多边形'
+    )

+ 74 - 0
migrations/versions/29a56094509c_add_four_county_land_use_table.py

@@ -0,0 +1,74 @@
+"""add_four_county_land_use_table
+
+Revision ID: 29a56094509c
+Revises: d89bb52ae481
+Create Date: 2025-08-17 10:01:27.121198
+
+"""
+from alembic import op
+import sqlalchemy as sa
+import geoalchemy2
+
+
+# revision identifiers, used by Alembic.
+revision = '29a56094509c'
+down_revision = 'd89bb52ae481'
+branch_labels = None
+depends_on = None
+
+
+def upgrade():
+    """升级数据库到当前版本 - 创建四县三种用电土地利用类型表"""
+    # 创建四县三种用电土地利用类型表
+    op.create_table(
+        'four_county_land',
+        sa.Column('gid', sa.Integer(), autoincrement=True, nullable=False, comment='主键ID'),
+        sa.Column('objectid', sa.Integer(), nullable=True, comment='对象标识符'),
+        sa.Column('bsm', sa.String(length=18), nullable=True, comment='标识码'),
+        sa.Column('ysdm', sa.String(length=10), nullable=True, comment='要素代码'),
+        sa.Column('tbybh', sa.String(length=18), nullable=True, comment='图斑预编号'),
+        sa.Column('tbbh', sa.String(length=8), nullable=True, comment='图斑编号'),
+        sa.Column('dlbm', sa.String(length=5), nullable=True, comment='地类编码'),
+        sa.Column('dlmc', sa.String(length=60), nullable=True, comment='地类名称'),
+        sa.Column('qsxz', sa.String(length=2), nullable=True, comment='权属性质'),
+        sa.Column('qsdwdm', sa.String(length=19), nullable=True, comment='权属单位代码'),
+        sa.Column('qsdwmc', sa.String(length=60), nullable=True, comment='权属单位名称'),
+        sa.Column('zldwdm', sa.String(length=19), nullable=True, comment='坐落单位代码'),
+        sa.Column('zldwmc', sa.String(length=60), nullable=True, comment='坐落单位名称'),
+        sa.Column('tbmj', sa.Numeric(precision=19, scale=11), nullable=True, comment='图斑面积'),
+        sa.Column('kcdlbm', sa.String(length=5), nullable=True, comment='扣除地类编码'),
+        sa.Column('kcxs', sa.Numeric(precision=19, scale=11), nullable=True, comment='扣除系数'),
+        sa.Column('kcmj', sa.Numeric(precision=19, scale=11), nullable=True, comment='扣除面积'),
+        sa.Column('tbdlmj', sa.Numeric(precision=19, scale=11), nullable=True, comment='图斑地类面积'),
+        sa.Column('gdlx', sa.String(length=2), nullable=True, comment='耕地类型'),
+        sa.Column('gdpdjb', sa.String(length=2), nullable=True, comment='耕地坡度级别'),
+        sa.Column('xzdwkd', sa.Numeric(precision=19, scale=11), nullable=True, comment='线状地物宽度'),
+        sa.Column('tbxhdm', sa.String(length=6), nullable=True, comment='图斑细化代码'),
+        sa.Column('tbxhmc', sa.String(length=20), nullable=True, comment='图斑细化名称'),
+        sa.Column('zzsxdm', sa.String(length=6), nullable=True, comment='种植属性代码'),
+        sa.Column('zzsxmc', sa.String(length=20), nullable=True, comment='种植属性名称'),
+        sa.Column('gddb', sa.Integer(), nullable=True, comment='耕地等别'),
+        sa.Column('frdbs', sa.String(length=1), nullable=True, comment='非入等标识'),
+        sa.Column('czcsxm', sa.String(length=4), nullable=True, comment='城镇村属性码'),
+        sa.Column('sjnf', sa.Integer(), nullable=True, comment='数据年份'),
+        sa.Column('mssm', sa.String(length=2), nullable=True, comment='模式识别码'),
+        sa.Column('hdmc', sa.String(length=100), nullable=True, comment='河道名称'),
+        sa.Column('bz', sa.String(length=254), nullable=True, comment='备注'),
+        sa.Column('shape_leng', sa.Numeric(precision=19, scale=11), nullable=True, comment='形状长度'),
+        sa.Column('shape_le_1', sa.Numeric(precision=19, scale=11), nullable=True, comment='形状长度1'),
+        sa.Column('shape_area', sa.Numeric(precision=19, scale=11), nullable=True, comment='形状面积'),
+        sa.Column('geom', geoalchemy2.types.Geometry(geometry_type='POLYGON', srid=4526, from_text='ST_GeomFromEWKT', name='geometry'), nullable=True, comment='几何位置信息-多边形'),
+        sa.PrimaryKeyConstraint('gid'),
+        comment='四县三种用电土地利用类型数据'
+    )
+    
+    # 创建空间索引
+    op.execute("CREATE INDEX IF NOT EXISTS idx_four_county_land_geom ON four_county_land USING gist (geom)")
+
+
+def downgrade():
+    """将数据库降级到上一版本 - 删除四县三种用电土地利用类型表"""
+    # 删除空间索引
+    op.drop_index('idx_four_county_land_geom', table_name='four_county_land')
+    # 删除表
+    op.drop_table('four_county_land')