Reputation: 5068
I need to store map bounds in a MySQL database. I've spent some time on the docs for geospacial extensions, but it's difficult and in my case unnecessary to learn all related info (WKT, WKB etc.) I just need a way to store a rectangle of coordinates and read it back later. Of course I could also just write the raw coordinates to floats, but if it isn't to complicated, I would prefer to have it in 1 column.
So, what's the simplest possible SQL code for that requirement?
PS: I already use a POINT value in that table, so the extensions are installed and working.
Upvotes: 0
Views: 1435
Reputation: 2388
What you want is called serialization /you can visit link and read about Programming language support/. For example in php exists function called serialize ( php serialize ) which is very helpful in your case. You can use it then store the value and later use php unserialize to read it in php.
I know MyISAM supports some spatial extensions but in my opinion using them is not as flexible as serialization.
Cheers!
I hope it helps. :)
Upvotes: 1
Reputation: 1741
You can store polygons in a geometry column within mysql. This will then let you perform some geometry function on them (if you need to - but doesn't sound like you do)
http://dev.mysql.com/doc/refman/4.1/en/polygon-property-functions.html
SET @poly = 'Polygon((0 0,0 3,3 0,0 0))';
SELECT Area(GeomFromText(@poly));
Edit:
CREATE TABLE `test` (`geo` geometry NOT NULL) ENGINE=MyISAM DEFAULT CHARSET=latin1;
INSERT INTO test SET geo = GeomFromText('Polygon((0 0,0 3,3 0,0 0))');
SELECT asText(geo) FROM `test`;
Try the above sql statements. I create a table with a geometry column, Add the polygon then select the data astext.
Upvotes: 0
Reputation: 875
If you're ONLY interested in storing and retrieving the points of a column, then I'd suggest just dumping the points (comma separated, or however you like) into a BLOB field. If you ever want to use any spatial analysis functions, you may want to look into the Polygon class and use your points to define a polygon for each rectangle of coordinates.
Upvotes: 0