• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ OSRNewSpatialReference函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中OSRNewSpatialReference函数的典型用法代码示例。如果您正苦于以下问题:C++ OSRNewSpatialReference函数的具体用法?C++ OSRNewSpatialReference怎么用?C++ OSRNewSpatialReference使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了OSRNewSpatialReference函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: OSRNewSpatialReference

bool SpatialReference::equals(const SpatialReference& input) const
{
    OGRSpatialReferenceH current =
        OSRNewSpatialReference(getWKT(eCompoundOK, false).c_str());
    OGRSpatialReferenceH other =
        OSRNewSpatialReference(input.getWKT(eCompoundOK, false).c_str());

    int output = OSRIsSame(current, other);
    OSRDestroySpatialReference(current);
    OSRDestroySpatialReference(other);

    return (output == 1);
}
开发者ID:FeodorFitsner,项目名称:PDAL,代码行数:13,代码来源:SpatialReference.cpp


示例2: pdal_error

void ReprojectionFilter::ready(PointTableRef table)
{
    if (m_inferInputSRS)
    {
        m_inSRS = table.spatialRef();
        if (m_inSRS.getWKT().empty())
            throw pdal_error("Source data has no spatial reference and none "
                "is specified with the 'in_srs' option.");
    }

    m_in_ref_ptr = ReferencePtr(OSRNewSpatialReference(0),
        OGRSpatialReferenceDeleter());
    m_out_ref_ptr = ReferencePtr(OSRNewSpatialReference(0),
        OGRSpatialReferenceDeleter());

    int result =
        OSRSetFromUserInput(m_in_ref_ptr.get(),
            m_inSRS.getWKT(pdal::SpatialReference::eCompoundOK).c_str());
    if (result != OGRERR_NONE)
    {
        std::ostringstream msg;
        msg << "Invalid input spatial reference '" << m_inSRS.getWKT() <<
            "'.  This is usually caused by a bad value for the 'in_srs'"
            "option or an invalid spatial reference in the source file.";
        throw pdal_error(msg.str());
    }

    result = OSRSetFromUserInput(m_out_ref_ptr.get(),
        m_outSRS.getWKT(pdal::SpatialReference::eCompoundOK).c_str());
    if (result != OGRERR_NONE)
    {
        std::ostringstream msg;
        msg << "Invalid output spatial reference '" << m_outSRS.getWKT() <<
            "'.  This is usually caused by a bad value for the 'out_srs'"
            "option.";
        throw pdal_error(msg.str());
    }
    m_transform_ptr = TransformPtr(
        OCTNewCoordinateTransformation(m_in_ref_ptr.get(),
            m_out_ref_ptr.get()), OSRTransformDeleter());

    if (!m_transform_ptr.get())
    {
        std::string msg = "Could not construct CoordinateTransformation in "
            "ReprojectionFilter:: ";
        throw std::runtime_error(msg);
    }

    setSpatialReference(m_outSRS);
}
开发者ID:ezhangle,项目名称:PDAL,代码行数:50,代码来源:ReprojectionFilter.cpp


示例3: mMapUnits

QgsCoordinateReferenceSystem::QgsCoordinateReferenceSystem()
    : mMapUnits( QGis::UnknownUnit )
    , mIsValidFlag( 0 )
    , mValidationHint( "" )
{
  mCRS = OSRNewSpatialReference( NULL );
}
开发者ID:mmubangizi,项目名称:qgis,代码行数:7,代码来源:qgscoordinatereferencesystem.cpp


示例4: tmp

std::string SpatialReference::getVerticalUnits() const
{
    std::string tmp("");

    std::string wkt = getWKT(eCompoundOK);
    const char* poWKT = wkt.c_str();
    OGRSpatialReference* poSRS =
        (OGRSpatialReference*)OSRNewSpatialReference(m_wkt.c_str());
    if (poSRS)
    {
        OGR_SRSNode* node = poSRS->GetAttrNode("VERT_CS");
        if (node)
        {
            char* units(0);
            double u = poSRS->GetLinearUnits(&units);
            tmp = units;
            CPLFree(units);

            Utils::trim(tmp);

        }
    }

    return tmp;
}
开发者ID:FeodorFitsner,项目名称:PDAL,代码行数:25,代码来源:SpatialReference.cpp


