WRAPPER_API void set_DSInstancePtr(void *value)
This function is used for interoperability between Blue Marble libraries. It accepts a pointer to an internal datasource, and uses it to initialize the current DataSource instance. If you are using the GeoTransform raster image library, or the GeoTranslate vector processing library, it is possible to share the same GeoCalc datasource. This allows you to manage and maintain coordinate systems from multiple application in one central repository.
The example below shows how to share a datasource between the GeoCalcPBW and GeoCore (or GeoTransform or GeoTranslate) libraries. The GeoCore::BCoordSysRepository is created and loaded first, and it is then passed to GeoCalc. In this way, it is only necessary to load the datasource once, rather than having to load it for each library. Also, a change made in the GeoCalc datasource will be immediately available in GeoCore (and vice versa). In this example, m_datasource is a pointer to a GEOCALCPBW_NAMESPACE::DataSource, and m_datasourceBox and m_auxDataBox are .Net Windows Forms TextBoxes.
void m_initFromGeoCoreButton_Click(Object^ sender, EventArgs^ e)
{
try
{
bool success = true;
// First, if we have previously created a datasource or repository,
// delete it.
if(m_datasource)
{
GEOCALCPBW_NAMESPACE::Disposal::Dispose(m_datasource);
m_datasource = 0;
}
GeoCore::BCoordSysRepository::DestroyInstance();
// Next, load the datasource into the GeoCalc::DataSource.
try
{
pin_ptr<const BmgChar> pinnedDSPath =
PtrToStringChars(m_datasourceBox->Text);
GeoCore::BCoordSysRepository::Instance()->Load(pinnedDSPath);
}
catch(GeoCore::BException& ex)
{
MessageBox::Show(gcnew String(ex.GetDetailedMessage().Ascii()),
"Error Loading Datasource");
success = false;
}
// Now, we pass the datasource we just loaded from GeoCore over to
// GeoCalcPBW, so that both libraries can make use of the same in-
// memory datasource.
try
{
m_datasource = GEOCALCPBW_NAMESPACE::DataSource::CreateDataSource();
m_datasource->set_DSInstancePtr(
GeoCore::BCoordSysRepository::Instance()->GetDSInstancePtr());
}
catch(GEOCALCPBW_NAMESPACE::GeoCalcException& ex)
{
MessageBox::Show(gcnew String(ex.get_FullMessage()),
"Error Sharing Datasource");
success = false;
}
// Finally, we set the neceessary data paths for both GeoCalc and
// GeoCore.
try
{
pin_ptr<const BmgChar> pinnedAuxPath =
PtrToStringChars(m_auxDataBox->Text);
GeoCore::BCoordSysRepository::SetAuxDataPath(pinnedAuxPath);
pin_ptr<const BmgChar> pinnedDataPath =
PtrToStringChars(System::IO::Path::Combine(m_auxDataBox->Text, "shiftfiles"));
m_datasource->SetDataPath(pinnedDataPath);
}
catch(GeoCore::BException& ex)
{
MessageBox::Show(gcnew String(ex.GetDetailedMessage().Ascii()),
"Error Setting Data Paths");
success = false;
}
if(success)
{
MessageBox::Show("Initialization Successful");
}
}
catch(GEOCALCPBW_NAMESPACE::GeoCalcException& ex)
{
MessageBox::Show(gcnew String(ex.get_FullMessage()),
"Unexpected GeoCalc Exception");
}
catch(GeoCore::BException& ex)
{
MessageBox::Show(gcnew String(ex.GetDetailedMessage().Ascii()),
"Unexpected GeoCore Exception");
}
catch(...)
{
MessageBox::Show("Unexpected Error");
}
}