GDAL SetProjection is not Retrieved after assigning WGS84 - projection

I got this code to set Geographic Projection to a GeoTiff File.
poDataset = (GDALDataset *) GDALOpen( fileName.c_str(), GA_Update);
OGRSpatialReference oSRS;
char *pszSRS_WKT = NULL;
oSRS.SetWellKnownGeogCS( "WGS84" );
oSRS.exportToWkt( &pszSRS_WKT );
oSRS.SetProjCS( pszSRS_WKT );
std::cout<<"Setted Proj: "<<pszSRS_WKT<<endl;
CPLErr err = poDataset->SetProjection( pszSRS_WKT );
std::cout<<"Proj Error: "<<err<<endl;
double adfGeoTransform[6];
CPLErr err2 = poDataset->GetGeoTransform( adfGeoTransform );
std::cout<<"Error: "<<err2<<endl;
std::string str = poDataset->GetProjectionRef();
std::cout<<"Retrieved Proj: "<<str<<endl;
Result is
Proj: GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,A
UTHORITY["EPSG","7030"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6326"]],PRIMEM
["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHOR
ITY["EPSG","9108"]],AUTHORITY["EPSG","4326"]]**
Proj Error: 0
Error: 3
Retrieved Proj:
Code seems reasonable, what might be the reason of this error?
Thanks in Advance

Well I solved the problem, when you set the projection, you should have assign new GeoTransformation too.
calling
poDataset->SetGeoTransform(adfGeoTransform);
solved my problem.

Related

Segfault in factory constructed class

