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
Next revision Both sides next revision
wiki:documentation:devguide:geometry_module [2016/01/17 12:26]
gribeiro [Geometry Class Hierarchy]
wiki:documentation:devguide:geometry_module [2016/01/20 10:21]
gribeiro [LineString]
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 23: Line 23:
 The following class diagram shows the geometric classes provided in TerraLib((This diagram follows OGC Simple Feature Specification)):​ The following class diagram shows the geometric classes provided in TerraLib((This diagram follows OGC Simple Feature Specification)):​
  
-{{:​wiki:​documentation:​devguide:​geometry_hierarchy.png?​1200|Geometry Classes}}+{{:​wiki:​documentation:​devguide:​geometry_hierarchy.png?​800|Geometry Classes}}
  
 This model implements the classes defined in OGC SFS and ISO SQL/MM Spatial. Following, each class from the above diagram is discussed in detail. This model implements the classes defined in OGC SFS and ISO SQL/MM Spatial. Following, each class from the above diagram is discussed in detail.
Line 43: Line 43:
  
 <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 54: Line 54:
  
 The OGC SFS specification defines only one subclass of **Curve** which uses linear interpolation between Points: **LineString**,​ **Line**, **LinearRing**. The ISO SQL/MM specifies **CircularString** and **CompoundCurve**. The OGC SFS specification defines only one subclass of **Curve** which uses linear interpolation between Points: **LineString**,​ **Line**, **LinearRing**. The ISO SQL/MM specifies **CircularString** and **CompoundCurve**.
 +
 +**Curve** is an abstract class and though not instantiable.
  
 For an in depth explanation,​ see [[http://​www.dpi.inpe.br/​terralib5/​codedocs_5.1.0/​d2/​d3f/​classte_1_1gm_1_1Curve.html|Doxygen documentation of this class]]. For an in depth explanation,​ see [[http://​www.dpi.inpe.br/​terralib5/​codedocs_5.1.0/​d2/​d3f/​classte_1_1gm_1_1Curve.html|Doxygen documentation of this class]].
Line 67: Line 69:
  
 <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 92: Line 94:
  
 <code cpp> <code cpp>
-std::​unique_ptr<​te::​gm::​LinearRing> ​= std::​make_unique<​te::​gm::​LinearRing>​(5,​ te::​gm::​LineStringType);​+std::​unique_ptr<​te::​gm::​LinearRing> ​= std::​make_unique<​te::​gm::​LinearRing>​(5,​ te::​gm::​LineStringType, 0);
  
-double xc = -54.0; +r->​setPoint(0, ​12); 
-double yc = -12.0; +r->​setPoint(1, ​17); 
-duble halfSize = size * 0.5; +r->​setPoint(2, ​77); 
- +r->​setPoint(3, ​72); 
-s->​setPoint(0, ​xc - halfSizeyc - halfSize); // lower left  +r->​setPoint(4, ​12);
-s->​setPoint(1, ​xc - halfSizeyc + halfSize); // upper left +
-s->​setPoint(2, ​xc + halfSizeyc + halfSize); // upper right +
-s->​setPoint(3, ​xc + halfSizeyc - halfSize); // lower right +
-s->​setPoint(4, ​xc - halfSizeyc - halfSize); // closing+
 </​code>​ </​code>​
  
Line 112: Line 110:
 ==== CircularString ==== ==== CircularString ====
  
-**CircularString** is a curve with circular interpolation between points and it must have an odd number ​of points greater than 1. When representing ​more than one arc the last point of the previous arc becomes the first point of the next arc.+**CircularString** is a curve with circular interpolation between points and it may consist ​of one or more circular ​arc segments connected end to end.
  
-For an in depth explanation,​ see [[http://​www.dpi.inpe.br/​terralib5/​codedocs_5.1.0/​da/​d63/​classte_1_1gm_1_1CircularString.html|Doxygen documentation ​of this class]].+A CircularString must have an odd number ​of points and this number must be greater than 1.
  
 +When representing more than one arc the last point of the previous arc becomes the first point of the next arc.
  
 +According to //ISO SQL-MM Part 3 - Spatial//:​\\ ​
 +//"The first three points define the first segment. The first point is the start point of the arc. The second point is any intermediate point on the arc other than the start or end point. The third point is the end point of the arc. Subsequent segments are defined by their intermediate and end points only, as the start point is implicitly defined as the previous segment'​s end point. In the special case where a segment is a complete circle, that is, the start and end points are coincident, then the intermediate point shall be the midpoint of the segment"​.//​
 +
 +Notes:
 +  * A CircularString value with exactly three points is a circular arc.
 +  * A circular ring is a CircularString value that is both closed and simple.
 +
 +For an in depth explanation,​ see [[http://​www.dpi.inpe.br/​terralib5/​codedocs_5.1.0/​da/​d63/​classte_1_1gm_1_1CircularString.html|Doxygen documentation of this class]].
 ==== CompoundCurve ==== ==== CompoundCurve ====
  
Line 144: Line 151:
 **Polygon** is a subclass of CurvePolygon whose rings are defined by linear rings. **Polygon** is a subclass of CurvePolygon whose rings are defined by linear rings.
  
 +The code snippet below shows how to create a polygon with just one outer boundary (a LinearRing):​
 +<code cpp>
 +std::​unique_ptr<​te::​gm::​LinearRing>​ r = std::​make_unique<​te::​gm::​LinearRing>​(5,​ te::​gm::​LineStringType,​ 4326);
 +
 +r->​setPoint(0,​ 1, 2);
 +r->​setPoint(1,​ 1, 7);
 +r->​setPoint(2,​ 7, 7);
 +r->​setPoint(3,​ 7, 2);
 +r->​setPoint(4,​ 1, 2);
 +    ​
 +te::​gm::​Polygon p(1, te::​gm::​PolygonType,​ 4326);
 +    ​
 +p.setRingN(0,​ r.release());​
 +</​code>​
 +
 +You have also methods that allows to add rings incrementally:​
 <code cpp> <code cpp>
 std::​unique_ptr<​te::​gm::​Polygon>​ p = std::​make_unique<​te::​gm::​Polygon>​(0,​ te::​gm::​PolygonType);​ std::​unique_ptr<​te::​gm::​Polygon>​ p = std::​make_unique<​te::​gm::​Polygon>​(0,​ te::​gm::​PolygonType);​
Line 241: Line 264:
  
 ===== Spatial Relationships ===== ===== Spatial Relationships =====
 +
 +**1.** Does the red polygon contains the blue one?
 <code cpp> <code cpp>
-std::​unique_ptr<​te::​gm::​Geometry> ​g1(0); +std::​unique_ptr<​te::​gm::​Geometry> ​red( te::gm::WKTReader::​read("​POLYGON ( (9 2, 9 7, 15 7, 15 2, 9 2) )"​) ​);
-std::​unique_ptr<​te::gm::Geometry>​ g2(0);+
  
-std::cout << g1->​contains(g2);+std::unique_ptr<te::​gm::​Geometry>​ blue( te::​gm::​WKTReader::​read("​POLYGON ( (10 4, 10 7, 14 7, 14 4, 10 4) )") ); 
 +     
 +bool result = red->​contains( ​blue() ​);
  
-std::cout << ​g1->​coveredBy(g2);+std::cout << ​std::​boolalpha << result << std::end; 
 +</​code>​
  
-std::cout << g1->covers(g2);+**2.** Does the red polygon contains the blue one? 
 +<code cpp> 
 +std::unique_ptr<te::​gm::​Geometryred( te::​gm::​WKTReader::​read("​POLYGON ( (2 3, 2 6, 6 6, 6 3, 2 3) )"​) ​);
  
-std::cout << return g1->crosses(g2);+std::unique_ptr<te::​gm::​Geometryblue( te::​gm::​WKTReader::​read("​POLYGON ( (1 2, 1 7, 7 7, 7 2, 1 2) )"​) ​);
  
-std::cout << return g1->disjoint(g2);+bool result =  red->withinblue() ​);
  
-std::cout << ​return g1->​equals(g2);+std::cout << ​std::​boolalpha << result << std::endl; 
 +</​code>​
  
-std::cout << g1->intersects(g2);+<code cpp> 
 +std::unique_ptr<te::​gm::​Geometryred( te::​gm::​WKTReader::​read("​POLYGON ( (10 4, 10 7, 14 7, 14 4, 10 4) )"​) ​);
  
-std::cout << g1->overlaps(g2);+std::unique_ptr<te::​gm::​Geometryblue( te::​gm::​WKTReader::​read("​POLYGON ( (9 2, 9 7, 15 7, 15 2, 9 2) )"​) ​);
  
-std::cout << g1->touches(g2);+bool result =  red->withinblue() ​);
  
-std::cout << ​g1->within(g2);+std::cout << ​std::​boolalpha << result << std::​endl;​ 
 +</​code>​ 
 + 
 +**3.** Does the red line touches the blue one? 
 +<code cpp> 
 +std::​unique_ptr<​te::​gm::​Geometry>​ red( te::​gm::​WKTReader::​read("​LINESTRING (1 5, 1 7, 3 7)") ); 
 +std::​unique_ptr<​te::​gm::​Geometry>​ blue( te::​gm::​WKTReader::​read("​LINESTRING (3 5, 1 7)") ); 
 +     
 +bool result = red->touchesblue.get() ); 
 + 
 +std::cout << std::​boolalpha << result << std::endl ; 
 +</​code>​ 
 + 
 +<code cpp> 
 +std::​unique_ptr<​te::​gm::​Geometry>​ red( te::​gm::​WKTReader::​read("​LINESTRING (4 5, 4 7, 6 7)") ); 
 +std::​unique_ptr<​te::​gm::​Geometry>​ blue( te::​gm::​WKTReader::​read("​LINESTRING (5 5, 5 8)") ); 
 + 
 +bool result = red->​touches( blue.get() ); 
 + 
 +std::cout << std::​boolalpha << result << std::endl ; 
 +</​code>​ 
 + 
 +<code cpp> 
 +std::​unique_ptr<​te::​gm::​Geometry>​ red( te::​gm::​WKTReader::​read("​LINESTRING (1 3, 3 4)") ); 
 +std::​unique_ptr<​te::​gm::​Geometry>​ blue( te::​gm::​WKTReader::​read("​LINESTRING (3 4, 5 3)") ); 
 +     
 +bool result = red->​touches( blue.get() ); 
 + 
 +std::cout << std::​boolalpha << result << std::endl ; 
 +</​code>​ 
 + 
 +**3.** Does the red polygon touches the blue one? 
 +<code cpp> 
 +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>​ blue( te::​gm::​WKTReader::​read("​POLYGON ( (4 0, 4 2, 7 2, 7 0, 4 0) )") ); 
 +     
 +bool result = red->​touches( blue.get() ); 
 + 
 +std::cout << std::​boolalpha << result << std::endl ; 
 +</​code>​ 
 +   
 +<code cpp> 
 +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>​ blue( te::​gm::​WKTReader::​read("​POLYGON ( (11 6, 13 8, 15 6, 13 4, 11 6) )") ); 
 + 
 +bool result = red->​touches( blue.get() ); 
 + 
 +std::cout << std::​boolalpha << result << std::endl ; 
 + 
 +</​code>​  
 +   
 +<code cpp> 
 +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>​ blue( te::​gm::​WKTReader::​read("​POLYGON ( (11 2, 13 3, 15 2, 13 1, 11 2) )") ); 
 +     
 +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 =====