SAGA API  v9.6
shapes_selection.cpp
Go to the documentation of this file.
1 
3 // //
4 // SAGA //
5 // //
6 // System for Automated Geoscientific Analyses //
7 // //
8 // Application Programming Interface //
9 // //
10 // Library: SAGA_API //
11 // //
12 //-------------------------------------------------------//
13 // //
14 // shapes_selection.cpp //
15 // //
16 // Copyright (C) 2005 by Olaf Conrad //
17 // //
18 //-------------------------------------------------------//
19 // //
20 // This file is part of 'SAGA - System for Automated //
21 // Geoscientific Analyses'. //
22 // //
23 // This library is free software; you can redistribute //
24 // it and/or modify it under the terms of the GNU Lesser //
25 // General Public License as published by the Free //
26 // Software Foundation, either version 2.1 of the //
27 // License, or (at your option) any later version. //
28 // //
29 // This library is distributed in the hope that it will //
30 // be useful, but WITHOUT ANY WARRANTY; without even the //
31 // implied warranty of MERCHANTABILITY or FITNESS FOR A //
32 // PARTICULAR PURPOSE. See the GNU Lesser General Public //
33 // License for more details. //
34 // //
35 // You should have received a copy of the GNU Lesser //
36 // General Public License along with this program; if //
37 // not, see <http://www.gnu.org/licenses/>. //
38 // //
39 //-------------------------------------------------------//
40 // //
41 // contact: Olaf Conrad //
42 // Institute of Geography //
43 // University of Goettingen //
44 // Goldschmidtstr. 5 //
45 // 37077 Goettingen //
46 // Germany //
47 // //
48 // e-mail: oconrad@saga-gis.org //
49 // //
51 
52 //---------------------------------------------------------
53 #include "shapes.h"
54 
55 
57 // //
58 // //
59 // //
61 
62 //---------------------------------------------------------
63 bool CSG_Shapes::Select(sLong Index, bool bInvert)
64 {
65  return( CSG_Table::Select(Index, bInvert) );
66 }
67 
68 //---------------------------------------------------------
69 bool CSG_Shapes::Select(CSG_Table_Record *pShape, bool bInvert)
70 {
71  return( CSG_Table::Select(pShape, bInvert) );
72 }
73 
74 //---------------------------------------------------------
75 bool CSG_Shapes::Select(const TSG_Rect &Extent, bool bInvert)
76 {
77  if( !bInvert )
78  {
80  }
81 
82  for(sLong i=0; i<Get_Count(); i++)
83  {
84  if( Get_Shape(i)->Intersects(Extent) )
85  {
86  CSG_Table::Select(i, true);
87  }
88  }
89 
90  return( Get_Selection_Count() > 0 );
91 }
92 
93 //---------------------------------------------------------
94 bool CSG_Shapes::Select(const TSG_Point &Point, bool bInvert)
95 {
96  if( Get_Type() != SHAPE_TYPE_Polygon )
97  {
98  return( Select(CSG_Rect(Point, Point), bInvert) );
99  }
100 
101  if( !bInvert )
102  {
104  }
105 
106  for(sLong i=0; i<Get_Count(); i++)
107  {
108  if( ((CSG_Shape_Polygon *)Get_Shape(i))->Contains(Point) )
109  {
110  CSG_Table::Select(i, true);
111  }
112  }
113 
114  return( Get_Selection_Count() > 0 );
115 }
116 
117 //---------------------------------------------------------
119 {
120  if( Get_Selection_Count() > 0 )
121  {
123 
124  for(sLong i=1; i<Get_Selection_Count(); i++)
125  {
126  m_Extent_Selected.Union(((CSG_Shape *)Get_Selection(i))->Get_Extent());
127  }
128  }
129  else
130  {
131  m_Extent_Selected.Assign(0., 0., 0., 0.);
132  }
133 
134  return( m_Extent_Selected );
135 }
136 
137 
139 // //
140 // //
141 // //
143 
144 //---------------------------------------------------------
CSG_Rect
Definition: geo_tools.h:471
CSG_Rect::Assign
CSG_Rect & Assign(double xMin, double yMin, double xMax, double yMax)
Definition: geo_classes.cpp:727
CSG_Shapes::m_Extent_Selected
CSG_Rect m_Extent_Selected
Definition: shapes.h:851
CSG_Shapes::Get_Shape
virtual CSG_Shape * Get_Shape(const CSG_Point &Point, double Epsilon=0.)
Definition: shapes.cpp:499
CSG_Shapes::Get_Selection
virtual CSG_Shape * Get_Selection(sLong Index=0)
Definition: shapes.h:835
CSG_Table_Record
Definition: table.h:130
SHAPE_TYPE_Polygon
@ SHAPE_TYPE_Polygon
Definition: shapes.h:105
CSG_Shape::Intersects
TSG_Intersection Intersects(CSG_Shape *pShape)
Definition: shape.cpp:118
SSG_Point
Definition: geo_tools.h:128
SSG_Rect
Definition: geo_tools.h:464
CSG_Shapes::Get_Selection_Extent
virtual const CSG_Rect & Get_Selection_Extent(void)
Definition: shapes_selection.cpp:118
CSG_Table::Get_Selection_Count
sLong Get_Selection_Count(void) const
Definition: table.h:420
sLong
signed long long sLong
Definition: api_core.h:158
CSG_Table::Get_Count
sLong Get_Count(void) const
Definition: table.h:392
CSG_Shapes::Get_Extent
virtual const CSG_Rect & Get_Extent(void)
Definition: shapes.h:813
CSG_Rect::Union
CSG_Rect & Union(double x, double y)
Definition: geo_classes.cpp:824
shapes.h
CSG_Table::Select
virtual bool Select(sLong Index, bool bInvert=false)
Definition: table_selection.cpp:136
CSG_Shapes::Get_Type
virtual TSG_Shape_Type Get_Type(void) const
Definition: shapes.h:809
CSG_Shape_Polygon
Definition: shapes.h:701
CSG_Shape
Definition: shapes.h:141
CSG_Shapes::Select
virtual bool Select(sLong Index, bool bInvert=false)
Definition: shapes_selection.cpp:63