示例5: get_wkt_of

// returned WKT string should be free by OGRFree or CPLFree
static char* get_wkt_of(int epsg_code) {
    OGRSpatialReferenceH srs = OSRNewSpatialReference(NULL);
    OSRImportFromEPSG(srs, epsg_code);
    char* srs_wkt;
    OSRExportToWkt(srs, &srs_wkt);
    return srs_wkt;
}
开发者ID:refactor,项目名称:geo_utils,代码行数:8,代码来源:gdal_nif.c


示例6: strstr

/// Fetch the SRS as WKT
std::string SpatialReference::getWKT(WKTModeFlag mode_flag , bool pretty) const
{
    std::string result_wkt = m_wkt;

    if ((mode_flag == eHorizontalOnly
            && strstr(result_wkt.c_str(),"COMPD_CS") != NULL)
            || pretty)
    {
        OGRSpatialReference* poSRS =
            (OGRSpatialReference*)OSRNewSpatialReference(result_wkt.c_str());
        char *pszWKT = NULL;

        if (mode_flag == eHorizontalOnly)
            poSRS->StripVertical();
        if (pretty)
            poSRS->exportToPrettyWkt(&pszWKT, FALSE);
        else
            poSRS->exportToWkt(&pszWKT);

        OSRDestroySpatialReference(poSRS);

        result_wkt = pszWKT;
        CPLFree(pszWKT);
    }

    return result_wkt;
}
开发者ID:FeodorFitsner,项目名称:PDAL,代码行数:28,代码来源:SpatialReference.cpp


示例7: QgsDebugMsg

bool QgsOgrLayerItem::setCrs( QgsCoordinateReferenceSystem crs )
{
  QgsDebugMsg( "mPath = " + mPath );
  OGRRegisterAll();
  OGRSFDriverH hDriver;
  OGRDataSourceH hDataSource = OGROpen( TO8F( mPath ), true, &hDriver );

  if ( !hDataSource )
    return false;

  QString  driverName = OGR_Dr_GetName( hDriver );
  OGR_DS_Destroy( hDataSource );

  // we are able to assign CRS only to shapefiles :-(
  if ( driverName == "ESRI Shapefile" )
  {
    QString layerName = mPath.left( mPath.indexOf( ".shp", Qt::CaseInsensitive ) );
    QString wkt = crs.toWkt();

    // save ordinary .prj file
    OGRSpatialReferenceH hSRS = OSRNewSpatialReference( wkt.toLocal8Bit().data() );
    OSRMorphToESRI( hSRS ); // this is the important stuff for shapefile .prj
    char* pszOutWkt = NULL;
    OSRExportToWkt( hSRS, &pszOutWkt );
    QFile prjFile( layerName + ".prj" );
    if ( prjFile.open( QIODevice::WriteOnly ) )
    {
      QTextStream prjStream( &prjFile );
      prjStream << pszOutWkt << endl;
      prjFile.close();
    }
    else
    {
      QgsMessageLog::logMessage( tr( "Couldn't open file %1.prj" ).arg( layerName ), tr( "OGR" ) );
      return false;
    }
    OSRDestroySpatialReference( hSRS );
    CPLFree( pszOutWkt );

    // save qgis-specific .qpj file (maybe because of better wkt compatibility?)
    QFile qpjFile( layerName + ".qpj" );
    if ( qpjFile.open( QIODevice::WriteOnly ) )
    {
      QTextStream qpjStream( &qpjFile );
      qpjStream << wkt.toLocal8Bit().data() << endl;
      qpjFile.close();
    }
    else
    {
      QgsMessageLog::logMessage( tr( "Couldn't open file %1.qpj" ).arg( layerName ), tr( "OGR" ) );
      return false;
    }

    return true;
  }

  // It it is impossible to assign a crs to an existing layer
  // No OGR_L_SetSpatialRef : http://trac.osgeo.org/gdal/ticket/4032
  return false;
}
开发者ID:LingboTang,项目名称:QGIS,代码行数:60,代码来源:qgsogrdataitems.cpp


