Diseñando un cliente de servicio WFS -- ++ campo con object-oriented camp codereview Relacionados El problema

Designing a WFS service Client


2
vote

problema

Español

El código de controlador que debe estar encapsulado en las interfaces se muestra a continuación:

      OGRDataSource *m_wfs_t;      m_wfs_t = OGRSFDriverRegistrar::Open("WFS:http://192.168.139.129/cgi-bin/tinyows.exe",true);      OGRSFDriver*driver = m_dataset->GetDriver();     std::cout<<driver->GetName();      OGRLayer *poLayer;      poLayer = m_wfs_t->GetLayerByName("tows:frida");       OGRFeature *poFeature;               poFeature = OGRFeature::CreateFeature( poLayer->GetLayerDefn() );      poFeature->SetField("gfname","ahmed");      OGRLinearRing ring1, ring2;     OGRMultiPolygon multi;      OGRPolygon poly1, poly2;       ring1.addPoint(1116651.439379124, 637392.6969887456);     ring1.addPoint(1188804.0108498496, 652655.7409537067);     ring1.addPoint(1226730.3625203592, 634155.0816022386);     ring1.addPoint(1281307.30760719, 636467.6640211721);     ring1.closeRings();     poly1.addRing(&ring1);       ring2.addPoint(1179553.6811741155, 647105.5431482664);     ring2.addPoint(1179553.6811741155, 626292.3013778647);     ring2.addPoint(1194354.20865529, 626292.3013778647);     ring2.addPoint(1194354.20865529, 647105.5431482664);     ring2.addPoint(1179553.6811741155, 647105.5431482664);     poly2.addRing(&ring2);      multi.addGeometry(&poly1);     multi.addGeometry(&poly2);      poFeature->SetGeometry(&multi);      if( poLayer->CreateFeature( poFeature ) != OGRERR_NONE )       {         std::cout <<"error creating a feature"<<endl;      }      OGRFeature::DestroyFeature( poFeature );       // Declare an object to refer to Layers returned from the WFS     OGRLayer  *Layer;      int cnt = m_wfs_t->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 );         }      }         OGRDataSource::DestroyDataSource( m_dataset );   

