本文整理汇总了C++中CPLJSONObject类的典型用法代码示例。如果您正苦于以下问题:C++ CPLJSONObject类的具体用法?C++ CPLJSONObject怎么用?C++ CPLJSONObject使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CPLJSONObject类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AddLayer
/*
* AddLayer()
*/
void OGRNGWDataset::AddLayer( const CPLJSONObject &oResourceJsonObject,
char **papszOptions, int nOpenFlagsIn )
{
std::string osLayerResourceId;
if( nOpenFlagsIn & GDAL_OF_VECTOR )
{
OGRNGWLayer *poLayer = new OGRNGWLayer( this, oResourceJsonObject );
papoLayers = (OGRNGWLayer**) CPLRealloc(papoLayers, (nLayers + 1) *
sizeof(OGRNGWLayer*));
papoLayers[nLayers++] = poLayer;
osLayerResourceId = poLayer->GetResourceId();
}
else
{
osLayerResourceId = oResourceJsonObject.GetString("resource/id");
}
// Check styles exist and add them as rasters.
if( nOpenFlagsIn & GDAL_OF_RASTER &&
oResourceJsonObject.GetBool( "resource/children", false ) )
{
CPLJSONDocument oResourceChildReq;
bool bResult = oResourceChildReq.LoadUrl( NGWAPI::GetChildren( osUrl,
osLayerResourceId ), papszOptions );
if( bResult )
{
CPLJSONArray oChildren( oResourceChildReq.GetRoot() );
for( int i = 0; i < oChildren.Size(); ++i )
{
AddRaster( oChildren[i], papszOptions );
}
}
}
}
示例2: oChildren
/*
* FillResources()
*/
bool OGRNGWDataset::FillResources( char **papszOptions, int nOpenFlagsIn )
{
CPLJSONDocument oResourceDetailsReq;
bool bResult = oResourceDetailsReq.LoadUrl( NGWAPI::GetChildren( osUrl,
osResourceId ), papszOptions );
if( bResult )
{
CPLJSONArray oChildren(oResourceDetailsReq.GetRoot());
for( int i = 0; i < oChildren.Size(); ++i )
{
CPLJSONObject oChild = oChildren[i];
std::string osResourceType = oChild.GetString("resource/cls");
if( (osResourceType == "vector_layer" ||
osResourceType == "postgis_layer") )
{
// Add vector layer. If failed, try next layer.
AddLayer( oChild, papszOptions, nOpenFlagsIn );
}
else if( (osResourceType == "raster_layer" ||
osResourceType == "wmsclient_layer") && nOpenFlagsIn & GDAL_OF_RASTER )
{
AddRaster( oChild, papszOptions );
}
// TODO: Add support for baselayers, webmap, wfsserver_service, wmsserver_service.
}
}
return bResult;
}
示例3: SetDescription
/*
* FillMetadata()
*/
void OGRNGWDataset::FillMetadata( const CPLJSONObject &oRootObject )
{
std::string osCreateDate = oRootObject.GetString("resource/creation_date");
if( !osCreateDate.empty() )
{
GDALDataset::SetMetadataItem( "creation_date", osCreateDate.c_str() );
}
osName = oRootObject.GetString("resource/display_name");
SetDescription( osName.c_str() );
GDALDataset::SetMetadataItem( "display_name", osName.c_str() );
std::string osDescription = oRootObject.GetString("resource/description");
if( !osDescription.empty() )
{
GDALDataset::SetMetadataItem( "description", osDescription.c_str() );
}
GDALDataset::SetMetadataItem( "id", osResourceId.c_str() );
std::vector<CPLJSONObject> items =
oRootObject.GetObj("resmeta/items").GetChildren();
for( const CPLJSONObject &item : items )
{
std::string osSuffix = NGWAPI::GetResmetaSuffix( item.GetType() );
GDALDataset::SetMetadataItem( (item.GetName() + osSuffix).c_str(),
item.ToString().c_str(), "NGW" );
}
}
示例4: GetObjectByPath
/**
* Delete json object by key.
* @param osName Key name.
*
* @since GDAL 2.3
*/
void CPLJSONObject::Delete(const std::string &osName)
{
std::string objectName;
CPLJSONObject object = GetObjectByPath( osName, objectName );
if( object.IsValid() )
{
json_object_object_del( TO_JSONOBJ(object.GetInternalHandle()),
objectName.c_str() );
}
}
示例5: FillCapabilities
/*
* FillCapabilities()
*/
void OGRNGWDataset::FillCapabilities( char **papszOptions )
{
CPLJSONDocument oRouteReq;
if( oRouteReq.LoadUrl( NGWAPI::GetRoute(osUrl), papszOptions ) )
{
CPLJSONObject oRoot = oRouteReq.GetRoot();
if( oRoot.IsValid() )
{
// TODO: check bHasFeaturePaging
}
}
}
示例6: apiEndpoint
bool Account::updateSupportInfo()
{
std::string apiEndpoint(API_ENDPOINT);
CPLJSONObject root = http::fetchJson(apiEndpoint + "/support_info/");
if(!root.IsValid()) {
return false;
}
bool supported = root.GetBool("supported");
Settings &settings = Settings::instance();
settings.set("account/supported", supported);
if(supported) {
settings.set("account/sign", root.GetString("sign"));
settings.set("account/start_date", root.GetString("start_date"));
settings.set("account/end_date", root.GetString("end_date"));
// Get key file
const char *settingsPath = CPLGetConfigOption("NGS_SETTINGS_PATH", nullptr);
std::string keyFilePath = File::formFileName(settingsPath, KEY_FILE, "");
return http::getFile(apiEndpoint + "/rsa_public_key/", keyFilePath);
}
m_supported = checkSupported();
return true;
}
示例7: TEST
TEST(StoreTests, TestJSONSAXPArser) {
char** options = nullptr;
options = ngsListAddNameValue(options, "DEBUG_MODE", "ON");
options = ngsListAddNameValue(options, "SETTINGS_DIR",
ngsFormFileName(ngsGetCurrentDirectory(), "tmp",
nullptr));
EXPECT_EQ(ngsInit(options), COD_SUCCESS);
ngsListFree(options);
options = nullptr;
options = ngsListAddNameValue(options, "MAX_RETRY", "20");
options = ngsListAddNameValue(options, "RETRY_DELAY", "5");
options = ngsListAddNameValue(options, "UNSAFESSL", "ON");
counter = 0;
CPLJSONDocument doc;
EXPECT_EQ(doc.LoadUrl("http://demo.nextgis.com/api/component/pyramid/pkg_version",
options, ngsGDALProgressFunc, nullptr), true);
ngsListFree(options);
CPLJSONObject obj = doc.GetRoot();
CPLString ngwVersion = obj.GetString("nextgisweb", "0");
EXPECT_STRNE(ngwVersion, "0");
}
示例8: if
/*
* AddRaster()
*/
void OGRNGWDataset::AddRaster( const CPLJSONObject &oRasterJsonObj,
char **papszOptions )
{
std::string osOutResourceId;
std::string osOutResourceName;
std::string osResourceType = oRasterJsonObj.GetString( "resource/cls" );
if( osResourceType == "mapserver_style" ||
osResourceType == "qgis_vector_style" ||
osResourceType == "raster_style" ||
osResourceType == "wmsclient_layer" )
{
osOutResourceId = oRasterJsonObj.GetString( "resource/id" );
osOutResourceName = oRasterJsonObj.GetString( "resource/display_name" );
}
else if( osResourceType == "raster_layer" )
{
std::string osRasterResourceId = oRasterJsonObj.GetString( "resource/id" );
CPLJSONDocument oResourceRequest;
bool bResult = oResourceRequest.LoadUrl( NGWAPI::GetChildren( osUrl,
osRasterResourceId ), papszOptions );
if( bResult )
{
CPLJSONArray oChildren(oResourceRequest.GetRoot());
for( int i = 0; i < oChildren.Size(); ++i )
{
CPLJSONObject oChild = oChildren[i];
osResourceType = oChild.GetString("resource/cls");
if( osResourceType == "raster_style" )
{
AddRaster( oChild, papszOptions );
}
}
}
}
if( !osOutResourceId.empty() )
{
if( osOutResourceName.empty() )
{
osOutResourceName = "raster_" + osOutResourceId;
}
CPLDebug("NGW", "Add raster %s: %s", osOutResourceId.c_str(),
osOutResourceName.c_str());
GDALDataset::SetMetadataItem( CPLSPrintf("SUBDATASET_%d_NAME", nRasters),
CPLSPrintf("NGW:%s/resource/%s", osUrl.c_str(),
osOutResourceId.c_str()), "SUBDATASETS" );
GDALDataset::SetMetadataItem( CPLSPrintf("SUBDATASET_%d_DESC", nRasters),
osOutResourceName.c_str(), "SUBDATASETS" );
nRasters++;
}
}
示例9: switch
bool ConnectionFactory::createRemoteConnection(const enum ngsCatalogObjectType type,
const std::string &path,
const Options &options)
{
switch(type) {
case CAT_CONTAINER_NGW:
{
std::string url = options.asString(KEY_URL);
if(url.empty()) {
return errorMessage(_("Missing required option 'url'"));
}
std::string login = options.asString(KEY_LOGIN);
if(login.empty()) {
login = "guest";
}
else {
std::string oldLogin(login);
login = CPLString(login).Trim();
if(!compare(oldLogin, login, true)) {
warningMessage("Login was trimmed!");
}
}
std::string password = options.asString(KEY_PASSWORD);
bool isGuest = options.asBool(KEY_IS_GUEST);
CPLJSONDocument connectionFile;
CPLJSONObject root = connectionFile.GetRoot();
root.Add(KEY_TYPE, type);
root.Add(KEY_URL, url);
root.Add(KEY_LOGIN, login);
root.Add(KEY_IS_GUEST, isGuest);
if(!password.empty()) {
root.Add(KEY_PASSWORD, encrypt(password));
}
return connectionFile.Save(path);
}
default:
return errorMessage(_("Unsupported connection type %d"), type);
}
}
示例10: GetObj
/**
* Get value by key.
* @param osName Key name.
* @param osDefault Default value.
* @return String value.
*
* @since GDAL 2.3
*/
std::string CPLJSONObject::GetString(const std::string &osName,
const std::string &osDefault) const
{
CPLJSONObject object = GetObj( osName );
return object.ToString( osDefault );
}
示例11: GetHeaders
/*
* Init()
*/
bool OGRNGWDataset::Init(int nOpenFlagsIn)
{
// NOTE: Skip check API version at that moment. We expected API v3.
// Get resource details.
CPLJSONDocument oResourceDetailsReq;
char **papszHTTPOptions = GetHeaders();
bool bResult = oResourceDetailsReq.LoadUrl( NGWAPI::GetResource( osUrl,
osResourceId ), papszHTTPOptions );
CPLDebug("NGW", "Get resource %s details %s", osResourceId.c_str(),
bResult ? "success" : "failed");
if( bResult )
{
CPLJSONObject oRoot = oResourceDetailsReq.GetRoot();
if( oRoot.IsValid() )
{
std::string osResourceType = oRoot.GetString("resource/cls");
FillMetadata( oRoot );
if( osResourceType == "resource_group" )
{
// Check feature paging.
FillCapabilities( papszHTTPOptions );
if( oRoot.GetBool( "resource/children", false ) ) {
// Get child resources.
bResult = FillResources( papszHTTPOptions, nOpenFlagsIn );
}
}
else if( (osResourceType == "vector_layer" ||
osResourceType == "postgis_layer") )
{
// Cehck feature paging.
FillCapabilities( papszHTTPOptions );
// Add vector layer.
AddLayer( oRoot, papszHTTPOptions, nOpenFlagsIn );
}
else if( osResourceType == "mapserver_style" ||
osResourceType == "qgis_vector_style" ||
osResourceType == "raster_style" ||
osResourceType == "wmsclient_layer" )
{
// GetExtent from parent.
OGREnvelope stExtent;
std::string osParentId = oRoot.GetString("resource/parent/id");
bool bExtentResult = NGWAPI::GetExtent(osUrl, osParentId,
papszHTTPOptions, 3857, stExtent);
if( !bExtentResult )
{
// Set full extent for EPSG:3857.
stExtent.MinX = -20037508.34;
stExtent.MaxX = 20037508.34;
stExtent.MinY = -20037508.34;
stExtent.MaxY = 20037508.34;
}
CPLDebug("NGW", "Raster extent is: %f, %f, %f, %f",
stExtent.MinX, stExtent.MinY,
stExtent.MaxX, stExtent.MaxY);
int nEPSG = 3857;
// Get parent details. We can skip this as default SRS in NGW is 3857.
if( osResourceType == "wmsclient_layer" )
{
nEPSG = oRoot.GetInteger("wmsclient_layer/srs/id", nEPSG);
}
else
{
CPLJSONDocument oResourceReq;
bResult = oResourceReq.LoadUrl( NGWAPI::GetResource( osUrl,
osResourceId ), papszHTTPOptions );
if( bResult )
{
CPLJSONObject oParentRoot = oResourceReq.GetRoot();
if( osResourceType == "mapserver_style" ||
osResourceType == "qgis_vector_style" )
{
nEPSG = oParentRoot.GetInteger("vector_layer/srs/id", nEPSG);
}
else if( osResourceType == "raster_style")
{
nEPSG = oParentRoot.GetInteger("raster_layer/srs/id", nEPSG);
}
}
}
// Create raster dataset.
std::string osRasterUrl = NGWAPI::GetTMS(osUrl, osResourceId);
char* pszRasterUrl = CPLEscapeString(osRasterUrl.c_str(), -1, CPLES_XML);
const char *pszConnStr = CPLSPrintf("<GDAL_WMS><Service name=\"TMS\">"
"<ServerUrl>%s</ServerUrl></Service><DataWindow>"
"<UpperLeftX>-20037508.34</UpperLeftX><UpperLeftY>20037508.34</UpperLeftY>"
"<LowerRightX>20037508.34</LowerRightX><LowerRightY>-20037508.34</LowerRightY>"
//.........这里部分代码省略.........
示例12: resetError
bool ConnectionFactory::checkRemoteConnection(const enum ngsCatalogObjectType type,
const Options &options)
{
resetError();
switch(type) {
case CAT_CONTAINER_NGW:
{
std::string url = options.asString(KEY_URL);
if(url.empty()) {
return errorMessage(_("Missing required option 'url'"));
}
std::string login = options.asString(KEY_LOGIN);
if(login.empty()) {
login = "guest";
}
else {
std::string oldLogin(login);
login = CPLString(login).Trim();
if(!compare(oldLogin, login, true)) {
warningMessage("Login was trimmed!");
}
}
std::string password = options.asString(KEY_PASSWORD);
CPLStringList requestOptions;
std::string headers = "Accept: */*";
Options authOptions;
authOptions.add(KEY_TYPE, "basic");
authOptions.add(KEY_LOGIN, login);
authOptions.add(KEY_PASSWORD, password);
AuthStore::authAdd(url, authOptions);
std::string auth = AuthStore::authHeader(url);
AuthStore::authRemove(url);
if(!auth.empty()) {
headers += "\r\n";
headers += auth;
}
requestOptions.AddNameValue("HEADERS", headers.c_str());
CPLJSONDocument checkReq;
if(!checkReq.LoadUrl(ngw::getCurrentUserUrl(url), requestOptions)) {
return errorMessage(CPLGetLastErrorMsg());
}
CPLJSONObject root = checkReq.GetRoot();
if(!root.IsValid()) {
return errorMessage(_("Response is invalid"));
}
if(root.GetString("keyname") == login) {
return true;
}
return errorMessage(_("User '%s' failed to connect to %s."),
login.c_str(), url.c_str());
}
default:
return errorMessage(_("Unsupported connection type %d"), type);
}
}