示例8:

	CProjection::CProjection(CProjection const& in)
	{
		m_pProjPJ = NULL;
		m_prjID = PRJ_NOT_INIT;
		m_pSpatialReference = (OGRSpatialReference *)OSRNewSpatialReference(NULL);

		if (in.IsInit())
		{
			operator=(in);
		}
	}
开发者ID:RNCan,项目名称:WeatherBasedSimulationFramework,代码行数:11,代码来源:Projection.cpp


示例9: getWKT

bool SpatialReference::valid() const
{
    std::string wkt = getWKT();
    OGRSpatialReferenceH current =
        OSRNewSpatialReference(wkt.c_str());

    OGRErr err = OSRValidate(current);

    OSRDestroySpatialReference(current);
    return err == OGRERR_NONE;
}
开发者ID:FeodorFitsner,项目名称:PDAL,代码行数:11,代码来源:SpatialReference.cpp


示例10: setlocale

void QgsCoordinateReferenceSystem::setProj4String( QString theProj4String )
{
  const char *oldlocale = setlocale( LC_NUMERIC, NULL );

  setlocale( LC_NUMERIC, "C" );
  OSRDestroySpatialReference( mCRS );
  mCRS = OSRNewSpatialReference( NULL );
  mIsValidFlag = OSRImportFromProj4( mCRS, theProj4String.toLatin1().constData() ) == OGRERR_NONE;
  setMapUnits();

#if defined(QGISDEBUG) && QGISDEBUG>=3
  debugPrint();
#endif

  setlocale( LC_NUMERIC, oldlocale );
}
开发者ID:mmubangizi,项目名称:qgis,代码行数:16,代码来源:qgscoordinatereferencesystem.cpp


示例11: stoi

	bool WebMapService::Layer::InitBase(libconfig::ChainedSetting& config)
	{
		auto crs = config["CRS"];
		const int numCRS = crs.getLength();
		if (numCRS > 0)
		{
			for (int c = 0; c < numCRS; c++)
			{
				supportedCRS[crs[c]] = (OGRSpatialReference*)OSRNewSpatialReference(NULL);
			}
		}
		else
		{
			cout << "WebMapService::Layer: " << "At least one CRS must be defined" << endl;
			return false;
		}

		for (auto it = supportedCRS.begin(); it != supportedCRS.end(); it++)
		{
			OGRErr err = OGRERR_UNSUPPORTED_SRS;
			string crsString = it->first;
			if (crsString.length() > 5)
			{
				int epsgCode = stoi(crsString.c_str() + 5); // TODO: support non-EPSG codes
				err = it->second->importFromEPSG(epsgCode);
			}
			if (err == OGRERR_UNSUPPORTED_SRS)
			{
				cout << "WebMapService::Layer: " << "requested CRS is unsupported:" << crsString << endl;
				return false;
			}
		}

		// create all possible SRS transformation permutations
		for (auto it1 = supportedCRS.begin(); it1 != supportedCRS.end(); it1++)
		{
			for (auto it2 = it1; it2 != supportedCRS.end(); it2++)
			{
				if (it2 == supportedCRS.end()) break;

				CreateTransform(it1->second, it2->second);
				CreateTransform(it2->second, it1->second);
			}
		}

		return true;
	}
开发者ID:Hemofektik,项目名称:Druckwelle,代码行数:47,代码来源:WebMapService.cpp


示例12: OSRNewSpatialReference

Q_NOWARN_DEPRECATED_POP

