Re: [SQL ] 關於mysql的polygon型態

看板Database作者 (肯先生)時間15年前 (2009/07/23 04:08), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/2 (看更多)
我是在 PHP 版看到的,不過覺得在這兒回比較妥當。 例如: $ID = '1'; $sw = '5 0'; $ne = '0 10'; $center = '2.5 5'; mysql_query("INSERT INTO UserLocation SET ID='$ID',". "location=Envelope(GeomFromText('LineString($sw,$ne)')),". "center=GeomFromText('POINT($center)')"); 取出的時候,例如: $ret = mysql_query("SELECT X(center),Y(center),AsText(location) FORM UserLocation WHERE blah ... "); 先自己在 mysql 底下 try 看看就知道囉~ mysql> INSERT INTO UserLocation SET ID='1',location=Envelope(GeomFromText('LineString(5 0,0 10)')),center=GeomFromText('POINT(2.5 5)'); ERROR 2006 (HY000): MySQL server has gone away No connection. Trying to reconnect... Connection id: 5982834 Current database: xxxx Query OK, 1 row affected, 1 warning (0.00 sec) mysql> SELECT X(center),Y(center),AsText(location) FROM UserLocation WHERE ID='1'; ERROR 2006 (HY000): MySQL server has gone away No connection. Trying to reconnect... Connection id: 5982969 Current database: xxxx +-----------+-----------+----------------------------------+ | X(center) | Y(center) | AsText(location) | +-----------+-----------+----------------------------------+ | 2.5 | 5 | POLYGON((0 0,5 0,5 10,0 10,0 0)) | +-----------+-----------+----------------------------------+ 1 row in set (0.00 sec) mysql> 所以一樣的道理,你要直接 INSERT polygon 的資料進去,那就是 INSERT INTO UserLocation SET ID=1, location=GeomFromText('POLYGON(0 0,5 0,5 10,0 10,0 0)') ※ 引述《caifu (C將。)》之銘言: : ※ [本文轉錄自 Database 看板] : 作者: caifu (C將。) 看板: Database : 標題: [SQL ] 關於mysql的polygon型態 : 時間: Wed Jul 22 23:39:37 2009 : 我的問題是 : 在mysql中polygon型態是長什麼樣子? : 也就是說我要insert資料進去的時候 : php那邊要怎麼寫? : 相對上select時我也搞不懂讀出來會長什麼樣子 : 該怎麼得到一個一個點的位置資訊? : 網路上相關的資訊真是少之又少 : 我試過去抓php的polygon class來試試 : 試過的感覺也不是我要的東西 : 不曉得板上大大有沒有寫過相關程式可以分享一下經驗的 : 感謝! ^^ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.166.128.203 ※ 編輯: KC73 來自: 118.166.128.203 (07/23 04:12)

07/23 23:39, , 1F
非常感謝你,我後來有成功了!! 感謝!! ^^
07/23 23:39, 1F
文章代碼(AID): #1APt7Fur (Database)
文章代碼(AID): #1APt7Fur (Database)