Skip to content

Instantly share code, notes, and snippets.

@itayher
Last active November 19, 2015 14:11
Show Gist options
  • Save itayher/336b2d1e7d354c9fc448 to your computer and use it in GitHub Desktop.
Save itayher/336b2d1e7d354c9fc448 to your computer and use it in GitHub Desktop.
How to create geo in backand.
1. Create a new query.
Give it a name and save.
2. In text enter table creation script
Example:
CREATE TABLE `nodes` (
`id` int(11) PRIMARY KEY,
`geom` geometry NOT NULL,
`user` varchar(50) DEFAULT NULL,
`version` int(11) DEFAULT NULL,
`timestamp` varchar(20) DEFAULT NULL,
`uid` int(11) DEFAULT NULL,
`changeset` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1
3. Run query.
4. Enter to any object in your model, and run "Sync from database"
5. Check you have your new object.
REMARK: geo type will be display as "String" but in DB it's saved as GEO.
==================================
How to add data?
==================================
Best way is to wrap geo data with text:
INSERT INTO nodes VALUES (1, ST_GeomFromText('POINT(1 1)'), 'sss', 1, sysdate(), 1, 2);
==================================
How to query geo function?
==================================
1. Create a new query, give it a name and save it.
2. Switch to SQL mode.
3. Write SQL query with geo:
Ex1 :
Select ST_DISTANCE(geom, POINT(2,2))
FROM nodes
Ex2: find point in a radius
Select *
FROM nodes
WHERE ST_DISTANCE(geom, POINT({{lon}},{{lat}})) < 50
Select ST_DISTANCE(geom, POINT({{lon}},{{lat}}))
FROM nodes
More examples can be found here:
http://dev.mysql.com/doc/refman/5.6/en/spatial-relation-functions-object-shapes.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment