Beispiel #1
0
  bool LabelPosition::crossesBoundary( PointSet *polygon ) const
  {
    if ( !mGeos )
      createGeosGeom();

    if ( !polygon->mGeos )
      polygon->createGeosGeom();

    GEOSContextHandle_t geosctxt = geosContext();
    try
    {
      if ( GEOSPreparedOverlaps_r( geosctxt, polygon->preparedGeom(), mGeos ) == 1
           || GEOSPreparedTouches_r( geosctxt, polygon->preparedGeom(), mGeos ) == 1 )
      {
        return true;
      }
      else if ( nextPart )
      {
        return nextPart->crossesBoundary( polygon );
      }
    }
    catch ( GEOSException &e )
    {
      QgsMessageLog::logMessage( QObject::tr( "Exception: %1" ).arg( e.what() ), QObject::tr( "GEOS" ) );
      return false;
    }

    return false;
  }
Beispiel #2
0
  bool LabelPosition::crossesLine( PointSet* line ) const
  {
    if ( !mGeos )
      createGeosGeom();

    if ( !line->mGeos )
      line->createGeosGeom();

    GEOSContextHandle_t geosctxt = geosContext();
    try
    {
      if ( GEOSPreparedIntersects_r( geosctxt, line->preparedGeom(), mGeos ) == 1 )
      {
        return true;
      }
      else if ( nextPart )
      {
        return nextPart->crossesLine( line );
      }
    }
    catch ( GEOSException &e )
    {
      QgsMessageLog::logMessage( QObject::tr( "Exception: %1" ).arg( e.what() ), QObject::tr( "GEOS" ) );
      return false;
    }

    return false;
  }
Beispiel #3
0
  bool LabelPosition::isInConflictSinglePart( LabelPosition* lp )
  {
    if ( !mGeos )
      createGeosGeom();

    if ( !lp->mGeos )
      lp->createGeosGeom();

    GEOSContextHandle_t geosctxt = geosContext();
    bool result = ( GEOSPreparedIntersects_r( geosctxt, preparedGeom(), lp->mGeos ) == 1 );
    return result;
  }
Beispiel #4
0
  int LabelPosition::polygonIntersectionCost( PointSet *polygon ) const
  {
    if ( !mGeos )
      createGeosGeom();

    if ( !polygon->mGeos )
      polygon->createGeosGeom();

    GEOSContextHandle_t geosctxt = geosContext();

    int cost = 0;
    //check the label center. if covered by polygon, initial cost of 4
    if ( polygon->containsPoint(( x[0] + x[2] ) / 2.0, ( y[0] + y[2] ) / 2.0 ) )
      cost += 4;

    try
    {
      //calculate proportion of label candidate which is covered by polygon
      GEOSGeometry* intersectionGeom = GEOSIntersection_r( geosctxt, mGeos, polygon->mGeos );
      if ( !intersectionGeom )
        return cost;

      double positionArea = 0;
      if ( GEOSArea_r( geosctxt, mGeos, &positionArea ) != 1 )
      {
        GEOSGeom_destroy_r( geosctxt, intersectionGeom );
        return cost;
      }

      double intersectionArea = 0;
      if ( GEOSArea_r( geosctxt, intersectionGeom, &intersectionArea ) != 1 )
      {
        intersectionArea = 0;
      }

      GEOSGeom_destroy_r( geosctxt, intersectionGeom );

      double portionCovered = intersectionArea / positionArea;
      cost += ceil( portionCovered * 8.0 ); //cost of 8 if totally covered
      return cost;
    }
    catch ( GEOSException &e )
    {
      QgsMessageLog::logMessage( QObject::tr( "Exception: %1" ).arg( e.what() ), QObject::tr( "GEOS" ) );
      return cost;
    }
  }
Beispiel #5
0
  bool LabelPosition::isInConflictSinglePart( LabelPosition* lp )
  {
    if ( !mGeos )
      createGeosGeom();

    if ( !lp->mGeos )
      lp->createGeosGeom();

    GEOSContextHandle_t geosctxt = geosContext();
    try
    {
      bool result = ( GEOSPreparedIntersects_r( geosctxt, preparedGeom(), lp->mGeos ) == 1 );
      return result;
    }
    catch ( GEOSException &e )
    {
      QgsMessageLog::logMessage( QObject::tr( "Exception: %1" ).arg( e.what() ), QObject::tr( "GEOS" ) );
      return false;
    }
  }
Beispiel #6
0
  bool LabelPosition::crossesLine( PointSet* line ) const
  {
    if ( !mGeos )
      createGeosGeom();

    if ( !line->mGeos )
      line->createGeosGeom();

    GEOSContextHandle_t geosctxt = geosContext();
    if ( GEOSPreparedIntersects_r( geosctxt, line->preparedGeom(), mGeos ) == 1 )
    {
      return true;
    }
    else if ( nextPart )
    {
      return nextPart->crossesLine( line );
    }

    return false;
  }
Beispiel #7
0
  bool LabelPosition::crossesBoundary( PointSet *polygon ) const
  {
    if ( !mGeos )
      createGeosGeom();

    if ( !polygon->mGeos )
      polygon->createGeosGeom();

    GEOSContextHandle_t geosctxt = geosContext();
    if ( GEOSPreparedOverlaps_r( geosctxt, polygon->preparedGeom(), mGeos ) == 1
         || GEOSPreparedTouches_r( geosctxt, polygon->preparedGeom(), mGeos ) == 1 )
    {
      return true;
    }
    else if ( nextPart )
    {
      return nextPart->crossesBoundary( polygon );
    }

    return false;
  }