Skip to content

Commit 2d71309

Browse files
committedJan 18, 2018
Add some more geometry relationship methods to LabelPosition
1 parent dded4ab commit 2d71309

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed
 

‎src/core/pal/labelposition.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,56 @@ bool LabelPosition::isIntersect( double *bbox )
196196
return false;
197197
}
198198

199+
bool LabelPosition::intersects( const GEOSPreparedGeometry *geometry )
200+
{
201+
if ( !mGeos )
202+
createGeosGeom();
203+
204+
try
205+
{
206+
if ( GEOSPreparedIntersects_r( geosContext(), geometry, mGeos ) == 1 )
207+
{
208+
return true;
209+
}
210+
else if ( nextPart )
211+
{
212+
return nextPart->intersects( geometry );
213+
}
214+
}
215+
catch ( GEOSException &e )
216+
{
217+
QgsMessageLog::logMessage( QObject::tr( "Exception: %1" ).arg( e.what() ), QObject::tr( "GEOS" ) );
218+
return false;
219+
}
220+
221+
return false;
222+
}
223+
224+
bool LabelPosition::within( const GEOSPreparedGeometry *geometry )
225+
{
226+
if ( !mGeos )
227+
createGeosGeom();
228+
229+
try
230+
{
231+
if ( GEOSPreparedContains_r( geosContext(), geometry, mGeos ) != 1 )
232+
{
233+
return false;
234+
}
235+
else if ( nextPart )
236+
{
237+
return nextPart->within( geometry );
238+
}
239+
}
240+
catch ( GEOSException &e )
241+
{
242+
QgsMessageLog::logMessage( QObject::tr( "Exception: %1" ).arg( e.what() ), QObject::tr( "GEOS" ) );
243+
return false;
244+
}
245+
246+
return true;
247+
}
248+
199249
bool LabelPosition::isInside( double *bbox )
200250
{
201251
for ( int i = 0; i < 4; i++ )

‎src/core/pal/labelposition.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,16 @@ namespace pal
113113
*/
114114
bool isIntersect( double *bbox );
115115

116+
/**
117+
* Returns true if the label position intersects a \a geometry.
118+
*/
119+
bool intersects( const GEOSPreparedGeometry *geometry );
120+
121+
/**
122+
* Returns true if the label position is within a \a geometry.
123+
*/
124+
bool within( const GEOSPreparedGeometry *geometry );
125+
116126
/**
117127
* \brief Is the labelposition inside the bounding-box ?
118128
*

0 commit comments

Comments
 (0)
Please sign in to comment.