bool QgsOgrLayerItem::setCrs( QgsCoordinateReferenceSystem crs )
{
  if ( !( mCapabilities & SetCrs ) )
    return false;

  QString layerName = mPath.left( mPath.indexOf( ".shp", Qt::CaseInsensitive ) );
  QString wkt = crs.toWkt();

  // save ordinary .prj file
  OGRSpatialReferenceH hSRS = OSRNewSpatialReference( wkt.toLocal8Bit().data() );
  OSRMorphToESRI( hSRS ); // this is the important stuff for shapefile .prj
  char* pszOutWkt = nullptr;
  OSRExportToWkt( hSRS, &pszOutWkt );
  QFile prjFile( layerName + ".prj" );
  if ( prjFile.open( QIODevice::WriteOnly ) )
  {
    QTextStream prjStream( &prjFile );
    prjStream << pszOutWkt << endl;
    prjFile.close();
  }
  else
  {
    QgsMessageLog::logMessage( tr( "Couldn't open file %1.prj" ).arg( layerName ), tr( "OGR" ) );
    return false;
  }
  OSRDestroySpatialReference( hSRS );
  CPLFree( pszOutWkt );

  // save qgis-specific .qpj file (maybe because of better wkt compatibility?)
  QFile qpjFile( layerName + ".qpj" );
  if ( qpjFile.open( QIODevice::WriteOnly ) )
  {
    QTextStream qpjStream( &qpjFile );
    qpjStream << wkt.toLocal8Bit().data() << endl;
    qpjFile.close();
  }
  else
  {
    QgsMessageLog::logMessage( tr( "Couldn't open file %1.qpj" ).arg( layerName ), tr( "OGR" ) );
    return false;
  }

  return true;
}
开发者ID:Antoviscomi,项目名称:QGIS,代码行数:46,代码来源:qgsogrdataitems.cpp


示例13: _setSourceCrsFromWKT

static QString _setSourceCrsFromWKT(const QString& wkt)
{
    QString ret;
    OGRSpatialReferenceH hSRS = OSRNewSpatialReference(NULL);
    QByteArray arr = wkt.toUtf8();
    const char* raw_data = arr.constData();
    if (OSRImportFromWkt(hSRS, const_cast<char**>(&raw_data)) == OGRERR_NONE)
    {
        char * ppszReturn = 0;
        if (OSRExportToProj4(hSRS, &ppszReturn) == OGRERR_NONE && ppszReturn != 0)
        {
            ret = ppszReturn;
        }
    }
    OSRDestroySpatialReference(hSRS);

    return ret;
}
开发者ID:aaschwanden,项目名称:qgis-crayfish-plugin,代码行数:18,代码来源:crayfish_mesh.cpp


示例14: _setSourceCrsFromESRI

static QString _setSourceCrsFromESRI(const QString& wkt)
{
    QString ret;

    QString wkt2("ESRI::" + wkt);
    OGRSpatialReferenceH hSRS = OSRNewSpatialReference(NULL);
    QByteArray arr = wkt2.toUtf8();
    if (OSRSetFromUserInput(hSRS, arr.constData()) == OGRERR_NONE)
    {
        char * ppszReturn = 0;
        if (OSRExportToProj4(hSRS, &ppszReturn) == OGRERR_NONE && ppszReturn != 0)
        {
            ret = ppszReturn;
        }
    }
    OSRDestroySpatialReference(hSRS);

    return ret;
}
开发者ID:aaschwanden,项目名称:qgis-crayfish-plugin,代码行数:19,代码来源:crayfish_mesh.cpp


