# Creating the spatial objects USE test; CREATE TABLE gis_point (fid INTEGER NOT NULL PRIMARY KEY, g POINT); CREATE TABLE gis_linestring (fid INTEGER NOT NULL PRIMARY KEY, g LINESTRING); CREATE TABLE gis_polygon (fid INTEGER NOT NULL PRIMARY KEY, g POLYGON); CREATE TABLE gis_multi_point (fid INTEGER NOT NULL PRIMARY KEY, g MULTIPOINT); CREATE TABLE gis_multi_linestring (fid INTEGER NOT NULL PRIMARY KEY, g MULTILINESTRING); CREATE TABLE gis_multi_polygon (fid INTEGER NOT NULL PRIMARY KEY, g MULTIPOLYGON); CREATE TABLE gis_geometrycollection (fid INTEGER NOT NULL PRIMARY KEY, g GEOMETRYCOLLECTION); # Inserting POINT Geometry Values INSERT INTO gis_point VALUES (101, ST_POINTFROMTEXT('POINT(0 0)')), (102, ST_POINTFROMTEXT('POINT(1 0)')), (103, ST_POINTFROMTEXT('POINT(0 1)')), (104, ST_POINTFROMTEXT('POINT(1 1)')), (105, ST_POINTFROMTEXT('POINT(-1 1)')); INSERT INTO gis_point VALUES (106, ST_POINTFROMWKB(POINT(0,0))), (107, ST_POINTFROMWKB(POINT(10,0))), (108, ST_POINTFROMWKB(POINT(0,10))), (109, ST_POINTFROMWKB(POINT(-10,0))), (110, ST_POINTFROMWKB(POINT(0,-10))); INSERT INTO gis_point VALUES (111, ST_POINTFROMWKB(ST_ASWKB(ST_POINTFROMTEXT('POINT(1 1)')))), (112, ST_POINTFROMWKB(ST_ASWKB(ST_POINTFROMTEXT('POINT(1e308 1e308)')))), (113, ST_POINTFROMWKB(ST_ASWKB(ST_POINTFROMTEXT('POINT(1e308 -1e308)')))), (114, ST_POINTFROMWKB(ST_ASWKB(ST_POINTFROMTEXT('POINT(-1e308 1e308)')))), (115, ST_POINTFROMWKB(ST_ASWKB(ST_POINTFROMTEXT('POINT(-1e308 -1e308)')))); # Inserting LINESTRING Geometry Values INSERT INTO gis_linestring VALUES (201, ST_LINEFROMTEXT('LINESTRING(0 0,5 5)')), (202, ST_LINEFROMTEXT('LINESTRING(0 0,2 2,4 4)')), (203, ST_LINEFROMTEXT('LINESTRING(0 0,5 5,10 10)')); INSERT INTO gis_linestring VALUES (204, ST_LINESTRINGFROMTEXT('LINESTRING(10 10,5 5)')), (205, ST_LINESTRINGFROMTEXT('LINESTRING(0 0,12 12,24 24)')), (206, ST_LINESTRINGFROMTEXT('LINESTRING(0 0,50 50,100 100)')); INSERT INTO gis_linestring VALUES (207, ST_LINEFROMWKB(LINESTRING(POINT(0,0), POINT(5,5)))), (208, ST_LINEFROMWKB(LINESTRING(POINT(0,0), POINT(-5,-5), POINT(-10,10)))), (209, ST_LINEFROMWKB(LINESTRING(POINT(0,0), POINT(2,2), POINT(4,4), POINT(6,6), POINT(8,8)))); INSERT INTO gis_linestring VALUES (210, ST_LINESTRINGFROMWKB(LINESTRING(POINT(0,0), POINT(5,5)))), (211, ST_LINESTRINGFROMWKB(LINESTRING(POINT(0,0), POINT(-50,-50), POINT(10,-10)))), (212, ST_LINESTRINGFROMWKB(LINESTRING(POINT(0,0), POINT(1e308,1e308), POINT(1e308,-1e308)))); INSERT INTO gis_linestring VALUES (213, ST_LINEFROMWKB(ST_ASWKB(ST_LINEFROMTEXT('LINESTRING(1e308 1e308,1e308 -1e308)')))), (214, ST_LINEFROMWKB(ST_ASWKB(ST_LINEFROMTEXT('LINESTRING(1 1,2 2,3 3,4 4,5 5,6 6,7 7,8 8,9 9)')))), (215, ST_LINESTRINGFROMWKB(ST_ASWKB(ST_LINESTRINGFROMTEXT('LINESTRING(10 10,10 -10,-10 -10,-10 10,10 10)')))); # Inserting POLYGON Geometry Values INSERT INTO gis_polygon VALUES (301, ST_POLYFROMTEXT('POLYGON((0 0,0 5,5 5,0 0))')), (302, ST_POLYFROMTEXT('POLYGON((0 0,0 5,5 5,5 0,0 0))')), (303, ST_POLYFROMTEXT('POLYGON((0 0,0 10,10 10,10 0,0 0))')); INSERT INTO gis_polygon VALUES (304, ST_POLYGONFROMTEXT('POLYGON((0 0,0 50,50 50,50 0,0 0))')), (305, ST_POLYGONFROMTEXT('POLYGON((0 0,0 10,10 10,10 0,0 0,0 0,0 0),(4 4,4 6,6 6,6 4,4 4))')), (306, ST_POLYGONFROMTEXT('POLYGON((0 0,0 10,10 10,10 0,0 0,0 0,0 0),(2 2,2 4,4 4,4 2,2 2),(6 6,6 8,8 8,8 6,6 6))')); INSERT INTO gis_polygon VALUES (307, ST_POLYFROMWKB(POLYGON(LINESTRING(POINT(0,0), POINT(0,5), POINT(5,5), POINT(0,0))))), (308, ST_POLYFROMWKB(POLYGON(LINESTRING(POINT(0,0), POINT(0,15), POINT(15,15), POINT(15,0), POINT(0,0))))), (309, ST_POLYFROMWKB(POLYGON(LINESTRING(POINT(0,0), POINT(0,10), POINT(10,10), POINT(10,0), POINT(0,0)), LINESTRING(POINT(4,4), POINT(4,6), POINT(6,6), POINT(6,4), POINT(4,4))))); INSERT INTO gis_polygon VALUES (310, ST_POLYGONFROMWKB(POLYGON(LINESTRING(POINT(0,0), POINT(0,5), POINT(5,5), POINT(0,0))))), (311, ST_POLYGONFROMWKB(POLYGON(LINESTRING(POINT(10,10), POINT(10,15), POINT(15,15), POINT(15,10), POINT(10,10))))), (312, ST_POLYGONFROMWKB(POLYGON(LINESTRING(POINT(10,10), POINT(10,20), POINT(20,20), POINT(20,10), POINT(10,10)), LINESTRING(POINT(14,14), POINT(14,16), POINT(16,16), POINT(16,14), POINT(14,14))))); INSERT INTO gis_polygon VALUES (313, ST_POLYFROMWKB(ST_ASWKB(ST_POLYFROMTEXT('POLYGON((0 0,0 10,10 10,10 0,0 0,0 0,5 5,0 0))')))), (314, ST_POLYFROMWKB(ST_ASWKB(ST_POLYGONFROMTEXT('POLYGON((10 0,10 10,0 10,-10 10,-10 0,-10 -10,0 10,10 -10,10 0))')))), (315, ST_POLYGONFROMWKB(ST_ASWKB(ST_POLYGONFROMTEXT('POLYGON((0 0,0 10,10 10,10 0,0 0,0 0,0 0),(2 2,2 4,4 4,4 2,2 2),(6 6,6 8,8 8,8 6,6 6))')))); # Inserting MULTIPOINT Geometry Values INSERT INTO gis_multi_point VALUES (401, ST_GEOMFROMTEXT('MULTIPOINT(0 0)')), (402, ST_GEOMFROMTEXT('MULTIPOINT(0 0,2 2,4 4)')), (403, ST_GEOMFROMTEXT('MULTIPOINT(0 0,5 5,10 10)')); INSERT INTO gis_multi_point VALUES (404, ST_GEOMFROMTEXT('MULTIPOINT(0 0,100 100)')), (405, ST_GEOMFROMTEXT('MULTIPOINT(0 0,1e308 1e308)')), (406, ST_GEOMFROMTEXT('MULTIPOINT(1e308 1e308,1e308 -1e308,-1e308 1e308,-1e308 -1e308)')); INSERT INTO gis_multi_point VALUES (407, ST_GEOMFROMWKB(MULTIPOINT(POINT(0,0)))), (408, ST_GEOMFROMWKB(MULTIPOINT(POINT(0,0), POINT(10,10)))), (409, ST_GEOMFROMWKB(MULTIPOINT(POINT(0,0), POINT(2,2), POINT(4,4), POINT(6,6)))); INSERT INTO gis_multi_point VALUES (410, ST_GEOMFROMWKB(MULTIPOINT(POINT(0,0)))), (411, ST_GEOMFROMWKB(MULTIPOINT(POINT(0,0), POINT(1e308,1e308)))), (412, ST_GEOMFROMWKB(MULTIPOINT(POINT(1e308,1e308), POINT(-1e308,1e308), POINT(1e308,-1e308), POINT(-1e308,-1e308)))); INSERT INTO gis_multi_point VALUES (413, ST_GEOMFROMWKB(ST_ASWKB(ST_GEOMFROMTEXT('MULTIPOINT(0 0)')))), (414, ST_GEOMFROMWKB(ST_ASWKB(ST_GEOMFROMTEXT('MULTIPOINT(0 0,1e308 1e308,-1e308 -1e308)')))), (415, ST_GEOMFROMWKB(ST_ASWKB(ST_GEOMFROMTEXT('MULTIPOINT(1e308 1e308,1e308 -1e308,-1e308 1e308,-1e308 -1e308,1e308 1e308)')))); # Inserting MULTILINESTRING Geometry Values INSERT INTO gis_multi_linestring VALUES (501, ST_GEOMFROMTEXT('MULTILINESTRING((0 0,2 2))')), (502, ST_GEOMFROMTEXT('MULTILINESTRING((0 0,2 2,4 4))')), (503, ST_GEOMFROMTEXT('MULTILINESTRING((0 0,2 2,4 4),(6 6,8 8,10 10))')); INSERT INTO gis_multi_linestring VALUES (504, ST_GEOMFROMTEXT('MULTILINESTRING((0 0,100 100,-100 -100))')), (505, ST_GEOMFROMTEXT('MULTILINESTRING((1e308 1e308,-1e308 -1e308))')), (506, ST_GEOMFROMTEXT('MULTILINESTRING((1e308 1e308,-1e308 -1e308),(1e308 -1e308,-1e308 1e308))')); INSERT INTO gis_multi_linestring VALUES (507, ST_GEOMFROMWKB(MULTILINESTRING(LINESTRING(POINT(0,0), POINT(2,2))))), (508, ST_GEOMFROMWKB(MULTILINESTRING(LINESTRING(POINT(0,0), POINT(12,12), POINT(24,24))))), (509, ST_GEOMFROMWKB(MULTILINESTRING(LINESTRING(POINT(0,0), POINT(2,2), POINT(4,4)), LINESTRING(POINT(6,6), POINT(8,8), POINT(10,10))))); INSERT INTO gis_multi_linestring VALUES (510, ST_GEOMFROMWKB(MULTILINESTRING(LINESTRING(POINT(0,0), POINT(2,2), POINT(4,4))))), (511, ST_GEOMFROMWKB(MULTILINESTRING(LINESTRING(POINT(0,0), POINT(1,1), POINT(2,2))))), (512, ST_GEOMFROMWKB(MULTILINESTRING(LINESTRING(POINT(0,0), POINT(12,12), POINT(24,24)), LINESTRING(POINT(36,36), POINT(48,48), POINT(50,50))))); INSERT INTO gis_multi_linestring VALUES (513, ST_GEOMFROMWKB(ST_ASWKB(ST_GEOMFROMTEXT('MULTILINESTRING((0 0,10 10),(0 10,10 0))')))), (514, ST_GEOMFROMWKB(ST_ASWKB(ST_GEOMFROMTEXT('MULTILINESTRING((0 0,10 10,-10 10,0 0),(0 0,-10 -10,10 -10,0 0))')))), (515, ST_GEOMFROMWKB(ST_ASWKB(ST_GEOMFROMTEXT('MULTILINESTRING((0 0,0 100),(0 0,100 0),(0 0,0 -100),(0 0,-100 0))')))); # Inserting MULTIPOLGYON Geometry Values INSERT INTO gis_multi_polygon VALUES (601, ST_GEOMFROMTEXT('MULTIPOLYGON(((0 0,0 5,5 5,0 0)))')), (602, ST_GEOMFROMTEXT('MULTIPOLYGON(((0 0,0 5,5 5,0 0)),((5 5,5 10,10 10,5 5)))')), (603, ST_GEOMFROMTEXT('MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0,0 0,0 0),(4 4,4 6,6 6,6 4,4 4)))')); INSERT INTO gis_multi_polygon VALUES (604, ST_GEOMFROMTEXT('MULTIPOLYGON(((0 0,0 5,5 5,0 0)))')), (605, ST_GEOMFROMTEXT('MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0,0 0,0 0),(4 4,4 6,6 6,6 4,4 4)),((0 0,0 -2,-2 -2,0 0)))')), (606, ST_GEOMFROMTEXT('MULTIPOLYGON(((0 0,5 5,-5 5,0 0)),((0 0,-5 -5,5 -5,0 0)))')); INSERT INTO gis_multi_polygon VALUES (607, ST_GEOMFROMWKB(MULTIPOLYGON(POLYGON(LINESTRING(POINT(0,0), POINT(5,0), POINT(5,5), POINT(0,5), POINT(0,0)))))), (608, ST_GEOMFROMWKB(MULTIPOLYGON(POLYGON(LINESTRING(POINT(0,0), POINT(10,0), POINT(10,10), POINT(0,10), POINT(0,0)), LINESTRING(POINT(4,4), POINT(4,6), POINT(6,6), POINT(6,4), POINT(4,4)))))), (609, ST_GEOMFROMWKB(MULTIPOLYGON(POLYGON(LINESTRING(POINT(0,0), POINT(5,0), POINT(5,5), POINT(0,5), POINT(0,0))), POLYGON(LINESTRING(POINT(0,0), POINT(-5,0), POINT(-5,-5), POINT(0,-5), POINT(0,0)))))); INSERT INTO gis_multi_polygon VALUES (610, ST_GEOMFROMWKB(MULTIPOLYGON(POLYGON(LINESTRING(POINT(0,0), POINT(-5,0), POINT(-5,-5), POINT(0,-5), POINT(0,0)))))), (611, ST_GEOMFROMWKB(MULTIPOLYGON(POLYGON(LINESTRING(POINT(10,10), POINT(20,10), POINT(20,20), POINT(10,20), POINT(10,10)), LINESTRING(POINT(14,14), POINT(14,16), POINT(16,16), POINT(16,14), POINT(14,14)))))), (612, ST_GEOMFROMWKB(MULTIPOLYGON(POLYGON(LINESTRING(POINT(0,0), POINT(0,10), POINT(10,10), POINT(10,0), POINT(0,0)), LINESTRING(POINT(4,4), POINT(4,6), POINT(6,6), POINT(6,4), POINT(4,4))), POLYGON(LINESTRING(POINT(0,0), POINT(-5,0), POINT(-5,-5), POINT(0,-5), POINT(0,0)))))); INSERT INTO gis_multi_polygon VALUES (613, ST_GEOMFROMWKB(ST_ASWKB(ST_GEOMFROMTEXT('MULTIPOLYGON(((0 0,5 5,5 -5,0 0)),((0 0,-5 5,-5 -5,0 0)))')))), (614, ST_GEOMFROMWKB(ST_ASWKB(ST_GEOMFROMTEXT('MULTIPOLYGON(((0 0,10 10,-10 10,0 0)),((0 0,-10 -10,10 -10,0 0)))')))), (615, ST_GEOMFROMWKB(ST_ASWKB(ST_GEOMFROMTEXT('MULTIPOLYGON(((0 0,5 5,10 0,5 -5,0 0)))')))); # Inserting GEOMETRYCOLLECTION Geometry Values INSERT INTO gis_geometrycollection VALUES (701, ST_GEOMCOLLFROMTEXT('GEOMETRYCOLLECTION(POINT(0 0))')), (702, ST_GEOMCOLLFROMTEXT('GEOMETRYCOLLECTION(POINT(0 0), LINESTRING(0 0,10 10))')), (703, ST_GEOMCOLLFROMTEXT('GEOMETRYCOLLECTION(POINT(5 5), POLYGON((0 0,0 10,10 10,10 0,0 0)))')); INSERT INTO gis_geometrycollection VALUES (704, ST_GEOMETRYCOLLECTIONFROMTEXT('GEOMETRYCOLLECTION(POINT(0 0), LINESTRING(0 0,10 10))')), (705, ST_GEOMETRYCOLLECTIONFROMTEXT('GEOMETRYCOLLECTION(POINT(0 0),' 'LINESTRING(0 0,10 10),' 'POLYGON((0 0,0 10,10 10,10 0,0 0,0 0, 0 0)))')), (706, ST_GEOMETRYCOLLECTIONFROMTEXT('GEOMETRYCOLLECTION(MULTIPOINT(0 0,5 5,10 10),' 'MULTILINESTRING((0 0,10 10),(0 10,10 0)),' 'MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),' '((0 0,-10 0,-10 -10,0 -10,0 0))))')); INSERT INTO gis_geometrycollection VALUES (707, ST_GEOMCOLLFROMWKB(GEOMETRYCOLLECTION(POINT(0,0)))), (708, ST_GEOMCOLLFROMWKB(GEOMETRYCOLLECTION(POINT(0,0), LINESTRING(POINT(0,0), POINT(2,2), POINT(4,4), POINT(6,6), POINT(8,8)), POLYGON(LINESTRING(POINT(0,0), POINT(0,10), POINT(10,10), POINT(10,0), POINT(0,0)), LINESTRING(POINT(4,4), POINT(4,6), POINT(6,6), POINT(6,4), POINT(4,4)))))), (709, ST_GEOMCOLLFROMWKB(GEOMETRYCOLLECTION(MULTIPOINT(POINT(0,0), POINT(5,5), POINT(10,10)), MULTILINESTRING(LINESTRING(POINT(0,0), POINT(2,2), POINT(4,4), POINT(6,6), POINT(8,8)), LINESTRING(POINT(10,10), POINT(5,5), POINT(0,10))), MULTIPOLYGON(POLYGON(LINESTRING(POINT(0,0), POINT(0,10), POINT(10,10), POINT(10,0), POINT(0,0)), LINESTRING(POINT(4,4), POINT(4,6), POINT(6,6), POINT(6,4), POINT(4,4))), POLYGON(LINESTRING(POINT(0,0), POINT(-10,0), POINT(-10,-10), POINT(0,0))))))); INSERT INTO gis_geometrycollection VALUES (710, ST_GEOMETRYCOLLECTIONFROMWKB(GEOMETRYCOLLECTION(POINT(0,0), LINESTRING(POINT(0,0), POINT(100,100))))), (711, ST_GEOMETRYCOLLECTIONFROMWKB(GEOMETRYCOLLECTION(POINT(10,10), LINESTRING(POINT(10,10), POINT(12,12), POINT(14,14), POINT(16,16), POINT(18,18)), POLYGON(LINESTRING(POINT(0,0), POINT(0,10), POINT(10,10), POINT(10,0), POINT(0,0)), LINESTRING(POINT(4,4), POINT(4,6), POINT(6,6), POINT(6,4), POINT(4,4)))))), (712, ST_GEOMETRYCOLLECTIONFROMWKB(GEOMETRYCOLLECTION(MULTIPOINT(POINT(10,10), POINT(15,15), POINT(20,20)), MULTILINESTRING(LINESTRING(POINT(0,0), POINT(2,2), POINT(4,4), POINT(6,6), POINT(8,8)), LINESTRING(POINT(10,10), POINT(5,5), POINT(0,10))), MULTIPOLYGON(POLYGON(LINESTRING(POINT(0,0), POINT(0,10), POINT(10,10), POINT(10,0), POINT(0,0)), LINESTRING(POINT(4,4), POINT(4,6), POINT(6,6), POINT(6,4), POINT(4,4))), POLYGON(LINESTRING(POINT(0,0), POINT(-10,0), POINT(-10,-10), POINT(0,0))))))); INSERT INTO gis_geometrycollection VALUES (713, ST_GEOMCOLLFROMWKB(ST_ASWKB(ST_GEOMCOLLFROMTEXT('GEOMETRYCOLLECTION(' 'POINT(0 0),' 'LINESTRING(0 0,10 10),' 'POLYGON((0 0,0 10,10 10,10 0,0 0)),' 'MULTIPOINT(0 0,2 2,4 4,6 6,8 8,10 10),' 'MULTILINESTRING((0 0,10 10),(0 10,10 0)),' 'MULTIPOLYGON(((0 0,0 5,5 5,5 0,0 0)),((5 5,5 10,10 10,10 5,5 5))))')))); # Creating a table with spatial index column CREATE TABLE geom_index (fid INTEGER NOT NULL PRIMARY KEY, g GEOMETRY NOT NULL, SPATIAL INDEX(g)); # Inserting geometry values INSERT INTO geom_index SELECT * FROM gis_point; INSERT INTO geom_index SELECT * FROM gis_linestring; INSERT INTO geom_index SELECT * FROM gis_polygon; INSERT INTO geom_index SELECT * FROM gis_multi_point; INSERT INTO geom_index SELECT * FROM gis_multi_linestring; INSERT INTO geom_index SELECT * FROM gis_multi_polygon; INSERT INTO geom_index SELECT * FROM gis_geometrycollection; check table geom_index; Table Op Msg_type Msg_text test.geom_index check status OK # Final cleanup DROP TABLE gis_point; DROP TABLE gis_linestring; DROP TABLE gis_polygon; DROP TABLE gis_multi_point; DROP TABLE gis_multi_linestring; DROP TABLE gis_multi_polygon; DROP TABLE gis_geometrycollection; DROP TABLE geom_index;