I have an issue where a Segfault occurs in random locations but those locations seem to always be the same. The issue also is made more confusing by the fact that the location of the Segfault can change depending on whether I'm using gdb or valgrind to try and solve the issue. This would seem to be a race condition problem but I don't always see any of my destructors being called so I'm not sure why that would be happening. I have not defined my copy constructors which I suppose could be the problem but I would like to understand why that may be.
The tests that I have on the midLevel class to exercise its functionality don't have this problem. Is there something flawed with my basic construction?
My use case is:
In highest level class:
returnObject highLevelClass::performTask( ){
std::shared_ptr< midLevelClass > midClass;
std::vector< someType > dataForClass;
for ( auto it = _someIterate.begin( ); it != _someIterate.end( ); it++ ){
...
buildMidClass( midClass, &dataForClass );
}
...
return returnObject;
}
returnObject highLevelClass::buildMidClass( std::shared_ptr< midLevelClass > &midClass,
std::vector< someType > *dataForClass ){
...
midClass = midLevelClass( _configurationInfo ).create( )
midClass.loadData( dataForClass );
midClass->processData( ); //SOMETIMES IT SEGFAULTS HERE DURING std::vector ALLOCATIONS
...
return returnObject;
}
highLevelClass::~highLevelClass( ){
//SOMETIMES IT SEGFAULTS HERE
return;
}
In the mid-level class:
midLevelClass::loadData( std::vector< someType > *data ){
_data = data; //_data is a std::vector< someType >*
}
std::shared_ptr< midLevelClass > midLevelClass::create( configurationType &_configInfo ){
if ( _configInfo[ "type" ] == childMidLevelClass ){
return std::make_shared< childMidLevelClass >( _configInfo );
}
_error = new errorNode( "create", "The type is not defined" );
return std::make_shared< volumeReconstructionBase >( _config, _error );
}
The answer turned out to be that another std::vector ( that wasn't being accessed by any other part of the code ) was overflowing through a bad access using []. Nothing in gdb or valgrind showed that this was the problem. The answer is probably be careful about using [] to access a std::vector and consider using std::vector::at( ).

How to get an error message instead of an integer in MQL5?

I am trying to get the error message using OpenCl in MQL5.
int cl_ctx;
if ( ( cl_ctx = CLContextCreate( CL_USE_ANY ) ) == INVALID_HANDLE )
{
Print( "OpenCL not found: ", GetLastError() );
float pr = 2.0 / ( period + 1.0 );
result[0] = (float)price[position] * pr + prev_value * ( 1 - pr );
Print( result[0] );
return( result[0] );
}
I am getting the message as:
OpenCL not found: 5113
Now I do not know what this 5113 means. How I can get the message in human readable format that will help me debug my program effectively?
In case your code received _LastError == 5113:
the documented human-readable explanation is this one:
ERR_OPENCL_TOO_MANY_OBJECTS 5113 Too many OpenCL objects
Next time, better present a few "surrounding" lines via a copy/paste from the MT5-log, there are more details surrounding the Runtime Error incident.
All error-code definitions and explanations are kept both in documentation and in < stderror.mqh > file since ever.
Also may re-read the online documentation aids.
Lastl, but not least, always pre-clear _LastError state with a call to ResetLastError()

I have successfully enlisted a user in cohort via core_cohort_add_cohort_members but getting a warning

I have successfuly enlisted a user in moodle cohort using core_cohort_add_cohort_members but i am getting a warning in response.Can anybody help me remoce this warning.
Here is the warning i get.
{"warnings":[]}
Here is my code
$fname = 'core_cohort_add_cohort_members';
/// Paramètres
$member = new stdClass();
$member->cohorttype[type]='id';
$member->cohorttype[value]=2;
$member->usertype[type]='id';
$member->usertype[value]=8;
$members = array($member);
$par = array('members' => $members);
$rest_format = 'json';
$Serve_Url = 'localhost/moodle' . '/webservice/rest/server.php'. '?wstoken=' . '72f102312fff135cbb4a301d9c7839ae' .'&wsfunction='. $fname;
require_once('curl.inc');
$Rest_format = ($rest_format == 'json') ? '&moodlewsrestformat=' . $rest_format : '';
$curl = new curl;
//if rest format == 'xml', then we do not add the param for backward compatibility with Moodle < 2.2
$rep = $curl->post($Serve_Url.$Rest_format, $par);
dpm($rep);
The warnings array is empty in your example reply.
If you want to detect this more verbosely, you can always just json_decode() the reply. You should see an empty array there.
So I think it's working just as you wanted.
Turn the keys into strings i.e
$member->cohorttype["type"]='id';
$member->cohorttype["value"]=2;
$member->usertype["type"]='id';
$member->usertype["value"]=8;
Mainly because newer versions of PHP may cause real exceptions because of
unidentified variables(type and value)
That aside as Sebastian Berm stated empty warnings array means no problem

displaying image from sqlite error

I have saved an image in sqlite and i am trying to retrieve it and displaying it in a QLabel using this code.
connect(ui.tableView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
this, SLOT(getImage(QModelIndex,QModelIndex)));
void smith::getImage()
{
.......
QModelIndex index = ui.tableView->currentIndex();
QString sqlQuery = QString("SELECT image FROM %1 WHERE id=:id").arg(tableName);
query.prepare(sqlQuery);
QSqlRecord recordz = tableModel->record(index.row());
query.bindValue(":id", recordz.value("id").toInt());
query.exec();
tableModel->select();
QByteArray array = query.value(0).toByteArray();
QBuffer buffer(&array);
buffer.open( QIODevice::ReadOnly );
QImageReader reader(&buffer, "PNG");
QImage image = reader.read();
if( image.isNull() )
{
QMessageBox::about(this, tr("Image Is Null"),
tr("<h2>Image Error</h2>"
"<p>Copyright © 2011."
"<p>Message Box To Check For "
" Errors "
));
}
ui.imageLabel->setPixmap( QPixmap::fromImage(image));
}
The project compiles without any errors but the image won't show.
I'd suggest adding some error-checking to your code, to narrow down where the error occurs.
For example, the documentation for QImageReader::read() says that if the image can't be read, the resultant image is null, and it tells you how to find out what the error was.
So after your call to reader.read(), check image.isNull().
And earlier on, check array.size() to make sure that you really got a value back from the database.
And the check the result returned by buffer.open( QIODevice::ReadOnly ) - the docs say it will return false if the call failed.

how to write a CDATA node using libxml2?

I'm using libxml2 to read/write xml files. Now I'm trying to write a CDATA node.
Here is what I tried:
nodePtr = xmlNewChild( parentPtr, NULL, "foo", NULL );
xmlNodeSetContentLen( nodePtr, "<![CDATA[\nTesting 1 < 2\n]]>", len );
However, this results in the following encoded text:
<foo><![CDATA[
Testing 1 < 2
]]></foo>
I'm thinking that perhaps there might be a CDATA-specific libxml2 API. Or maybe I have to call something else to tell libxml2 not to automatically encode the node content?
Figured it out. The trick is in knowing that CDATA text content is actually a child and not a part of the current node, and the critical API to call is xmlNewCDataBlock(). Using the same example as above:
nodePtr = xmlNewChild( parentPtr, NULL, "foo", NULL );
cdataPtr = xmlNewCDataBlock( doc, "Testing 1 < 2", 13 );
xmlAddChild( nodePtr, cdataPtr );
This will produce the following xml:
<foo><![CDATA[Testing 1 < 2]]></foo>
I cannot say for all versions of libxml2, but according to libxml2-2.9.4 the doc part of returning node of xmlNewChild comes from its parent. Also the parent of child node returned from xmlNewCDataBlock is set by doc parameter. So the following would be a good practice:
const char str[] = "said the kitty";
xmlNodePtr node = xmlNewNode(NULL, BAD_CAST "meow");
xmlNodePtr cdata_node = xmlNewCDataBlock(node->doc, BAD_CAST str, strlen(str));
xmlAddChild(node, cdata_node);
The resulting xml is
<meow><![CDATA[said the kitty]]></meow>
And it would not matter if node is part of an xmlDoc or not

Resources