soil.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. from sqlalchemy import Column, Integer, Float, ForeignKey, ForeignKeyConstraint
  2. from geoalchemy2 import Geometry
  3. from app.database import Base
  4. class SoilData(Base):
  5. """
  6. 土壤理化性质数据模型
  7. @param {int} id - 自增主键
  8. @param {int} farmland_id - 关联的农业用地矢量点编号(外键)
  9. @param {int} sample_id - 关联的采样自增ID(外键)
  10. @param {float} clay_0002IDW - 黏粒组分(<0.002mm)占比(%)
  11. @param {float} bd020_90 - 土壤容重(g/cm³)
  12. ...(其他字段参考下方详细定义)
  13. """
  14. __tablename__ = 'Soil_data'
  15. __table_args__ = (
  16. # 定义复合外键约束(关联Farmland_data表的联合主键)
  17. ForeignKeyConstraint(
  18. ['Farmland_ID', 'Sample_ID'], # 当前表的列名
  19. ['Farmland_data.Farmland_ID', 'Farmland_data.Sample_ID'] # 被引用表的列名
  20. ),
  21. {'comment': '土壤理化性质数据表,存储关联的耕地样点土壤指标'}
  22. )
  23. # 主键
  24. id = Column('ID', Integer, primary_key=True, autoincrement=True, comment='自增主键')
  25. # 外键(注意字段名与Farmland_data表大小写保持一致)
  26. farmland_id = Column('Farmland_ID', Integer, nullable=False, comment='关联Farmland_data表的Farmland_ID')
  27. sample_id = Column('Sample_ID', Integer, nullable=False, comment='关联Farmland_data表的Sample_ID')
  28. # 土壤理化性质字段(按表格顺序定义)
  29. clay_0002IDW = Column('0002IDW', Float, nullable=True, comment='粒径<0.002mm的黏粒组分占比(%)')
  30. bd020_90 = Column('bd020_90', Float, nullable=True, comment='容重(g/cm³),使用时需除1000')
  31. por_layer = Column('POR_Layer', Float, nullable=True, comment='土壤孔隙度(cm³/cm³)')
  32. exal_idw = Column('ExAl_IDW', Float, nullable=True, comment='交换性Al³⁺[cmol(1/3Al³⁺)/kg]')
  33. exca_idw = Column('ExCa_IDW', Float, nullable=True, comment='交换性Ca²⁺[cmol(1/2Ca²⁺)/kg]')
  34. exk_idw = Column('ExK_IDW', Float, nullable=True, comment='交换性K⁺[cmol(K⁺)/kg]')
  35. exmg_idw = Column('ExMg_IDW', Float, nullable=True, comment='交换性Mg²⁺[cmol(1/2Mg²⁺)/kg]')
  36. exna_idw = Column('ExNa_IDW', Float, nullable=True, comment='交换性Na⁺[cmol(Na⁺)/kg]')
  37. fed_idw = Column('Fed_IDW', Float, nullable=True, comment='游离铁(g/kg)')
  38. som_idw = Column('SOM_IDW', Float, nullable=True, comment='有机质(g/kg)')
  39. idw_2013pc_cd = Column('IDW_2013PC_Cd', Float, nullable=True, comment='2013年普查总镉(mg/kg)')
  40. idw_2018xc_cd = Column('IDW_2018XC_Cd', Float, nullable=True, comment='2018年详查总镉(mg/kg)')
  41. idw_2023sp_cd = Column('IDW_2023SP_Cd', Float, nullable=True, comment='2023年三普镉(mg/kg)')
  42. idw_2013pc_ph = Column('IDW_2013PC_pH', Float, nullable=True, comment='2013年普查pH值')
  43. idw_2018xc_ph = Column('IDW_2018XC_pH', Float, nullable=True, comment='2018年详查pH值')
  44. idw_2023sp_ph = Column('IDW_2023SP_pH', Float, nullable=True, comment='2023年三普pH值')
  45. silt_002_0002IDW = Column('002_0002IDW', Float, nullable=True, comment='粉粒组分(0.002~0.02mm)占比(%)')
  46. sand_02_002IDW = Column('02_002IDW', Float, nullable=True, comment='砂粒组分(0.02~0.2mm)占比(%)')
  47. gravel_2_02IDW = Column('2_02IDW', Float, nullable=True, comment='石砾组分(>2mm)占比(%)')
  48. avak_idw = Column('AvaK_IDW', Float, nullable=True, comment='速效钾(mg/kg)')
  49. avap_idw = Column('AvaP_IDW', Float, nullable=True, comment='有效磷(mg/kg)')
  50. cec_idw = Column('CEC_IDW', Float, nullable=True, comment='阳离子交换量[cmol(+)/kg]')
  51. ec_idw = Column('EC_IDW', Float, nullable=True, comment='电导率(mS/cm)')
  52. oc_fe_0_30 = Column('OC-Fe_0-30', Float, nullable=True, comment='土壤铁结合态有机碳(g/kg)')
  53. savak_idw = Column('SAvaK_IDW', Float, nullable=True, comment='缓效钾(mg/kg)')
  54. tal_idw = Column('TAl_IDW', Float, nullable=True, comment='全铝(%)')
  55. tca_idw = Column('TCa_IDW', Float, nullable=True, comment='全钙(%)')
  56. tcd_idw = Column('TCd_IDW', Float, nullable=True, comment='总镉(mg/kg)')
  57. teb_idw = Column('TEB_IDW', Float, nullable=True, comment='水溶性盐总量(mg/L)')
  58. texh_idw = Column('TExH_IDW', Float, nullable=True, comment='交换性酸总量[cmol (H⁺ + 1/3Al³⁺)/kg]')
  59. tfe_idw = Column('TFe_IDW', Float, nullable=True, comment='全铁(%)')
  60. tk_idw = Column('TK_IDW', Float, nullable=True, comment='全钾(g/kg)')
  61. tmg_idw = Column('TMg_IDW', Float, nullable=True, comment='全镁(%)')
  62. tmn_idw = Column('TMn_IDW', Float, nullable=True, comment='全锰(mg/kg)')
  63. tn_idw = Column('TN_IDW', Float, nullable=True, comment='全氮(g/kg)')
  64. tp_idw = Column('TP_IDW', Float, nullable=True, comment='全磷(g/kg)')
  65. ts_idw = Column('TS_IDW', Float, nullable=True, comment='全硫(g/kg)')
  66. dqcj_cd = Column('DQCJ_Cd', Float, nullable=True, comment='大气沉降输入Cd(g/ha/a)')
  67. ggs_cd = Column('GGS_Cd', Float, nullable=True, comment='灌溉水输入Cd(g/ha/a)')
  68. dx_cd = Column('DX_Cd', Float, default=0.023, nullable=True, comment='地下渗漏Cd(g/ha/a)')
  69. db_cd = Column('DB_Cd', Float, default=0.368, nullable=True, comment='地表径流Cd(g/ha/a)')
  70. def __repr__(self):
  71. return f"<SoilData(id={self.id}, farmland_id={self.farmland_id}, sample_id={self.sample_id})>"