Пример #1
0
QgsAbstractGeometryV2* QgsGeometryFactory::geomFromWkb( QgsConstWkbPtr wkbPtr )
{
  if ( !wkbPtr )
    return nullptr;

  //find out type (bytes 2-5)
  QgsWKBTypes::Type type = wkbPtr.readHeader();
  wkbPtr -= 1 + sizeof( int );

  QgsAbstractGeometryV2* geom = nullptr;

  geom = geomFromWkbType( type );

  if ( geom )
  {
    try
    {
      geom->fromWkb( wkbPtr );
    }
    catch ( const QgsWkbException &e )
    {
      Q_UNUSED( e );
      QgsDebugMsg( "WKB exception: " + e.what() );
      delete geom;
      geom = nullptr;
    }
  }

  return geom;
}
Пример #2
0
QgsAbstractGeometryV2* QgsGeometryImport::geomFromWkb( const unsigned char* wkb )
{
  if ( !wkb )
  {
    return 0;
  }

  //find out type (bytes 2-5)
  int type;
  memcpy( &type, wkb + 1, sizeof( int ) );
  QgsAbstractGeometryV2* geom = 0;

  geom = geomFromWkbType( QgsWKBTypes::Type( type ) );

#if 0
  type = QgsWKBTypes::flatType( QgsWKBTypes::Type( type ) );
  switch ( type )
  {
    case QgsWKBTypes::Point:
      geom = new QgsPointV2();
      break;
    case QgsWKBTypes::LineString:
      geom = new QgsLineStringV2();
      break;
    case QgsWKBTypes::CircularString:
      geom = new QgsCircularStringV2();
      break;
    case QgsWKBTypes::CompoundCurve:
      geom = new QgsCompoundCurveV2();
      break;
    case QgsWKBTypes::Polygon:
      geom = new QgsPolygonV2();
      break;
    case QgsWKBTypes::CurvePolygon:
      geom = new QgsCurvePolygonV2();
      break;
    case QgsWKBTypes::MultiLineString:
      geom = new QgsMultiLineStringV2();
      break;
    case QgsWKBTypes::MultiPolygon:
      geom = new QgsMultiPolygonV2();
      break;
    case QgsWKBTypes::MultiPoint:
      geom = new QgsMultiPointV2();
      break;
    default:
      geom = 0;
  }
#endif

  if ( geom )
  {
    geom->fromWkb( wkb );
  }
  return geom;
}
Пример #3
0
QgsAbstractGeometryV2* QgsGeometryFactory::geomFromWkb( const unsigned char* wkb )
{
  if ( !wkb )
  {
    return 0;
  }

  //find out type (bytes 2-5)
  int type;
  memcpy( &type, wkb + 1, sizeof( int ) );
  QgsAbstractGeometryV2* geom = 0;

  geom = geomFromWkbType( QgsWKBTypes::Type( type ) );

  if ( geom )
  {
    geom->fromWkb( wkb );
  }
  return geom;
}
Пример #4
0
std::unique_ptr<QgsAbstractGeometry> QgsGeometryFactory::geomFromWkb( QgsConstWkbPtr &wkbPtr )
{
  if ( !wkbPtr )
    return nullptr;

  //find out type (bytes 2-5)
  QgsWkbTypes::Type type = QgsWkbTypes::Unknown;
  try
  {
    type = wkbPtr.readHeader();
  }
  catch ( const QgsWkbException &e )
  {
    Q_UNUSED( e );
    QgsDebugMsg( "WKB exception while reading header: " + e.what() );
    return nullptr;
  }
  wkbPtr -= 1 + sizeof( int );

  std::unique_ptr< QgsAbstractGeometry > geom = geomFromWkbType( type );

  if ( geom )
  {
    try
    {
      geom->fromWkb( wkbPtr );  // also updates wkbPtr
    }
    catch ( const QgsWkbException &e )
    {
      Q_UNUSED( e );
      QgsDebugMsg( "WKB exception: " + e.what() );
      geom.reset();
    }
  }

  return geom;
}