Monday, 12 March 2018

geometry - Convert lineString to MultilineString in PostGIS


How can I convert the line string to multiline string in PostGIS? I have converted geometry points to line string by this: st_makeline(location.shape) but by this command:


  SELECT uuid_generate_v4()                                         AS uuid,
j."deviceId",

st_astext(st_linemerge(st_union(j.shape))) AS multiLine
FROM j
group by date, j."deviceId" ;

I got this results:


enter image description here


It's result is again line string?



Answer



Have you tried ST_Multi? https://postgis.net/docs/ST_Multi.html


select st_astext(st_multi(st_geometryfromtext('LINESTRING (30 10, 10 30, 40 40)')))



MULTILINESTRING((30 10,10 30,40 40))



For you this would be


 SELECT uuid_generate_v4()                                         AS uuid,
j."deviceId",
st_astext(st_multi(st_linemerge(st_union(j.shape)))) AS multiLine
FROM j
group by date, j."deviceId" ;

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...