Interfaces que deben encapsular el código anterior:

  class Area { public:   Area(){}   ~Area(){} private:   string m_Id;  };   class IData {  private:      OGRLayer * m_Layer; public:     ~IData() {}     IData(OGRLayer *layer)     {         m_Layer = layer;     }      OGRLayer* getLayer();   };  OGRLayer* IData::getLayer() {     return m_Layer; }    class Areas  { public:      Areas(){}      Areas(std::shared_ptr<IData> data);      vector<Area>  getAreas();      ~Areas(){}  private:      std::shared_ptr<IData> m_Data;      vector<Area> m_Areas; };   Areas::Areas(std::shared_ptr<IData> data) {    m_Data = data; }  vector<Area> Areas::getAreas() {       if(m_Data == nullptr)     return vector<Area>();      // 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)     m_Data->getLayer()->ResetReading();      while ((Feature = m_Data->getLayer()->GetNextFeature()) != NULL)     {         // Variable initialised to contain the definitions of all of the fileds in the WFS Layer         OGRFeatureDefn *FeatureDefinition = m_Data->getLayer()->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);     }  }   struct IConnection {     virtual std::shared_ptr<IData>  QueryLayer(string layer) = 0;     virtual int                     Write(IData *data) = 0;     virtual void                    Release() = 0;     IConnection() {}     virtual ~IConnection() {} };  struct ImplIConnection : public IConnection {     OGRDataSource *m_wfs_t; public:     ImplIConnection(OGRDataSource *dataset)     {         m_wfs_t = dataset;     }     ~ImplIConnection() {} private:      std::shared_ptr<IData>  QueryLayer(string data);     int                     Write(IData *data);     void                    Release();  };  std::shared_ptr<IData> ImplIConnection::QueryLayer(string layerName) {     OGRLayer  *Layer = m_wfs_t->GetLayerByName(layerName.c_str());     if (Layer == NULL)     {         return NULL;     }       std::shared_ptr<IData> data(new IData(Layer));      return data; }   int ImplIConnection::Write(IData *data) {      return 0; }    void ImplIConnection::Release() {   }    struct IMapServer {     virtual std::shared_ptr<IConnection>           OpenConnection(string url) = 0;     virtual void                                   Release() = 0;     IMapServer() {}     virtual ~IMapServer() {}  };  struct ImplMapServer : public IMapServer {  private:     OGRDataSource *m_wfs_t; public:     ImplMapServer() {}     ~ImplMapServer()     {         OGRDataSource::DestroyDataSource(m_wfs_t);     }     void Init(void);     std::shared_ptr<IConnection>     OpenConnection(string url);     void                             Release() {}; };   std::shared_ptr<IConnection>  ImplMapServer::OpenConnection(string url) {     m_wfs_t = OGRSFDriverRegistrar::Open(url.c_str(), true);      if (m_wfs_t == NULL)     {         return NULL;     }      std::shared_ptr<ImplIConnection> connection(new ImplIConnection(m_wfs_t));      return connection; }  void ImplMapServer::Init(void) {     CPLSetConfigOption("CPL_DEBUG", "ON");     GDALAllRegister();     OGRRegisterAll(); }   

Me gustaría saber cómo obtengo una opción de icono de OpenConnection (URL);

Además, ¿cómo podría rellenar los datos que obtengo de la biblioteca GDAL y lo relabiera a mis interfaces?

Estoy buscando un diseño adecuado y cómo implementaría esas interfaces.

Tenga en cuenta también la forma en que el cliente usa un hilo que siempre actualiza los datos del servidor. En qué lugar debo ejecutar ese hilo, y rellenar la interfaz

  std::shared_ptr<IConnection> connection = mapserver.OpenConnection("WFS:http://192.168.139.129/cgi-bin/tinyows.exe");     std::shared_ptr<IData> frida = connection->QueryLayer("frida");     Areas *areas = new Areas(frida);      vector<Area> areasVector = areas->getAreas();   
Original en ingles

The Driver Code that needs to be encapsulated in interfaces is shown next:

    OGRDataSource *m_wfs_t;      m_wfs_t = OGRSFDriverRegistrar::Open("WFS:http://192.168.139.129/cgi-bin/tinyows.exe",true);      OGRSFDriver*driver = m_dataset->GetDriver();     std::cout<<driver->GetName();      OGRLayer *poLayer;      poLayer = m_wfs_t->GetLayerByName("tows:frida");       OGRFeature *poFeature;               poFeature = OGRFeature::CreateFeature( poLayer->GetLayerDefn() );      poFeature->SetField("gfname","ahmed");      OGRLinearRing ring1, ring2;     OGRMultiPolygon multi;      OGRPolygon poly1, poly2;       ring1.addPoint(1116651.439379124, 637392.6969887456);     ring1.addPoint(1188804.0108498496, 652655.7409537067);     ring1.addPoint(1226730.3625203592, 634155.0816022386);     ring1.addPoint(1281307.30760719, 636467.6640211721);     ring1.closeRings();     poly1.addRing(&ring1);       ring2.addPoint(1179553.6811741155, 647105.5431482664);     ring2.addPoint(1179553.6811741155, 626292.3013778647);     ring2.addPoint(1194354.20865529, 626292.3013778647);     ring2.addPoint(1194354.20865529, 647105.5431482664);     ring2.addPoint(1179553.6811741155, 647105.5431482664);     poly2.addRing(&ring2);      multi.addGeometry(&poly1);     multi.addGeometry(&poly2);      poFeature->SetGeometry(&multi);      if( poLayer->CreateFeature( poFeature ) != OGRERR_NONE )       {         std::cout <<"error creating a feature"<<endl;      }      OGRFeature::DestroyFeature( poFeature );       // Declare an object to refer to Layers returned from the WFS     OGRLayer  *Layer;      int cnt = m_wfs_t->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 );         }      }         OGRDataSource::DestroyDataSource( m_dataset ); 

Interfaces that needs to encapsulate the above code :

class Area { public:   Area(){}   ~Area(){} private:   string m_Id;  };   class IData {  private:      OGRLayer * m_Layer; public:     ~IData() {}     IData(OGRLayer *layer)     {         m_Layer = layer;     }      OGRLayer* getLayer();   };  OGRLayer* IData::getLayer() {     return m_Layer; }    class Areas  { public:      Areas(){}      Areas(std::shared_ptr<IData> data);      vector<Area>  getAreas();      ~Areas(){}  private:      std::shared_ptr<IData> m_Data;      vector<Area> m_Areas; };   Areas::Areas(std::shared_ptr<IData> data) {    m_Data = data; }  vector<Area> Areas::getAreas() {       if(m_Data == nullptr)     return vector<Area>();      // 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)     m_Data->getLayer()->ResetReading();      while ((Feature = m_Data->getLayer()->GetNextFeature()) != NULL)     {         // Variable initialised to contain the definitions of all of the fileds in the WFS Layer         OGRFeatureDefn *FeatureDefinition = m_Data->getLayer()->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);     }  }   struct IConnection {     virtual std::shared_ptr<IData>  QueryLayer(string layer) = 0;     virtual int                     Write(IData *data) = 0;     virtual void                    Release() = 0;     IConnection() {}     virtual ~IConnection() {} };  struct ImplIConnection : public IConnection {     OGRDataSource *m_wfs_t; public:     ImplIConnection(OGRDataSource *dataset)     {         m_wfs_t = dataset;     }     ~ImplIConnection() {} private:      std::shared_ptr<IData>  QueryLayer(string data);     int                     Write(IData *data);     void                    Release();  };  std::shared_ptr<IData> ImplIConnection::QueryLayer(string layerName) {     OGRLayer  *Layer = m_wfs_t->GetLayerByName(layerName.c_str());     if (Layer == NULL)     {         return NULL;     }       std::shared_ptr<IData> data(new IData(Layer));      return data; }   int ImplIConnection::Write(IData *data) {      return 0; }    void ImplIConnection::Release() {   }    struct IMapServer {     virtual std::shared_ptr<IConnection>           OpenConnection(string url) = 0;     virtual void                                   Release() = 0;     IMapServer() {}     virtual ~IMapServer() {}  };  struct ImplMapServer : public IMapServer {  private:     OGRDataSource *m_wfs_t; public:     ImplMapServer() {}     ~ImplMapServer()     {         OGRDataSource::DestroyDataSource(m_wfs_t);     }     void Init(void);     std::shared_ptr<IConnection>     OpenConnection(string url);     void                             Release() {}; };   std::shared_ptr<IConnection>  ImplMapServer::OpenConnection(string url) {     m_wfs_t = OGRSFDriverRegistrar::Open(url.c_str(), true);      if (m_wfs_t == NULL)     {         return NULL;     }      std::shared_ptr<ImplIConnection> connection(new ImplIConnection(m_wfs_t));      return connection; }  void ImplMapServer::Init(void) {     CPLSetConfigOption("CPL_DEBUG", "ON");     GDALAllRegister();     OGRRegisterAll(); } 

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

std::shared_ptr<IConnection> connection = mapserver.OpenConnection("WFS:http://192.168.139.129/cgi-bin/tinyows.exe");     std::shared_ptr<IData> frida = connection->QueryLayer("frida");     Areas *areas = new Areas(frida);      vector<Area> areasVector = areas->getAreas(); 
     
         
         

Lista de respuestas


Relacionados problema

0  Creación de múltiples objetos del extracto de SQL Server  ( Creating multiple objects from sql server extract ) 
He creado una solución prototipo simplificada como una especie de prueba de concepto antes de comenzar un programa más grande. Aquí están los datos de prueb...

1  Clase de juego, escrito usando enums  ( Playing card class written using enums ) 
Escribí una clase de tarjeta A Mientras vuelvas a esta publicación aquí: Pregunta previa Sé que ha pasado mucho tiempo, pero recientemente regresé al proyec...

8  Árbol fractal orientado a objetos  ( Object oriented fractal tree ) 
Hice un árbol fractal orientado a objetos en JavaScript utilizando la biblioteca P5, consta de tres archivos: fraternal tree.js sucursal.js flower.js ...

8  Envoltura Libusb Library en C ++  ( Wrapping libusb library in c ) 
Quiero usar la biblioteca de Libusb en mi aplicación C ++. He creado clases que envuelven las funciones de Libusb. Puede ver que la API de Libusb se divide en...

3  General Pathfinder en Python  ( General pathfinder in python ) 
Recientemente trabajé en un proyecto donde tuve la siguiente configuración: $_{456}$6 Ninguno del Código es relevante, no tendrá que poder ejecutar nada...

5  ¿Podría mejorarse este sistema de profundidad para un juego?  ( Could this depth system for a game be improved ) 
Todavía soy nuevo en C ++ y no tengo una gran idea de mi codificación, así que estaría muy agradecido a cualquiera y todos los que le otorgan consejos. Ade...

5  Solicitud de Tkinter para administrar las tareas escolares  ( Tkinter application to manage school tasks ) 
Soy un principiante en la programación de la OOP y me pregunto cuál es la mejor manera de poner todas las ventanas y funciones de una aplicación de ventana en...

6  Objetos de Java para un programa de sniffer de red  ( Java objects for a network sniffer program ) 
Estoy trabajando en un programa de sniffer de red, cuya estructura utiliza 3 clases principales: clase de marco - uno por marco monitoreado, sostiene la re...

10  "Stardust" Simulador 2D Gravity - Seguimiento 1: Los planetas  ( Stardust 2d gravity simulator follow up 1 the planets ) 
Este es un seguimiento para el juego de gravedad del simulador 2D pregunta. Desde entonces, he desarrollado mis habilidades de JavaScript, y ahora esto...

1  Pasando un objeto a la vista en CodeIgner  ( Passing an object to the view in codeigniter ) 
Estoy tratando de usar un objeto y persistirlo en la base de datos. He creado una clase en la carpeta de la biblioteca. <?php if (!defined('BASEPATH'))...




© 2022 respuesta.top Reservados todos los derechos. Centro de preguntas y respuestas reservados todos los derechos