-- GIS引擎数据库初始化脚本
-- 创建PostGIS扩展
CREATE EXTENSION IF NOT EXISTS postgis;
CREATE EXTENSION IF NOT EXISTS postgis_topology;

-- 创建精河县基础底图
INSERT INTO gis_base_map (name, type, geom) VALUES 
('精河县基础底图', 'county', ST_GeomFromText('POLYGON((82.85 43.98, 83.10 43.98, 83.10 44.08, 82.85 44.08, 82.85 43.98))', 4326));

-- 创建监测点位（模拟数据）
INSERT INTO iot_device (device_code, name, device_type, longitude, latitude, gis_layer_name, location_geom) VALUES
('SW001', '1号水位监测点', 'SW', 44.0321, 82.8973, 'water_level', ST_GeomFromText('POINT(44.0321 82.8973)', 4326)),
('SW002', '2号水位监测点', 'SW', 44.0365, 82.9058, 'water_level', ST_GeomFromText('POINT(44.0365 82.9058)', 4326)),
('YL001', '1号压力监测点', 'YL', 44.0410, 82.9143, 'water_pressure', ST_GeomFromText('POINT(44.0410 82.9143)', 4326)),
('YL002', '2号压力监测点', 'YL', 44.0455, 82.9228, 'water_pressure', ST_GeomFromText('POINT(44.0455 82.9228)', 4326)),
('ZD001', '1号浊度监测点', 'ZD', 44.0500, 82.9313, 'turbidity', ST_GeomFromText('POINT(44.0500 82.9313)', 4326)),
('LL001', '1号流量监测点', 'LL', 44.0545, 82.9398, 'flow_rate', ST_GeomFromText('POINT(44.0545 82.9398)', 4326));

-- 创建管网数据（模拟）
INSERT INTO water_pipe_network (pipe_code, pipe_type, diameter, material, start_point_geom, end_point_geom) VALUES
('P001', '主管道', 300, '铸铁', ST_GeomFromText('POINT(44.0321 82.8973)', 4326), ST_GeomFromText('POINT(44.0410 82.9143)', 4326)),
('P002', '支管道', 150, 'PE', ST_GeomFromText('POINT(44.0365 82.9058)', 4326), ST_GeomFromText('POINT(44.0455 82.9228)', 4326)),
('P003', '管道', 100, 'PVC', ST_GeomFromText('POINT(44.0410 82.9143)', 4326), ST_GeomFromText('POINT(44.0500 82.9313)', 4326));
