-2

我有一个名为areas_map两列的表a_id (bigint),并且geom (geometry(MultiPolygon, 4326)).

表“public.areas_map”列 | 类型 | 整理 | 可空 | 默认 ----------+-----------------+-------- ---+----------+--------- gid | 整数 | | 不为空 | a_id | 大整数 | | | gtype | 小号 | | | 几何 | 几何(MultiPolygon,4326) | | | mod_op | 字符(1) | | | mod_date | 没有时区的时间戳| | | 索引:“areas_map_pkey”主键,btree(gid)“idx_areas_map_geom”gist(geom)“idx_areas_map_a_id”btree(a_id)触发器:在插入或更新areas_map之前,每行执行过程add_mod_op_date()

我有另一个名为areas列的表,a_id_1 (character varying)wkt在上面的表中插入areas_map。我需要将 wkt 几何转换为 wkb 几何,以便将其放入“areas_map”中。

这些是我数据库中“区域”表中的列。

表“public.areas”列 | 类型 | 整理 | 可空 | 默认 --------------+-------------------+------------+-- --------+---------------------------------------- ogc_fid | 整数 | | 不为空 | nextval('areas_ogc_fid_seq'::regclass) a_id_1 | 性格变化| | | 周| 性格变化| | | wkb_geometry | 几何 | | | 索引:“areas_pkey”PRIMARY KEY、btree (ogc_fid) “areas_wkb_geometry_geom_idx”要点 (wkb_geometry)

这是表“区域”中的数据。

ogc_fid | a_id_1 | 周| wkb_geometry
-------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- --------------------------------- 1 | 3002618658 | MULTIPOLYGON(((-76.5473560619672 42.9413419720012,-76.5461994270791 42.9408894029933,-76.5428849220592 42.9424413310329,-76.540085618445 42.9435130207937,-76.5403432456807 42.9445933354756,-76.5417136457824 42.9446447959923,-76.5423695540135 42.9449534586902,-76.5424515359008 42.9454507456148,-76.5446238177076 42.9456536187894,-76.5449061034313 42.9473752994633,-76.5465216192731 42.9473555320693,-76.5464451670431 42.9465415450345,-76.547964643124 42.9465042162103,-76.5475477862325 42.9444728204718,-76.5473560619672 42. 9413419720012))) | 2 | 3003264375 | MULTIPOLYGON(((-118.20883035065 33.8744540214534,-118.208788426448 33.8811453764129,-118.214318573149 33.8811626720137,-118.213868789377 33.8764587738789,-118.214025554548 33.8755041061261,-118.214192790618 33.8749920466446,-118.213910539173 33.8744626447363,-118.20883035065 33. 8744540214534))) | 010600000001000000010300000001000000080000000E9DF9795D8D5DC0C0FFFF1BEEEF404028D821CA5C8D5DC0865B275FC9F040406CA63F65B78D5DC09E603DF0C9F040409900B806B08D5DC0130D15CD2FF04040AF523D98B28D5DC0A4A9BF8410F0404092AFAD55B58D5DC0A14C48BDFFEF40402381D4B5B08D5DC0A85B5664EEEF40400E9DF9795D8D5DC0C0FFFF1BEEEF4040 (2 rows)

我尝试了以下 sql 命令,但它一直给我错误。

INSERT INTO areas_map(a_id, geom)
SELECT a_id_1, ST_AsBinary(ST_GeomFromText(wkt)) AS geom
FROM areas WHERE a_id_1=CAST(a_id_1 as bigint);

我真的很感谢你的帮助。谢谢你。

4

1 回答 1

0

根据您的错误,我认为您希望的查询是:

INSERT INTO areas_map(a_id, geom)
VALUES (3002618658, ST_SetSRID(ST_GeomFromText('MULTIPOLYGON(((-76.5473560619672 42.9413419720012,-76.5461994270791 42.9408894029933,-76.5428849220592 42.9424413310329,-76.540085618445 42.9435130207937,-76.5403432456807 42.9445933354756,-76.5417136457824 42.9446447959923,-76.5423695540135 42.9449534586902,-76.5424515359008 42.9454507456148,-76.5446238177076 42.9456536187894,-76.5449061034313 42.9473752994633,-76.5465216192731 42.9473555320693,-76.5464451670431 42.9465415450345,-76.547964643124 42.9465042162103,-76.5475477862325 42.9444728204718,-76.5473560619672 42.9413419720012)))'), 4326))

您只需将数据插入表中

于 2021-09-10T18:40:14.480 回答