SAGA API Version 9.14
Loading...
Searching...
No Matches
map_shapes_polygon.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// map_shapes_polygon.cpp //
15// //
16// Copyright (C) 2026 by //
17// Olaf Conrad //
18// //
19//-------------------------------------------------------//
20// //
21// This file is part of 'SAGA - System for Automated //
22// Geoscientific Analyses'. SAGA is free software; you //
23// can redistribute it and/or modify it under the terms //
24// of the GNU General Public License as published by the //
25// Free Software Foundation, either version 2 of the //
26// License, or (at your option) any later version. //
27// //
28// SAGA is distributed in the hope that it will be //
29// useful, but WITHOUT ANY WARRANTY; without even the //
30// implied warranty of MERCHANTABILITY or FITNESS FOR A //
31// PARTICULAR PURPOSE. See the GNU General Public //
32// License for more details. //
33// //
34// You should have received a copy of the GNU General //
35// Public License along with this program; if not, see //
36// <http://www.gnu.org/licenses/>. //
37// //
38//-------------------------------------------------------//
39// //
40// e-mail: oconrad@saga-gis.org //
41// //
42// contact: Olaf Conrad //
43// Institute of Geography //
44// University of Hamburg //
45// Germany //
46// //
48
49//---------------------------------------------------------
50#include "../dc_helper.h"
51
52#include "map_symbology.h"
53
54#include "map_layer.h"
55
56
58// //
59// //
60// //
62
63//---------------------------------------------------------
73
74
76// //
78
79//---------------------------------------------------------
81{
83
84 //-----------------------------------------------------
85 // Display...
86
87 BrushList_Add(Parameters, "NODE_DISPLAY" , "DISPLAY_BRUSH" , _TL("Fill Style" ), _TL(""));
88
89 Parameters.Add_Bool ("NODE_DISPLAY" , "OUTLINE" , _TL("Outline" ), _TL(""), true)->Set_Collapsed();
90 Parameters.Add_Color ("OUTLINE" , "OUTLINE_COLOR" , _TL("Color" ), _TL(""), SG_GET_RGB(0, 0, 0));
91 Parameters.Add_Int ("OUTLINE" , "OUTLINE_SIZE" , _TL("Size" ), _TL(""), 1, 1, true);
92
93 Parameters.Add_Bool ("NODE_DISPLAY" , "BOUNDARY_EFFECT" , _TL("Boundary Effect"), _TL(""), false);
94 Parameters.Add_Int ("BOUNDARY_EFFECT", "BOUNDARY_SIZE" , _TL("Size" ), _TL(""), 4, 1, true, 32, true);
95 Parameters.Add_Color ("BOUNDARY_EFFECT", "BOUNDARY_COLOR" , _TL("Color" ), _TL(""), SG_COLOR_GREY);
96
97 Parameters.Add_Choice ("NODE_DISPLAY" , "DISPLAY_POINTS" , _TL("Show Vertices" ), _TL(""), CSG_String::Format("%s|%s|%s", _TL("no"), _TL("yes"), _TL("with label")), 0);
98 Parameters.Add_Bool ("NODE_DISPLAY" , "DISPLAY_CENTROID", _TL("Show Centroids" ), _TL(""), false);
99
100 //-----------------------------------------------------
101 return( true );
102}
103
104
106// //
108
109//---------------------------------------------------------
111{
112 if( Flags & PARAMETER_CHECK_VALUES )
113 {
114 // nop
115 }
116
117 //-----------------------------------------------------
118 if( Flags & PARAMETER_CHECK_ENABLE )
119 {
120 if( Parameter.Cmp_Identifier("BOUNDARY_EFFECT") )
121 {
122 Parameter.Set_Children_Enabled(Parameter.asBool());
123 }
124 }
125
126 //-----------------------------------------------------
127 return( CSG_Map_Shapes::Parameter_Changed(Parameters, Parameter, Flags) );
128}
129
130
132// //
134
135//---------------------------------------------------------
137{
139
140 //-----------------------------------------------------
141 return( true );
142}
143
144
146// //
148
149//---------------------------------------------------------
151{
153
154 //-----------------------------------------------------
155 m_bOutline = m_Parameters["OUTLINE"].asBool();
156 m_Pen = wxPen(!m_bOutline ? m_pSymbology->Get_Single_Color() : SG_Get_wxColor(m_Parameters["OUTLINE_COLOR"].asColor()), !m_bOutline ? 1 : m_Parameters["OUTLINE_SIZE"].asInt(), wxPENSTYLE_SOLID);
157 m_Brush = wxBrush(m_pSymbology->Get_Single_Color(), BrushList_Get_Style("DISPLAY_BRUSH"));
158
159 m_bVertices = m_Parameters["DISPLAY_POINTS" ].asInt ();
160 m_bCentroid = m_Parameters["DISPLAY_CENTROID"].asBool();
161
162 //-----------------------------------------------------
163 return( true );
164}
165
166
168// //
170
171//---------------------------------------------------------
173{
175
176 CSG_Point Limits(
177 dc_Map.rWorld().Get_XRange() / dc_Map.rDC().GetWidth (),
178 dc_Map.rWorld().Get_YRange() / dc_Map.rDC().GetHeight()
179 );
180
181 if( Limit < 1 || m_pObject->asShapes()->Get_Count() <= Limit )
182 {
183 for(sLong i=0; i<m_pObject->asShapes()->Get_Count(); i++)
184 {
185 CSG_Shape_Polygon *pPolygon = m_pObject->asShapes()->Get_Shape(i)->asPolygon();
186
187 if( pPolygon->Get_Extent().Get_XRange() > Limits.x
188 && pPolygon->Get_Extent().Get_YRange() > Limits.y )
189 {
190 Draw_Shape(dc_Map, pPolygon, LAYER_DRAW_FLAG_THUMBNAIL);
191 }
192 else
193 {
194 TSG_Point_Int Center = dc_Map.World2DC(pPolygon->Get_Extent().Get_Center());
195
196 dc_Map.DrawPoint(Center.x, Center.y);
197 }
198 }
199 }
200 else
201 {
202 CSG_Table Size; Size.Add_Field("SIZE", SG_DATATYPE_Double); Size.Set_Count(m_pObject->asShapes()->Get_Count());
203
204 for(sLong i=0; i<m_pObject->asShapes()->Get_Count(); i++)
205 {
206 Size[i].Set_Value(0, m_pObject->asShapes()->Get_Shape(i)->asPolygon()->Get_Area());
207 }
208
209 Size.Sort(0, false);
210
211 for(int i=0; i<Limit; i++)
212 {
213 CSG_Shape_Polygon *pPolygon = m_pObject->asShapes()->Get_Shape(Size[i].Get_Index())->asPolygon();
214
215 if( pPolygon->Get_Extent().Get_XRange() > Limits.x
216 && pPolygon->Get_Extent().Get_YRange() > Limits.y )
217 {
218 Draw_Shape(dc_Map, pPolygon, LAYER_DRAW_FLAG_THUMBNAIL);
219 }
220 else
221 {
222 TSG_Point_Int Center = dc_Map.World2DC(pPolygon->Get_Extent().Get_Center());
223
224 dc_Map.DrawPoint(Center.x, Center.y);
225 }
226 }
227 }
228}
229
230
232// //
234
235//---------------------------------------------------------
237{
238 if( (Flags & LAYER_DRAW_FLAG_THUMBNAIL) == 0 && m_Parameters["BOUNDARY_EFFECT"].asBool() )
239 {
240 int color = m_Parameters["BOUNDARY_COLOR"].asInt(), size = m_Parameters["BOUNDARY_SIZE"].asInt() + m_Parameters["OUTLINE_SIZE"].asInt();
241
242 dc_Map.SetPen(wxPen(SG_Get_wxColor(color), size, wxPENSTYLE_SOLID)); dc_Map.SetBrush(*wxTRANSPARENT_BRUSH);
243
244 for(sLong i=0; i<m_pObject->asShapes()->Get_Count(); i++)
245 {
246 dc_Map.Draw_Polygon(m_pObject->asShapes()->Get_Shape(i)->asPolygon());
247 }
248 }
249
250 dc_Map.SetBrush(m_Brush); dc_Map.SetPen(m_Pen);
251}
252
253//---------------------------------------------------------
255{
256 if( (Flags & LAYER_DRAW_FLAG_SELECTION) != 0 )
257 {
258 dc_Map.Draw_Polygon(pShape->asPolygon());
259
260 return;
261 }
262
263 //-----------------------------------------------------
264 if( !m_Brush.IsTransparent() || m_bOutline )
265 {
266 int Color;
267
268 if( Get_Class_Color(pShape, Color) || m_bNoData )
269 {
270 m_Brush.SetColour(SG_GET_R(Color), SG_GET_G(Color), SG_GET_B(Color));
271 dc_Map.SetBrush(m_Brush);
272
273 if( !m_bOutline )
274 {
275 m_Pen.SetColour(SG_GET_R(Color), SG_GET_G(Color), SG_GET_B(Color));
276 dc_Map.SetPen(m_Pen);
277 }
278
279 dc_Map.Draw_Polygon((CSG_Shape_Polygon *)pShape);
280 }
281 }
282
283 //-----------------------------------------------------
284 if( (Flags & LAYER_DRAW_FLAG_THUMBNAIL) == 0 && m_bCentroid )
285 {
286 TSG_Point Point = ((CSG_Shape_Polygon *)pShape)->Get_Centroid();
287
288 dc_Map.DrawCircle((int)dc_Map.xWorld2DC(Point.x), (int)dc_Map.yWorld2DC(Point.y), 2);
289 }
290}
291
292//---------------------------------------------------------
293void CSG_Map_Shapes_Polygon::Draw_Label(CSG_Map_DC &dc_Map, CSG_Shape *pShape, const wxString &Label)
294{
295 if( 0 )
296 {
297 TSG_Point_Int p = dc_Map.World2DC(((CSG_Shape_Polygon *)pShape)->Get_Centroid());
298
299 dc_Map.DrawText(SG_DC_TEXTALIGN_CENTER, p.x, p.y, Label, m_Label.Effect, m_Label.Effect_Color, m_Label.Effect_Size);
300 }
301 else
302 {
303 for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
304 {
305 if( !((CSG_Shape_Polygon *)pShape)->is_Lake(iPart) )
306 {
307 TSG_Point_Int p = dc_Map.World2DC(((CSG_Shape_Polygon *)pShape)->Get_Centroid());
308
309 dc_Map.DrawText(SG_DC_TEXTALIGN_CENTER, p.x, p.y, Label, m_Label.Effect, m_Label.Effect_Color, m_Label.Effect_Size);
310 }
311 }
312 }
313}
314
315
317// //
318// //
319// //
321
322//---------------------------------------------------------
#define SG_GET_B(rgb)
Definition api_core.h:1350
#define SG_GET_G(rgb)
Definition api_core.h:1349
signed long long sLong
Definition api_core.h:158
#define SG_COLOR_GREY
Definition api_core.h:1355
#define SG_GET_R(rgb)
Definition api_core.h:1348
@ SG_DATATYPE_Double
Definition api_core.h:1054
#define SG_GET_RGB(r, g, b)
Definition api_core.h:1345
#define _TL(s)
Definition api_core.h:1619
void SetBrush(const wxBrush &Brush)
Definition map_dc.cpp:495
void DrawPoint(int x, int y)
Definition map_dc.cpp:513
void SetPen(const wxPen &Pen)
Definition map_dc.cpp:482
double yWorld2DC(double y, bool bRound=true)
Definition map_dc.h:147
void DrawCircle(int x, int y, int radius)
Definition map_dc.cpp:556
const CSG_Rect & rWorld(void) const
Definition map_dc.h:124
double xWorld2DC(double x, bool bRound=true)
Definition map_dc.h:140
const wxRect & rDC(void) const
Definition map_dc.h:129
void Draw_Polygon(CSG_Shape_Polygon *pPolygon)
Definition map_dc.cpp:317
const double & World2DC(void) const
Definition map_dc.h:131
void DrawText(int Align, int x, int y, const wxString &Text)
Definition map_dc.cpp:616
CSG_Data_Object * m_pObject
Definition map_layer.h:151
bool Set_Object(CSG_Data_Object *pObject)
CSG_Parameters m_Parameters
Definition map_layer.h:149
class CSG_Map_Symbology * m_pSymbology
Definition map_layer.h:153
virtual bool DataObject_Changed(void)
virtual void Draw_Label(CSG_Map_DC &dc_Map, CSG_Shape *pShape, const wxString &Label)
virtual bool Parameter_Changed(CSG_Parameters &Parameters, CSG_Parameter &Parameter, int Flags)
virtual void Draw_Thumbnails(CSG_Map_DC &dc_Map, int Limit)
virtual bool Parameters_Changed(void)
virtual bool Add_Parameters(CSG_Parameters &Parameters)
virtual void Draw_Initialize(CSG_Map_DC &dc_Map, int Flags)
virtual void Draw_Shape(CSG_Map_DC &dc_Map, CSG_Shape *pShape, int Flags=0)
CSG_Map_Shapes_Polygon(CSG_Shapes *pShapes=NULL)
virtual bool Add_Parameters(CSG_Parameters &Parameters)
CSG_Parameter * BrushList_Add(CSG_Parameters &Parameters, const CSG_String &ParentID, const CSG_String &Identifier, const CSG_String &Name, const CSG_String &Description) const
virtual bool Parameter_Changed(CSG_Parameters &Parameters, CSG_Parameter &Parameter, int Flags)
wxBrushStyle BrushList_Get_Style(const CSG_String &Identifier)
bool Get_Class_Color(CSG_Shape *pShape, int &Color)
class CSG_Map_Shapes::CLabel m_Label
wxBrush m_Brush
Definition map_layer.h:666
virtual bool Parameters_Changed(void)
virtual bool DataObject_Changed(void)
bool Set_Collapsed(bool bOn=true)
bool Set_Children_Enabled(bool bEnabled=true)
bool asBool(void) const
Definition parameters.h:286
bool Cmp_Identifier(const CSG_String &Identifier) const
CSG_Parameter * Add_Choice(const CSG_String &ParentID, const CSG_String &ID, const CSG_String &Name, const CSG_String &Description, const CSG_String &Items, int Default=0)
CSG_Parameter * Add_Int(const CSG_String &ParentID, const CSG_String &ID, const CSG_String &Name, const CSG_String &Description, int Value=0, int Minimum=0, bool bMinimum=false, int Maximum=0, bool bMaximum=false)
CSG_Parameter * Add_Color(const CSG_String &ParentID, const CSG_String &ID, const CSG_String &Name, const CSG_String &Description, int Value=0)
CSG_Parameter * Add_Bool(const CSG_String &ParentID, const CSG_String &ID, const CSG_String &Name, const CSG_String &Description, bool Value=false)
double Get_YRange(void) const
Definition geo_tools.h:511
double Get_XRange(void) const
Definition geo_tools.h:510
CSG_Point Get_Center(void) const
Definition geo_tools.h:519
virtual const CSG_Rect & Get_Extent(void)
Definition shapes.h:548
class CSG_Shape_Polygon * asPolygon(void) const
Definition shapes.h:164
virtual int Get_Part_Count(void) const =0
virtual TSG_Shape_Type Get_Type(void) const
Definition shapes.h:814
static CSG_String Format(const char *Format,...)
virtual bool Set_Value(sLong Index, int Field, const SG_Char *Value)
Definition table.h:429
virtual bool Set_Count(sLong nRecords)
Definition table.cpp:954
bool Sort(const char *Field, bool bAscending=true)
Definition table.cpp:1390
virtual bool Add_Field(const CSG_String &Name, TSG_Data_Type Type, int Position=-1)
Definition table.cpp:479
wxColour SG_Get_wxColor(int Color)
Definition dc_helper.cpp:70
#define SG_DC_TEXTALIGN_CENTER
Definition dc_helper.h:135
struct SSG_Point TSG_Point
struct SSG_Point_Int TSG_Point_Int
#define LAYER_DRAW_FLAG_THUMBNAIL
Definition map_layer.h:74
#define LAYER_DRAW_FLAG_SELECTION
Definition map_layer.h:75
#define PARAMETER_CHECK_ENABLE
Definition parameters.h:191
#define PARAMETER_CHECK_VALUES
Definition parameters.h:190
CSG_String SG_Get_ShapeType_Name(TSG_Shape_Type Type)
Definition shapes.cpp:65
@ SHAPE_TYPE_Polygon
Definition shapes.h:105
double x
Definition geo_tools.h:129
double y
Definition geo_tools.h:129