This is a read-only copy of the MariaDB Knowledgebase generated on 2024-11-14. For the latest, interactive version please visit https://mariadb.com/kb/.

GEOMETRY

Spiegazione

MariaDB fornisce un modo standard per creare colonne spaziali per i tipi geometrici, per esempio, con CREATE TABLE o ALTER TABLE. Attualmente, le colonne spaziali sono supportate dalle tabelle MyISAM, InnoDB, NDB e ARCHIVE. Si vedano anche le note sugli indici spaziali, alla pagina SPATIAL.

Il tipo di base per tutte le geometrie è GEOMETRY, ma può essere più specifico. I seguenti tipi sono supportati:

Tipi geometrici
POINT
LINESTRING
POLYGON
MULTIPOINT
MULTILINESTRING
MULTIPOLYGON
GEOMETRYCOLLECTION
GEOMETRY

Esempi

Nota: Per chiarezza, negli esempi seguenti, viene utilizzato un solo tipo geometrico per ogni tabella. Ma una riga può contenere diversi tipi. Ad esempio:

CREATE TABLE oggetto (formaA POLYGON, formaB LINESTRING);

POINT

CREATE TABLE punto_gis  (g POINT);
SHOW FIELDS FROM punto_gis;
INSERT INTO gis_point VALUES
    (PointFromText('POINT(10 10)')),
    (PointFromText('POINT(20 10)')),
    (PointFromText('POINT(20 20)')),
    (PointFromWKB(AsWKB(PointFromText('POINT(10 20)'))));

LINESTRING

CREATE TABLE riga_gis  (g LINESTRING);
INSERT INTO riga_gis VALUES
SHOW FIELDS FROM gis_line;
    (LineFromText('LINESTRING(0 0,0 10,10 0)')),
    (LineStringFromText('LINESTRING(10 10,20 10,20 20,10 20,10 10)')),
    (LineStringFromWKB(AsWKB(LineString(Point(10, 10), Point(40, 10)))));

POLYGON

CREATE TABLE poligono_gis   (g POLYGON);
SHOW FIELDS FROM poligono_gis;
INSERT INTO gis_polygon VALUES
    (PolygonFromText('POLYGON((10 10,20 10,20 20,10 20,10 10))')),
    (PolyFromText('POLYGON((0 0,50 0,50 50,0 50,0 0), (10 10,20 10,20 20,10 20,10 10))')),
    (PolyFromWKB(AsWKB(Polygon(LineString(Point(0, 0), Point(30, 0), Point(30, 30), Point(0, 0))))));

MULTIPOINT

CREATE TABLE multi_point_gis (g MULTIPOINT);
SHOW FIELDS FROM multi_point_gis;
INSERT INTO gis_multi_point VALUES
    (MultiPointFromText('MULTIPOINT(0 0,10 10,10 20,20 20)')),
    (MPointFromText('MULTIPOINT(1 1,11 11,11 21,21 21)')),
    (MPointFromWKB(AsWKB(MultiPoint(Point(3, 6), Point(4, 10)))));

MULTILINESTRING

CREATE TABLE multiriga_gis (g MULTILINESTRING);
SHOW FIELDS FROM multiriga_gis;
INSERT INTO gis_multi_line VALUES
    (MultiLineStringFromText('MULTILINESTRING((10 48,10 21,10 0),(16 0,16 23,16 48))')),
    (MLineFromText('MULTILINESTRING((10 48,10 21,10 0))')),
    (MLineFromWKB(AsWKB(MultiLineString(LineString(Point(1, 2), Point(3, 5)), LineString(Point(2, 5), Point(5, 8), Point(21, 7))))));

MULTIPOLYGON

CREATE TABLE gis_multi_polygon  (g MULTIPOLYGON);
SHOW FIELDS FROM multipoligono_gis;
INSERT INTO multipoligono_gis VALUES
    (MultiPolygonFromText('MULTIPOLYGON(((28 26,28 0,84 0,84 42,28 26),(52 18,66 23,73 9,48 6,52 18)),((59 18,67 18,67 13,59 13,59 18)))')),
    (MPolyFromText('MULTIPOLYGON(((28 26,28 0,84 0,84 42,28 26),(52 18,66 23,73 9,48 6,52 18)),((59 18,67 18,67 13,59 13,59 18)))')),
    (MPolyFromWKB(AsWKB(MultiPolygon(Polygon(LineString(Point(0, 3), Point(3, 3), Point(3, 0), Point(0, 3)))))));

GEOMETRYCOLLECTION

CREATE TABLE collezione_geometrica_gis  (g GEOMETRYCOLLECTION);
SHOW FIELDS FROM collezione_geometrica_gis;
INSERT INTO gis_geometrycollection VALUES
    (GeomCollFromText('GEOMETRYCOLLECTION(POINT(0 0), LINESTRING(0 0,10 10))')),
    (GeometryFromWKB(AsWKB(GeometryCollection(Point(44, 6), LineString(Point(3, 6), Point(7, 9)))))),
    (GeomFromText('GeometryCollection()')),
    (GeomFromText('GeometryCollection EMPTY'));

GEOMETRY

CREATE TABLE gis_geometry (g GEOMETRY);
SHOW FIELDS FROM geometria;
INSERT into geometria SELECT * FROM punto_gis;
INSERT into geometria SELECT * FROM riga_gis;
INSERT into geometria SELECT * FROM poligono_gis;
INSERT into geometria SELECT * FROM multi_point_gis;
INSERT into geometria SELECT * FROM multiriga_gis;
INSERT into geometria SELECT * FROM multipoligono_gis;
INSERT into geometria SELECT * FROM collezione_geometrica_gis;
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.