示例15: ensure

    void object::test<4>()
    {
        ensure("SRS handle is NULL", nullptr != srs_);

        err_ = OSRSetGS(srs_, -117.0, 100000.0, 100000);
        ensure_equals("OSRSetGS failed", err_, OGRERR_NONE);

        err_ = OSRSetGeogCS(srs_, "Test GCS", "Test Datum", "WGS84",
            SRS_WGS84_SEMIMAJOR, SRS_WGS84_INVFLATTENING,
            nullptr, 0, nullptr, 0);
        ensure_equals("OSRSetGeogCS failed", err_, OGRERR_NONE);

        err_ = OSRSetTOWGS84(srs_, 1, 2, 3, 0, 0, 0, 0);
        ensure_equals("OSRSetTOWGS84 failed", err_, OGRERR_NONE);

        const int coeffSize = 7;
        double coeff[coeffSize] = { 0 };
        const double expect[coeffSize] = { 1, 2, 3, 0, 0, 0, 0 };

        err_ = OSRGetTOWGS84(srs_, coeff, 7);
        ensure_equals("OSRSetTOWGS84 failed", err_, OGRERR_NONE);
        ensure("GetTOWGS84 result is wrong",
            std::equal(coeff, coeff + coeffSize, expect));
        OSRSetLinearUnits(srs_, "Metre", 1);

        char* proj4 = nullptr;
        err_ = OSRExportToProj4(srs_, &proj4);
        ensure_equals("OSRExportToProj4 failed", err_, OGRERR_NONE);

        OGRSpatialReferenceH srs2 = nullptr;
        srs2 = OSRNewSpatialReference(nullptr);

        err_ = OSRImportFromProj4(srs2, proj4);
        ensure_equals("OSRImportFromProj4 failed", err_, OGRERR_NONE);

        err_ = OSRGetTOWGS84(srs2, coeff, 7);
        ensure_equals("OSRSetTOWGS84 failed", err_, OGRERR_NONE);
        ensure("GetTOWGS84 result is wrong",
            std::equal(coeff, coeff + coeffSize, expect));

        OSRDestroySpatialReference(srs2);
        CPLFree(proj4);
    }
开发者ID:AsgerPetersen,项目名称:gdal,代码行数:43,代码来源:test_osr.cpp


示例16: IsValidSRS

static bool IsValidSRS( const char *pszUserInput )

{
    OGRSpatialReferenceH hSRS;
    bool bRes = true;

    CPLErrorReset();

    hSRS = OSRNewSpatialReference( nullptr );
    if( OSRSetFromUserInput( hSRS, pszUserInput ) != OGRERR_NONE )
    {
        bRes = false;
        CPLError( CE_Failure, CPLE_AppDefined,
                  "Translating source or target SRS failed:\n%s",
                  pszUserInput );
    }

    OSRDestroySpatialReference( hSRS );

    return bRes;
}
开发者ID:AsgerPetersen,项目名称:gdal,代码行数:21,代码来源:gdaltransform.cpp


示例17: CPLErrorReset

char *SanitizeSRS( const char *pszUserInput )

{
    OGRSpatialReferenceH hSRS;
    char *pszResult = NULL;

    CPLErrorReset();
    
    hSRS = OSRNewSpatialReference( NULL );
    if( OSRSetFromUserInput( hSRS, pszUserInput ) == OGRERR_NONE )
        OSRExportToWkt( hSRS, &pszResult );
    else
    {
        CPLError( CE_Failure, CPLE_AppDefined,
                  "Translating source or target SRS failed:\n%s",
                  pszUserInput );
        exit( 1 );
    }
    
    OSRDestroySpatialReference( hSRS );

    return pszResult;
}
开发者ID:AsherBond,项目名称:MondocosmOS,代码行数:23,代码来源:gdaltransform.cpp


示例18: GPJ_wkt_to_grass

int GPJ_wkt_to_grass(struct Cell_head *cellhd, struct Key_Value **projinfo,
		     struct Key_Value **projunits, const char *wkt,
		     int datumtrans)
{
    int retval;

    if (wkt == NULL)
	retval =
	    GPJ_osr_to_grass(cellhd, projinfo, projunits, NULL, datumtrans);
    else {
	OGRSpatialReferenceH hSRS;

	/* Set finder function for locating OGR csv co-ordinate system tables */
	SetCSVFilenameHook(GPJ_set_csv_loc);

	hSRS = OSRNewSpatialReference(wkt);
	retval =
	    GPJ_osr_to_grass(cellhd, projinfo, projunits, hSRS, datumtrans);
	OSRDestroySpatialReference(hSRS);
    }

    return retval;
}
开发者ID:AsherBond,项目名称:MondocosmOS,代码行数:23,代码来源:convert.c


示例19: test_osr_data

 test_osr_data()
     : err_(OGRERR_NONE), srs_(NULL)
 {
     srs_ = OSRNewSpatialReference(NULL);
 }
