MySQL and splitting spacial data -


i have mysql table using storing of latitude , longitude. coordinates defined 'geometry' type column , can contain number of coordinate pairs.

when run code, conversion of geometry type text should able parse out:

select st_astext(st_exteriorring(c.coordinate))         `app_coordinate` c, app_type_coordinate tc          c.idtypecoord = tc.idtypecoord              , tc.description="safezone"; 

i following result:

linestring(-17.386557 -66.150796,-17.388676 -66.150335,-17.388727 -66.14952,-17.385963 -66.147642,-17.386557 -66.150796) linestring(-17.388043 -66.157421,-17.387351 -66.154347,-17.391524 -66.153496,-17.3921 -66.156664,-17.388043 -66.157421) linestring(-17.389281 -66.1413,-17.387155 -66.141837,-17.386763 -66.142888,-17.389566 -66.142929,-17.389281 -66.1413) linestring(-17.389914 -66.143621,-17.390695 -66.143275,-17.390262 -66.1409,-17.389487 -66.141172,-17.389914 -66.143621) 

each linestring row has set of coordinate pairs, need split. first pair #1, second pair #2, etc. thing is, have number of pairs.

what need able split each linestring pairs , store in variable, pair1_x, pair1_y, pair2_x, pair2_y, pair3_x... though won't know how many pairs exist , have 2 delimeters...a space between coordinates , comma between pairs.

here did solution: modified original statement couple of replace() statements remove text each row, used group_concat() statement concatenate multiple rows 1 row, , added starting , trailing brackets (for formatting) concat() statement.

set group_concat_max_len = 2048;  select concat('[', replace(replace(group_concat(distinct(st_astext(st_exteriorring(c.coordinate))), ''), "linestring(", ""), ")", ""), ']') punto     `app_coordinate` c, app_type_coordinate tc      c.idtypecoord = tc.idtypecoord          , tc.description="safezone"; 

Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -