我有一个roadfollowing
表,包含列
COLUMN geom geometry(LineString,4326);
我还有一个sub_polygon
表,包含一列
COLUMN geom geometry(MultiPolygon,4326);
我想sub_polygon
从存储在表中的线串中减去存储的多边形roadfollowing
,并用这些新数据更新表。
我尝试执行以下查询:
WITH RESULTS as (
SELECT ST_Difference(public.roadnetwork.geom, public.sub_polygon.geom)
FROM public.roadnetwork, public.sub_polygon
),
FILTERED_RESULTS as (
SELECT RESULTS.st_difference FROM RESULTS where GeometryType(RESULTS.st_difference) <> 'GEOMETRYCOLLECTION'
)
UPDATE public.roadnetwork
SET geom = FILTERED_RESULTS.st_difference
FROM FILTERED_RESULTS;
但我收到以下错误:
ERROR: Geometry type (MultiLineString) does not match column type (LineString)
我修改了查询以检查字符串格式的结果:
WITH RESULTS as (
SELECT ST_Difference(public.roadnetwork.geom, public.sub_polygon.geom)
FROM public.roadnetwork, public.sub_polygon
),
FILTERED_RESULTS as (
SELECT ST_AsText(RESULTS.st_difference) FROM RESULTS where GeometryType(RESULTS.st_difference) <> 'GEOMETRYCOLLECTION'
)
SELECT * from FILTERED_RESULTS;
我可以看到结果中有一些MULTILINESTRING
无法在roadnetwork.geom
列中复制,因为数据不一致:
...
MULTILINESTRING((51.5054201 25.3462475,51.505411 25.3462656,51.5052981 25.3464467,51.5051894 25.3466039,51.5049763 25.3469023,51.5048058 25.347141,51.5046538 25.347324,51.5044476 25.3475493,51.5041983 25.3478035,51.5038722 25.3481104,51.5035605 25.3483885,51.509695 25.3489269,51.5026179 25.3492445,51.5022888 25.349556),(51.5022888 25.349556,51.5022898 25.3495551),(51.5022888 25.349556,51.5017303 25.3500517))
LINESTRING(51.5017303 25.3500517,51.5014725 25.3502989,51.5013472 25.3504121)
LINESTRING(51.5013472 25.3504121,51.501175 25.3505679)
...
如何更新我的查询以转换MULTILINESTRING
为,LINESTRING
以便我可以成功更新我的表?