开发者ID:drons,项目名称:gdal,代码行数:5,代码来源:test_osr.cpp


示例20: main

int main( int argc, char ** argv )

{
    GDALDatasetH	hDataset;
    GDALRasterBandH	hBand;
    int			i, iBand;
    double		adfGeoTransform[6];
    GDALDriverH		hDriver;
    char		**papszMetadata;
    int                 bComputeMinMax = FALSE;

    if( !GDALBridgeInitialize( "..", stderr ) )
    {
        fprintf( stderr, "Unable to intiailize GDAL bridge.\n" );
        exit( 10 );
    }

    if( argc > 1 && strcmp(argv[1],"-mm") == 0 )
    {
        bComputeMinMax = TRUE;
        argv++;
    }

    GDALAllRegister();

    hDataset = GDALOpen( argv[1], GA_ReadOnly );
    
    if( hDataset == NULL )
    {
        fprintf( stderr,
                 "GDALOpen failed - %d\n%s\n",
                 CPLGetLastErrorNo(), CPLGetLastErrorMsg() );
        exit( 1 );
    }
    
/* -------------------------------------------------------------------- */
/*      Report general info.                                            */
/* -------------------------------------------------------------------- */
    hDriver = GDALGetDatasetDriver( hDataset );
    printf( "Driver: %s/%s\n",
            GDALGetDriverShortName( hDriver ),
            GDALGetDriverLongName( hDriver ) );

    printf( "Size is %d, %d\n",
            GDALGetRasterXSize( hDataset ), 
            GDALGetRasterYSize( hDataset ) );

/* -------------------------------------------------------------------- */
/*      Report projection.                                              */
/* -------------------------------------------------------------------- */
    if( GDALGetProjectionRef( hDataset ) != NULL )
    {
        OGRSpatialReferenceH  hSRS;
        char		      *pszProjection;

        pszProjection = (char *) GDALGetProjectionRef( hDataset );

        hSRS = OSRNewSpatialReference(NULL);
        if( OSRImportFromWkt( hSRS, &pszProjection ) == CE_None )
        {
            char	*pszPrettyWkt = NULL;

            OSRExportToPrettyWkt( hSRS, &pszPrettyWkt, FALSE );
            printf( "Coordinate System is:\n%s\n", pszPrettyWkt );
        }
        else
            printf( "Coordinate System is `%s'\n",
                    GDALGetProjectionRef( hDataset ) );

        OSRDestroySpatialReference( hSRS );
    }

/* -------------------------------------------------------------------- */
/*      Report Geotransform.                                            */
/* -------------------------------------------------------------------- */
    if( GDALGetGeoTransform( hDataset, adfGeoTransform ) == CE_None )
    {
        printf( "Origin = (%.6f,%.6f)\n",
                adfGeoTransform[0], adfGeoTransform[3] );

        printf( "Pixel Size = (%.6f,%.6f)\n",
                adfGeoTransform[1], adfGeoTransform[5] );
    }

/* -------------------------------------------------------------------- */
/*      Report GCPs.                                                    */
/* -------------------------------------------------------------------- */
    if( GDALGetGCPCount( hDataset ) > 0 )
    {
        printf( "GCP Projection = %s\n", GDALGetGCPProjection(hDataset) );
        for( i = 0; i < GDALGetGCPCount(hDataset); i++ )
        {
            const GDAL_GCP	*psGCP;
            
            psGCP = GDALGetGCPs( hDataset ) + i;

            printf( "GCP[%3d]: Id=%s, Info=%s\n"
                    "          (%g,%g) -> (%g,%g,%g)\n", 
                    i, psGCP->pszId, psGCP->pszInfo, 
                    psGCP->dfGCPPixel, psGCP->dfGCPLine, 
//.........这里部分代码省略.........
开发者ID:drownedout,项目名称:datamap,代码行数:101,代码来源:bridge_test.cpp



注:本文中的OSRNewSpatialReference函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ OSSL_NELEM函数代码示例发布时间:2022-05-30
下一篇:
C++ OSMemSet函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap