Esempio n. 1
0
static VALUE method_geometry_intersection(VALUE self, VALUE rhs)
{
  VALUE result = Qnil;
  RGeo_GeometryData* self_data = RGEO_GEOMETRY_DATA_PTR(self);
  const GEOSGeometry* self_geom = self_data->geom;
  if (self_geom) {
    VALUE factory = self_data->factory;
    const GEOSGeometry* rhs_geom = rgeo_convert_to_geos_geometry(factory, rhs, Qnil);
    if (rhs_geom) {
      result = rgeo_wrap_geos_geometry(factory, GEOSIntersection_r(self_data->geos_context, self_geom, rhs_geom), Qnil);
    }
  }
  return result;
}
Esempio n. 2
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;
    }
  }