1 / 25

Models de dades espacials. Bases de dades espacials

Models de dades espacials. Bases de dades espacials. Fonaments de Cartografia i Sistemes d’Informació Geogràfica. Bases de dades amb suport espacial (vectorial). Recordatori: Model integrat:

zorina
Download Presentation

Models de dades espacials. Bases de dades espacials

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Models de dades espacials.Bases de dades espacials Fonaments de Cartografia i Sistemes d’Informació Geogràfica

  2. Bases de dades amb suport espacial (vectorial) • Recordatori: Model integrat: • Un gestor de bases de dades relacionals incorpora tipus de dades, operadors, funcions i índexs per treballar amb les geometries de les dades vectorials • En contraposició, el model híbrid gestiona per separat atributs i geometries • Exemples: • MySQL, Spatial Extensions (opensource) • PostgreSQL i PostGIS (opensource) • Oracle Spatial

  3. MySQL: tipus geomètrics • Geometry (non-instantiable) • Point (instantiable) • Curve (non-instantiable) • LineString (instantiable) • Line • LinearRing • Surface (non-instantiable) • Polygon (instantiable) • GeometryCollection (instantiable) • MultiPoint (instantiable) • MultiCurve (non-instantiable) • MultiLineString (instantiable) • MultiSurface (non-instantiable) • MultiPolygon (instantiable)

  4. MySQL: creació d’una taula CREATE TABLE illes ( codi integer, nom varchar(50), … geometria GEOMETRY );

  5. MySQL: Representació de geometries • Valors: • Un punt: POINT(15 20) • Una línia amb 4 punts: LINESTRING(0 0, 10 10, 20 25, 50 60) • Un polígon amb un anell exterior i un altre interior: POLYGON( (0 0,10 0,10 10,0 10,0 0), (5 5,7 5,7 7,5 7, 5 5) )

  6. MySQL: operadors espacials (I) • Buffer(g,d) • Difference(g1,g2) • Intersection(g1,g2) • SymDifference(g1,g2) • Union(g1,g2) NOTA: Operacions referides al Minimum Bounding Rectangle (MBR)

  7. MySQL: operadors espacials (II) • Distance(g1,g2) • Contains(g1,g2) • Crosses(g1,g2) • Disjoint(g1,g2) • Equals(g1,g2) • Intersects(g1,g2) • Overlaps(g1,g2) • Related(g1,g2,pattern_matrix) • Touches(g1,g2) • Within(g1,g2)

  8. MySQL: indexació • Podem definir un índex espacial sobre una columna de tipus geomètric per accelerar els accessos • CREATE SPATIAL INDEX sp_index ON carrers(geometria); • Utilitza arbre R

  9. Tipus geomètric Tamany d’emmag. Representació Descripció Point 16 bytes (x,y) Un punt en l’espai Line 32 bytes ((x1,y1),(x2,y2)) Una línia entre dos punts Lseg 32 bytes ((x1,y1),(x2,y2)) Un segment de línia entre dos punts Box 32 bytes ((x1,y1),(x2,y2)) Un rectangle definit per dos vèrtexs oposats Path 4+32n bytes ((x1,y1),...) Un seguit desegments de línia (tancat) Path 4+32n bytes [(x1,y1),...] Un seguit desegments de línia (obert) Polygon 4+32n bytes ((x1,y1),...) Polígon (similar a un path tancat) Circle 24 bytes <(x,y),r> Cercle (definit pel centre i el radi) PostgreSQL: tipus de dades geomètrics

  10. PostgreSQL: índex espacial • Podem definir un índex espacial sobre una columna de tipus geomètric per accelerar els accessos • Per fer-ho s’utilitza l’arbre R • Exemple: • CREATE INDEX name ON table USING RTREE (column);

  11. Funció Retorna Descripció Exemple area(object) double precision area of item area(box '((0,0),(1,1))') box(box, box) box intersection box box(box '((0,0),(1,1))',box '((0.5,0.5),(2,2))') center(object) point center of item center(box '((0,0),(1,2))') diameter(circle) double precision diameter of circle diameter(circle '((0,0),2.0)') height(box) double precision vertical size of box height(box '((0,0),(1,1))') Isclosed(path) boolean a closed path? isclosed(path '((0,0),(1,1),(2,0))') isopen(path) boolean an open path? isopen(path '[(0,0),(1,1),(2,0)]') length(object) double precision length of item length(path '((-1,0),(1,0))') pclose(path) path convert path to closed popen(path '[(0,0),(1,1),(2,0)]') npoint(path) int4 number of points npoints(path '[(0,0),(1,1),(2,0)]') popen(path) path convert path to open path popen(path '((0,0),(1,1),(2,0))') radius(circle) double precision radius of circle radius(circle '((0,0),2.0)') width(box) double precision horizontal size width(box '((0,0),(1,1))') PostgreSQL: funcions geomètriques

  12. Operador Descripció Exemple + Translation box '((0,0),(1,1))' + point '(2.0,0)' - Translation box '((0,0),(1,1))' - point '(2.0,0)' * Scaling/rotation box '((0,0),(1,1))' * point '(2.0,0)' / Scaling/rotation box '((0,0),(2,2))' / point '(2.0,0)' # Intersection '((1,-1),(-1,1))' # '((1,1),(-1,-1))' # Number of points in polygon # '((1,0),(0,1),(-1,0))' ## Point of closest proximity point '(0,0)' ## lseg '((2,0),(0,2))' && Overlaps? box '((0,0),(1,1))' && box '((0,0),(2,2))' &< Overlaps to left? box '((0,0),(1,1))' &< box '((0,0),(2,2))' &> Overlaps to right? box '((0,0),(3,3))' &> box '((0,0),(2,2))' <-> Distance between circle '((0,0),1)' <-> circle '((5,0),1)' << Left of? circle '((0,0),1)' << circle '((5,0),1)' <^ Is below? circle '((0,0),1)' <^ circle '((0,5),1)' >> Is right of? circle '((5,0),1)' >> circle '((0,0),1)' >^ Is above? circle '((0,5),1)' >^ circle '((0,0),1)' ?# Intersects or overlaps lseg '((-1,0),(1,0))' ?# box '((-2,-2),(2,2))'; ?- Is horizontal? point '(1,0)' ?- point '(0,0)' ?-| Is perpendicular? lseg '((0,0),(0,1))' ?-| lseg '((0,0),(1,0))' @-@ Length or circumference @-@ path '((0,0),(1,0))' ?| Is vertical? point '(0,1)' ?| point '(0,0)' ?|| Is parallel? lseg '((-1,0),(1,0))' ?|| lseg '((-1,2),(1,2))' @ Contained or on point '(1,1)' @ circle '((0,0),2)' @@ Center of @@ circle '((0,0),10)' ~= Same as polygon '((0,0),(1,1))' ~= polygon '((1,1),(0,0))' PostgreSQL: operadors geomètrics

  13. PostGIS • És un paquet que dóna major suport per treballar amb informació geogràfica a PostgreSQL

  14. Oracle: Oracle Spatial • Oracle Spatial és un paquet d’Oracle que dóna suport per a dades espacials

  15. Oracle Spatial: tipus geomètric • Una columna que ha d’emmagatzemar les geometries es declara amb el tipus • MDSYS.SDO_GEOMETRY • La figura mostra les diferents geometries soportades en Oracle Spatial

  16. Oracle Spatial: Exemple • Àrees de distribució de 4 tipus de refrescos de cola diferents

  17. Oracle Spatial: Creació de la taula CREATE TABLE cola_markets ( mkt_id NUMBER PRIMARY KEY, name VARCHAR2(32), shape MDSYS.SDO_GEOMETRY);

  18. Oracle Spatial: Inserció de dades • A l’hora de fer una inserció d’un element (mercat de cola) a la BD, s’han de definir una sèrie de paràmetres referents a la geometria • Entre d’altres: • Tipus de geometria: un codi de 4 dígits. Per exemple 2003 és un polígon en 2D, 3002 és una línia en 3D, o 4001 un punt en 4D • Sistema de referència espacial • Llista de coordenades amb la seva descripció

  19. Oracle Spatial: Inserció de dades INSERT INTO cola_markets VALUES(1,’cola_a’, MDSYS.SDO_GEOMETRY( 2003, -- 2-dimensional polygon NULL, NULL, MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,3), -- one rectangle (1003 = exterior) MDSYS.SDO_ORDINATE_ARRAY(1,1, 5,7) -- only 2 points needed to -- define rectangle (lower left and upper right) with -- Cartesian-coordinate data )); INSERT INTO cola_markets VALUES(2,’cola_b’, MDSYS.SDO_GEOMETRY( 2003, -- 2-dimensional polygon NULL, NULL, MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,1), -- one polygon (exterior polygon ring) MDSYS.SDO_ORDINATE_ARRAY(5,1, 8,1, 8,6, 5,7, 5,1) ));

  20. Oracle Spatial: Inserció de dades INSERT INTO cola_markets VALUES(3,’cola_c’, MDSYS.SDO_GEOMETRY( 2003, -- 2-dimensional polygon NULL, NULL, MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,1), -- one polygon (exterior polygon ring) MDSYS.SDO_ORDINATE_ARRAY(3,3, 6,3, 6,5, 4,5, 3,3) ) ); INSERT INTO cola_markets VALUES(4,’cola_d’, MDSYS.SDO_GEOMETRY( 2003, -- 2-dimensional polygon NULL, NULL, MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,4), -- one circle MDSYS.SDO_ORDINATE_ARRAY(8,7, 10,9, 8,11) ) );

  21. Oracle Spatial: índex espacial • Abans de crear un índex sobre una columna geometria (‘shape’ al nostre exemple), cal prèviament omplir unes metadades (a la taula USER_SDO_GEOM_METADATA): INSERT INTO USER_SDO_GEOM_METADATA VALUES ( ’cola_markets’, ’shape’, MDSYS.SDO_DIM_ARRAY( -- 20X20 grid MDSYS.SDO_DIM_ELEMENT(’X’, 0, 20, 0.005), MDSYS.SDO_DIM_ELEMENT(’Y’, 0, 20, 0.005) ), NULL -- SRID );

  22. Oracle Spatial: índex espacial • Ara ja es pot crear l’índex sobre la columna ‘shape’ • Pot utilitzar-se un índex amb arbre R: CREATE INDEX cola_spatial_idx ON cola_markets(shape) INDEXTYPE IS MDSYS.SPATIAL_INDEX; • També es podria definir (amb altres paràmetres) un arbre quaternari (quadtree), amb cel·les de tamany fixe o variable

  23. Oracle Spatial: exemples de consultes espacials -- Return the topological intersection of two geometries. SELECT SDO_GEOM.SDO_INTERSECTION(c_a.shape, c_c.shape, 0.005) FROM cola_markets c_a, cola_markets c_c WHERE c_a.name = 'cola_a' AND c_c.name = 'cola_c'; -- Do two geometries have any spatial relationship? SELECT SDO_GEOM.RELATE(c_b.shape, 'anyinteract', c_d.shape, 0.005) FROM cola_markets c_b, cola_markets c_d WHERE c_b.name = 'cola_b' AND c_d.name = 'cola_d'; -- Return the areas of all cola markets. SELECT name, SDO_GEOM.SDO_AREA(shape, 0.005) FROM cola_markets; -- Return the area of just cola_a. SELECT c.name, SDO_GEOM.SDO_AREA(c.shape, 0.005) FROM cola_markets c WHERE c.name = 'cola_a'; -- Return the distance between two geometries. SELECT SDO_GEOM.SDO_DISTANCE(c_b.shape, c_d.shape, 0.005) FROM cola_markets c_b, cola_markets c_d WHERE c_b.name = 'cola_b' AND c_d.name = 'cola_d';

  24. Oracle Spatial: SDOAPI • JDBC és una llibreria que permet des de classes Java accedir a les dades d’una base de dades relacionals i executar-hi sentències SQL • Problema: JDBC és estàndard i no té suport per a les dades geomètriques • Solució: Oracle proporciona la llibreria SDOAPI, que estén JDBC amb els tipus geomètrics d’Oracle

  25. Referències • MySQL: • http://www.mysql.com/ • PostgreSQL: • http://www.postgresql.org/ • PostGIS • http://postgis.refractions.net • Oracle Spatial: • http://www.oracle.com/technology/products/spatial/index.html

More Related