I have a web service, WFS. I use a library called GDAL for retrieving the data from the server. Here is how I do it.
OGRDataSource *m_wfs_t;
m_wfs_t = OGRSFDriverRegistrar::Open("WFS:
http://192.168.139.129/cgi-bin/tinyows.exe",true);
// Declare an object to refer to Layers returned from the WFS OGRLayer *Layer;
int cnt = m_wfs->GetLayerCount();
cnt--;
while(cnt >= 0 )
{
Layer = m_dataset->GetLayer(cnt--);
// Declare variable for reading the features from a WFS layer
OGRFeature *Feature;
// Reset Reading (Although not necessary now because it hasnt been read yet, this is good practice before reading WFS data)
Layer->ResetReading();
while( (Feature = Layer->GetNextFeature()) != NULL )
{
// Variable initialised to contain the definitions of all of the fileds in the WFS Layer
OGRFeatureDefn *FeatureDefinition = Layer->GetLayerDefn();
for( int i = 0; i < FeatureDefinition->GetFieldCount(); i++ )
{
// Variable initialised to contain field data at the current index of i
OGRFieldDefn *FieldDefinition = FeatureDefinition->GetFieldDefn(i);
if(FieldDefinition->GetType() == OFTInteger)
{
std::cout << Feature->GetFieldAsInteger(i) << ",";
}
else if(FieldDefinition->GetType() == OFTReal)
{
std::cout << Feature->GetFieldAsDouble(i) << ",";
}
else if( FieldDefinition->GetType() == OFTString )
{
std::cout << Feature->GetFieldAsString(i) << ",";
}
else
{
std::cout << Feature->GetFieldAsString(i) << ",";
}
}
// Variable initialised to contain Geometry point data for the field at the current index of i
OGRGeometry *Geometry = Feature->GetGeometryRef();
if(Geometry != NULL && wkbFlatten(Geometry->getGeometryType()) == wkbPoint)
{
OGRPoint *Point = (OGRPoint *) Geometry;
// Maybe need to limit the number of decimal places for X and Y coordinates to 2-3
std::cout << Point->getX() << "," << Point->getY() << std::endl;
}
else
{
std::cout << "No Point Geometry" << std::endl;
}
OGRFeature::DestroyFeature( Feature );
}
}
I had written those interfaces:
struct IData
{
string type();
IData* QueryInterfcae(string name);
};
struct IConnection
{
bool Query( string data) = 0;
int Write(IData *data) = 0;
IData Read() = 0;
void Release() = 0;
};
struct IMapServer
{
IConnection* OpenConnection(string url ) = 0;
void Release() = 0;
};
I would like to know how do I get an IConnection from OpenConnection(url);
Also how would I populate the data that I get from the GDAL Library and populate it to my interfaces.
I'm looking for a proper design and how would I implement those interfaces.
Note also how about the Client that uses a thread that always refresh the data from the server. In which place should I run that thread, and populate the interface.