TerraLib and TerraView Wiki Page

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
wiki:documentation:devguide:geometry_module [2016/01/19 09:08]
gribeiro [Spatial Relationships]
wiki:documentation:devguide:geometry_module [2016/02/12 10:36] (current)
gribeiro [General Concepts]
Line 5: Line 5:
 It is important to notice that this module refers to //**a geometry model to be used in main memory**// and //**it doesn'​t assume any kind of persistence or data storage management**//​. This section explains the basic concepts, design behind this module ad how to use it. It is important to notice that this module refers to //**a geometry model to be used in main memory**// and //**it doesn'​t assume any kind of persistence or data storage management**//​. This section explains the basic concepts, design behind this module ad how to use it.
  
-All the types offered by Geometry module are in the namespace ''​te::​gm''​. Check the [[http://​www.dpi.inpe.br/​terralib5/​codedocs_5.1.0/​d9/​dba/​group__geometry.html|DOxygen ​documentation of this module]], where these and other classes are documented in details.+All the types offered by Geometry module are in the namespace ''​te::​gm''​. Check the [[http://​www.dpi.inpe.br/​terralib5/​codedocs_5.1.0/​d9/​dba/​group__geometry.html|Doxygen ​documentation of this module]], where these and other classes are documented in details.
 ===== General Concepts ===== ===== General Concepts =====
  
Line 14: Line 14:
     * A 1-dimensional geometry is one with a geometric dimension of 1 (one). Curves (lines) are 1-dimensional objects.     * A 1-dimensional geometry is one with a geometric dimension of 1 (one). Curves (lines) are 1-dimensional objects.
     * A 2-dimensional geometry is one with a geometric dimension of 2 (two). Surfaces (polygons) are 2-dimensional objects.     * A 2-dimensional geometry is one with a geometric dimension of 2 (two). Surfaces (polygons) are 2-dimensional objects.
-  * We can have geometries in ℜ2, ℜ3 or ℜ4 coordinate spaces.+  * We can have geometries in ℜ<sup>2</​sup>​, ℜ<sup>3</​sup> ​or ℜ<sup>4</​sup> ​coordinate spaces.
     * The //z// coordinate value not necessarely represents altitude.     * The //z// coordinate value not necessarely represents altitude.
     * The //m// coordinate value represents arbitrary measurement.     * The //m// coordinate value represents arbitrary measurement.
   * The term //ring// is applied to a closed curve (the first and last points are coincident).   * The term //ring// is applied to a closed curve (the first and last points are coincident).
- 
 ===== Geometry Class Hierarchy ===== ===== Geometry Class Hierarchy =====
  
Line 43: Line 42:
  
 <code cpp> <code cpp>
-std::​unique_ptr<​te::​gm::​Point= std::​make_unique<​te::​gm::​Point>​(-54.0, -12.0, 4326);+te::​gm::​Point p(-54.0, -12.0, 4326);
 </​code>​ </​code>​
  
Line 69: Line 68:
  
 <code cpp> <code cpp>
-std::​unique_ptr<​te::​gm::​LineString= std::​make_unique<​te::​gm::​ LineString>​(2, te::​gm::​LineStringType);​+te::​gm::​LineString l(2, te::​gm::​LineStringType);​
    
-l->setPoint(0, -54.0, -12.0); +l.setPoint(0, -54.0, -12.0); 
-l->setPoint(1, -55.0, -13.0);+l.setPoint(1, -55.0, -13.0);
 </​code>​ </​code>​
  
Line 94: Line 93:
  
 <code cpp> <code cpp>
-std::​unique_ptr<​te::​gm::​LinearRing= std::​make_unique<​te::​gm::​LinearRing>​(5, te::​gm::​LineStringType,​ 0);+te::​gm::​LinearRing r(5, te::​gm::​LineStringType,​ 0);
  
-r->setPoint(0, 1, 2); +r.setPoint(0, 1, 2); 
-r->setPoint(1, 1, 7); +r.setPoint(1, 1, 7); 
-r->setPoint(2, 7, 7); +r.setPoint(2, 7, 7); 
-r->setPoint(3, 7, 2); +r.setPoint(3, 7, 2); 
-r->setPoint(4, 1, 2);+r.setPoint(4, 1, 2);
 </​code>​ </​code>​
  
Line 299: Line 298:
 **3.** Does the red line touches the blue one? **3.** Does the red line touches the blue one?
 <code cpp> <code cpp>
-std::​unique_ptr<​te::​gm::​Geometry> ​vermelho( te::​gm::​WKTReader::​read("​LINESTRING (1 5, 1 7, 3 7)") ); +std::​unique_ptr<​te::​gm::​Geometry> ​red( te::​gm::​WKTReader::​read("​LINESTRING (1 5, 1 7, 3 7)") ); 
-std::​unique_ptr<​te::​gm::​Geometry> ​azul( te::​gm::​WKTReader::​read("​LINESTRING (3 5, 1 7)") );+std::​unique_ptr<​te::​gm::​Geometry> ​blue( te::​gm::​WKTReader::​read("​LINESTRING (3 5, 1 7)") );
     ​     ​
-std::cout << "A linha Vermelha toca a Azul? " << std::​boolalpha << vermelho->​touches( ​azul.get() ) << std::end;+bool result = red->​touches( ​blue.get() );
  
 +std::cout << std::​boolalpha << result << std::endl ;
 </​code>​ </​code>​
  
 <code cpp> <code cpp>
-std::​unique_ptr<​te::​gm::​Geometry> ​vermelho( te::​gm::​WKTReader::​read("​LINESTRING (4 5, 4 7, 6 7)") ); +std::​unique_ptr<​te::​gm::​Geometry> ​red( te::​gm::​WKTReader::​read("​LINESTRING (4 5, 4 7, 6 7)") ); 
-std::​unique_ptr<​te::​gm::​Geometry> ​azul( te::​gm::​WKTReader::​read("​LINESTRING (5 5, 5 8)") );+std::​unique_ptr<​te::​gm::​Geometry> ​blue( te::​gm::​WKTReader::​read("​LINESTRING (5 5, 5 8)") );
  
-std::cout << "A linha Vermelha toca a Azul? " << std::​boolalpha << vermelho->​touches( ​azul.get() ) << std::end;+bool result = red->​touches( ​blue.get() );
  
 +std::cout << std::​boolalpha << result << std::endl ;
 </​code>​ </​code>​
  
 <code cpp> <code cpp>
-std::​unique_ptr<​te::​gm::​Geometry> ​vermelho( te::​gm::​WKTReader::​read("​LINESTRING (1 3, 3 4)") ); +std::​unique_ptr<​te::​gm::​Geometry> ​red( te::​gm::​WKTReader::​read("​LINESTRING (1 3, 3 4)") ); 
-std::​unique_ptr<​te::​gm::​Geometry> ​azul( te::​gm::​WKTReader::​read("​LINESTRING (3 4, 5 3)") );+std::​unique_ptr<​te::​gm::​Geometry> ​blue( te::​gm::​WKTReader::​read("​LINESTRING (3 4, 5 3)") );
     ​     ​
-std::​cout ​<< "A linha Vermelha toca a Azul? " ​<< std::​boolalpha << ​vermelho->​touches( azul.get() ) << std::endl;+bool result = red->​touches( blue.get() ); 
 + 
 +std::cout << std::​boolalpha << ​result ​<< std::endl ;
 </​code>​ </​code>​
  
-**3.** Does the polygon ​line touches the blue one?+**3.** Does the red polygon touches the blue one?
 <code cpp> <code cpp>
-std::​unique_ptr<​te::​gm::​Geometry> ​vermelho( te::​gm::​WKTReader::​read("​POLYGON ( (1 0, 1 2, 4 2, 4 0, 1 0) )") ); +std::​unique_ptr<​te::​gm::​Geometry> ​red( te::​gm::​WKTReader::​read("​POLYGON ( (1 0, 1 2, 4 2, 4 0, 1 0) )") ); 
-std::​unique_ptr<​te::​gm::​Geometry> ​azul( te::​gm::​WKTReader::​read("​POLYGON ( (4 0, 4 2, 7 2, 7 0, 4 0) )") );+std::​unique_ptr<​te::​gm::​Geometry> ​blue( te::​gm::​WKTReader::​read("​POLYGON ( (4 0, 4 2, 7 2, 7 0, 4 0) )") );
     ​     ​
-std::​cout ​<< "O poligono Vermelho toca o Azul? " ​<< std::​boolalpha << ​vermelho->​touches( azul.get() ) << std::endl;+bool result = red->​touches( blue.get() ); 
 + 
 +std::cout << std::​boolalpha << ​result ​<< std::endl ;
 </​code>​ </​code>​
   ​   ​
 <code cpp> <code cpp>
-std::​unique_ptr<​te::​gm::​Geometry> ​vermelho( te::​gm::​WKTReader::​read("​POLYGON ( (8 5, 8 7, 11 7, 11 5, 8 5) )") ); +std::​unique_ptr<​te::​gm::​Geometry> ​red( te::​gm::​WKTReader::​read("​POLYGON ( (8 5, 8 7, 11 7, 11 5, 8 5) )") ); 
-std::​unique_ptr<​te::​gm::​Geometry> ​azul( te::​gm::​WKTReader::​read("​POLYGON ( (11 6, 13 8, 15 6, 13 4, 11 6) )") ); +std::​unique_ptr<​te::​gm::​Geometry> ​blue( te::​gm::​WKTReader::​read("​POLYGON ( (11 6, 13 8, 15 6, 13 4, 11 6) )") ); 
-std::​cout ​<< "O poligono Vermelho toca o Azul? " ​<< std::​boolalpha << ​vermelho->​touches( azul.get() ) << std::endl;+ 
 +bool result = red->​touches( blue.get() ); 
 + 
 +std::cout << std::​boolalpha << ​result ​<< std::endl ; 
 </​code> ​ </​code> ​
   ​   ​
 <code cpp> <code cpp>
-std::​unique_ptr<​te::​gm::​Geometry> ​vermelho( te::​gm::​WKTReader::​read("​POLYGON ( (9 1, 9 3, 12 3, 12 1, 9 1) )") ); +std::​unique_ptr<​te::​gm::​Geometry> ​red( te::​gm::​WKTReader::​read("​POLYGON ( (9 1, 9 3, 12 3, 12 1, 9 1) )") ); 
-std::​unique_ptr<​te::​gm::​Geometry> ​azul( te::​gm::​WKTReader::​read("​POLYGON ( (11 2, 13 3, 15 2, 13 1, 11 2) )") );+std::​unique_ptr<​te::​gm::​Geometry> ​blue( te::​gm::​WKTReader::​read("​POLYGON ( (11 2, 13 3, 15 2, 13 1, 11 2) )") );
     ​     ​
-std::​cout ​<< "O poligono Vermelho toca o Azul? " ​<< std::​boolalpha << ​vermelho->​touches( azul.get() ) << std::endl;+bool result = red->​touches( blue.get() ); 
 + 
 +std::cout << std::​boolalpha << ​result ​<< std::endl ;
 </​code>​ </​code>​
- 
  
 ===== Set Operations ===== ===== Set Operations =====
  
 +**1.** Polygon intersection:​
 +<code cpp>
 +std::​unique_ptr<​te::​gm::​Geometry>​ red( te::​gm::​WKTReader::​read("​POLYGON ( (2 2, 2 4, 5 4, 5 2, 2 2) )") );
 +std::​unique_ptr<​te::​gm::​Geometry>​ blue( te::​gm::​WKTReader::​read("​POLYGON ( (4 1, 4 3, 7 3, 7 1, 4 1) )") );
 +    ​
 +std::​unique_ptr<​te::​gm::​Geometry>​ result( red->​intersection( blue.get() ) );
 +    ​
 +std::cout << result->​toString() ​ << std::end;
 +</​code>​
 +
 +<code cpp>
 +std::​unique_ptr<​te::​gm::​Geometry>​ red( te::​gm::​WKTReader::​read("​POLYGON ( (2 5, 2 7, 5 7, 5 5, 2 5) )") );
 +std::​unique_ptr<​te::​gm::​Geometry>​ blue( te::​gm::​WKTReader::​read("​POLYGON ( (5 5, 5 7, 8 7, 8 5, 5 5) )") );
 +    ​
 +std::​unique_ptr<​te::​gm::​Geometry>​ result( red->​intersection( blue.get() ) );
 +    ​
 +std::cout << result->​toString() ​ << std::endl;
 +</​code>​
 +
 +<code cpp>
 +std::​unique_ptr<​te::​gm::​Geometry>​ red( te::​gm::​WKTReader::​read("​POLYGON ( (9 2, 9 4, 11 4, 11 2, 9 2) )") );
 +std::​unique_ptr<​te::​gm::​Geometry>​ blue( te::​gm::​WKTReader::​read("​POLYGON ( (12 1, 12 3, 15 3, 15 1, 12 1) )") );
 +    ​
 +std::​unique_ptr<​te::​gm::​Geometry>​ result( red->​intersection( blue.get() ) );
 +    ​
 +std::cout << result->​toString() ​ << std::endl;
 +</​code>​
 +
 +**2.** Polygon union:
 +<code cpp>
 +std::​unique_ptr<​te::​gm::​Geometry>​ red( te::​gm::​WKTReader::​read("​POLYGON ( (2 2, 2 4, 5 4, 5 2, 2 2) )") );
 +std::​unique_ptr<​te::​gm::​Geometry>​ blue( te::​gm::​WKTReader::​read("​POLYGON ( (4 1, 4 3, 7 3, 7 1, 4 1) )") );
 +    ​
 +std::​unique_ptr<​te::​gm::​Geometry>​ result( red->​Union( blue.get() ) );
 +    ​
 +std::cout << result->​toString() ​ << std::endl;
 +</​code>​
 +
 +<code cpp>
 +std::​unique_ptr<​te::​gm::​Geometry>​ red( te::​gm::​WKTReader::​read("​POLYGON ( (2 5, 2 7, 5 7, 5 5, 2 5) )") );
 +std::​unique_ptr<​te::​gm::​Geometry>​ blue( te::​gm::​WKTReader::​read("​POLYGON ( (5 5, 5 7, 8 7, 8 5, 5 5) )") );
 +    ​
 +std::​unique_ptr<​te::​gm::​Geometry>​ result( red->​Union( blue.get() ) );
 +    ​
 +std::cout << result->​toString() ​ << std::endl;
 +</​code>​
 +
 +<code cpp>
 +std::​unique_ptr<​te::​gm::​Geometry>​ red( te::​gm::​WKTReader::​read("​POLYGON ( (9 2, 9 4, 11 4, 11 2, 9 2) )") );
 +std::​unique_ptr<​te::​gm::​Geometry>​ blue( te::​gm::​WKTReader::​read("​POLYGON ( (12 1, 12 3, 15 3, 15 1, 12 1) )") );
 +    ​
 +std::​unique_ptr<​te::​gm::​Geometry>​ result( red->​Union( blue.get() ) );
 +    ​
 +std::cout << result->​toString() ​ << std::endl;
 +</​code>​
 ===== Buffer ===== ===== Buffer =====
  
 +<code cpp>
 +std::​unique_ptr<​te::​gm::​Geometry>​ poly( te::​gm::​WKTReader::​read("​POLYGON ( (6 3, 6 5, 9 5, 9 3, 6 3) )") );
 +
 +std::​unique_ptr<​te::​gm::​Geometry>​ result( poly->​buffer(2.0) );
 +    ​
 +std::cout << result->​toString() ​ << std::endl;
 +</​code>​
 ===== Metric Operators ===== ===== Metric Operators =====