Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error while inserting values into a MySQL multipolygon data type field

Tags:

mysql

spatial

My understanding of the multipolygon field is - a field that can hold information about multiple polygons in a single cell.

My table structure is -

CREATE TABLE `test_table` (
  `key` int(11) NOT NULL AUTO_INCREMENT,
  `selected_polygon` multipolygon DEFAULT NULL,
  PRIMARY KEY (`key`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

I am trying to insert the following data into a multipolygon field -

SET @g ='MULTIPOLYGON(((45.55215127678357 -122.65701296506451, 
45.52329405876074 -122.63572695432232, 
45.52473727138698 -122.56156923947856, 
45.54397656857749- 122.56088259397076, 
45.559363267325914 -122.60345461545514, 
45.56224780438123 -122.65220644650982, 
45.55215127678357 -122.65701296506451)))';

INSERT INTO test_table(selected_polygon) VALUES (GeomFromText(@g));

I get the following the error every time I tried to execute the above statement -

Error Code: 3037. Invalid GIS data provided to function st_geometryfromtext.

like image 246
codejunkie Avatar asked Oct 24 '25 19:10

codejunkie


1 Answers

When you look at your data, there is a subtle error that's hard to spot.

SET @g ='MULTIPOLYGON(((45.55215127678357 -122.65701296506451, 
45.52329405876074 -122.63572695432232, 
45.52473727138698 -122.56156923947856, 
45.54397656857749  -122.56088259397076,  
45.559363267325914 -122.60345461545514, /* this line had - in wrong place */
45.56224780438123 -122.65220644650982, 
45.55215127678357 -122.65701296506451)))';

Please use the above.

like image 72
e4c5 Avatar answered Oct 26 '25 10:10

e4c5