2013-03-16 47 views
5

我試圖在我的MySQL數據庫中插入一個多邊形的地理座標。我有一個名爲類型的多邊形多邊形領域,我已經試過所有運行這些查詢,但繼續獲得SQL語法錯誤:將座標插入到MySQL中 - PolyFromText SQL語法錯誤/返回null

SET @g = 'POLYGON((-74.13591384887695 40.93750722242824,-74.13522720336914 40.929726129575016,-74.15102005004883 40.9329683629703,-74.14329528808594 40.94256444133327))'; 
INSERT INTO 'zones' ('polygon') VALUES (PolyFromText(@g)); 

INSERT INTO 'zones' ('polygon') VALUES (PolyFromText('POLYGON((-74.13591384887695 40.93750722242824,-74.13522720336914 40.929726129575016,-74.15102005004883 40.9329683629703,-74.14329528808594 40.94256444133327))')); 

INSERT INTO 'zones' ('polygon') VALUES (PolyFromText('POLYGON((-74.13591384887695 40.93750722242824,-74.13522720336914 40.929726129575016,-74.15102005004883 40.9329683629703,-74.14329528808594 40.94256444133327))', 0)); 

上次查詢是使用phpmyadmins自己的地理空間工具生成的,並返回「Column」多邊形「不能爲null」。任何幫助表示讚賞!

+0

我試過PolygonFromText,PolyFromText和GeomFromText的 - 既不是他們的工作。 – Yev 2013-03-16 19:05:04

回答

25

原因是因爲null退出最後一點不等於第一個點,是符合OSGeo標準WKT的條件,在某些實現中這是允許的,但是mysql對它是嚴格的,在SQL Server中文檔更好地解釋條件。

看到這個

SELECT Dimension(GeomFromText('POLYGON((-74.13591384887695 40.93750722242824,-74.13522720336914 40.929726129575016,-74.15102005004883 40.9329683629703,-74.14329528808594 40.94256444133327,-74.13591384887695 40.93750722242824)))')); 

的mysql的文檔

http://dev.mysql.com/doc/refman/5.0/en/gis-class-polygon.html

DOC SQLSERVER

http://msdn.microsoft.com/en-us/library/bb964739(v=sql.105).aspx

+0

謝謝!我在最後重複了這一點,它工作了! – Yev 2013-03-16 19:24:28

+1

你真棒,m8! – nurgasemetey 2015-03-12 15:09:51