Ignore:
Timestamp:
May 1, 2014, 1:28:14 AM (6 years ago)
Author:
djay
Message:

Support metapath embedded in service name. Add support for accessing ZOO-Kernel path subdirectories for full list of available services. Fix issue #98.

File:
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/zoo-project/zoo-services/cgal/voronoi.c

    r468 r469  
    3636#include "ogrsf_frmts.h"
    3737#include "service.h"
    38 
    39 typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
    40 
    41 typedef CGAL::Delaunay_triangulation_2<K>  Triangulation;
     38#include "cgal_service.h"
     39
     40typedef CGAL::Delaunay_triangulation_2<Kernel>  Triangulation;
    4241typedef Triangulation::Edge_iterator  Edge_iterator;
    43 typedef Triangulation::Point          Point;
    44 
    45 typedef CGAL::Constrained_Delaunay_triangulation_2<K> CDT;
    46 typedef CDT::Point Point;
    47 typedef CDT::Vertex_handle Vertex_handle;
    48 
    49 typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
    50 typedef CGAL::Triangulation_euclidean_traits_xy_3<K>  Gt;
    51 typedef CGAL::Delaunay_triangulation_2<Gt> DelaunayTriangulation;
    52 
    5342typedef Triangulation::Vertex_circulator Vertex_circulator;
    5443
    55 typedef K::Point_3   Point1;
    56 
    5744extern "C" {
    58 #include <libxml/tree.h>
    59 #include <libxml/parser.h>
    60 #include <libxml/xpath.h>
    61 #include <libxml/xpathInternals.h>
    62 
    63 #include <openssl/sha.h>
    64 #include <openssl/hmac.h>
    65 #include <openssl/evp.h>
    66 #include <openssl/bio.h>
    67 #include <openssl/buffer.h>
    68 
    69   xmlNodeSet* extractFromDoc(xmlDocPtr,char*);
    70   void printExceptionReportResponse(maps*,map*);
    7145
    7246  int Voronoi(maps*& conf,maps*& inputs,maps*& outputs){
     
    7751    OGRGeometryH geometry,res;
    7852    int bufferDistance;
    79     xmlInitParser();
    8053    map* tmpm=NULL;
    8154    tmpm=getMapFromMaps(inputs,"InputPoints","value");
    82    
    83     xmlInitParser();
    84     xmlDocPtr doc =
    85       xmlParseMemory(tmpm->value,strlen(tmpm->value));
    86     xmlNodePtr cur = xmlDocGetRootElement(doc);
    87     /**
    88      * Parse every Input in DataInputs node.
    89      */
    90     maps* tempMaps=NULL;
    91     xmlXPathContextPtr xpathCtx;
    92     xmlXPathObjectPtr xpathObj;
    93     xpathCtx = xmlXPathNewContext(doc);
    94     xpathObj = xmlXPathEvalExpression(BAD_CAST "/*/*[local-name()='featureMember']/*/*/*[local-name()='Point']/*[local-name()='coordinates']",xpathCtx);
    95     xmlXPathFreeContext(xpathCtx);
    96     xmlNodeSet* nSet=xpathObj->nodesetval;
    97 
    98     if(nSet==NULL){
    99       setMapInMaps(conf,"lenv","message","Unable to continue !!!");
    100       return SERVICE_FAILED;
    101     }
    102     char filepath[2048];
    103     map* tmpMap=getMapFromMaps(conf,"main","tmpPath");
    104     if(tmpMap!=NULL){
    105       sprintf(filepath,"%s/varonoi_%d.tmp",tmpMap->value,getpid());
    106     }
    107     FILE *fo=fopen(filepath,"w");
    108 #ifdef DEBUG
    109     fprintf(stderr,"File Creation (%s) OK\nPrinting %d Points.\n",filepath,nSet->nodeNr);
    110 #endif
    111     for(int k=0;k<nSet->nodeNr;k++){
    112       xmlNodePtr cur=nSet->nodeTab[k];
    113       char *val=
    114         (char*)xmlNodeListGetString(doc,cur->xmlChildrenNode,1);
    115       char *tmp=strstr(val,",");
    116       char tmp1[1024];
    117       strncpy(tmp1,val,strlen(val)-strlen(tmp));
    118       tmp1[strlen(val)-strlen(tmp)]=0;
    119       char buff[1024];
    120       sprintf(buff,"%s %s\n",tmp1,tmp+1);
    121       fwrite(buff,1,strlen(buff)*sizeof(char),fo);
    122     }
    123     fclose(fo);
    124 #ifdef DEBUG
    125     fprintf(stderr,"File Close (%s) OK\n",filepath);
    126 #endif
    127 
    128     std::ifstream in(filepath);
    129     std::istream_iterator<Point> begin(in);
    130     std::istream_iterator<Point> end;
     55
     56    OGRRegisterAll();
     57
     58    std::vector<Point> points;
     59    if(int res=parseInput(conf,inputs,&points,"/vsimem/tmp")!=SERVICE_SUCCEEDED)
     60      return res;
     61   
    13162    Triangulation T;
    132     T.insert(begin, end);
     63    T.insert(points.begin(), points.end());
    13364
    13465    OGRRegisterAll();
     
    14273    int                  iDriver;
    14374
    144     tmpMap=getMapFromMaps(outputs,"Result","mimeType");
     75    map* tmpMap=getMapFromMaps(outputs,"Result","mimeType");
    14576    const char *oDriver;
    14677    oDriver="GeoJSON";
     
    192123    /* -------------------------------------------------------------------- */
    193124    map* tpath=getMapFromMaps(conf,"main","tmpPath");
    194     char *pszDestDataSource=(char*)malloc(strlen(tpath->value)+20);
     125    char *pszDestDataSource=(char*)malloc(100);
    195126    char **papszDSCO=NULL;
    196     sprintf(pszDestDataSource,"%s/result_%d.json",tpath->value,getpid());
     127    sprintf(pszDestDataSource,"/vsimem/result_%d.json",tpath->value,getpid());
    197128    poODS = poDriver->CreateDataSource( pszDestDataSource, papszDSCO );
    198129    if( poODS == NULL ){
     
    231162    for ( ; eit !=T.edges_end(); ++eit) {
    232163      CGAL::Object o = T.dual(eit);
    233       if (const K::Segment_2 *tmp=CGAL::object_cast<K::Segment_2>(&o)) {
    234         const K::Point_2 p1=tmp->source();
    235         const K::Point_2 p2=tmp->target();
     164      if (const Kernel::Segment_2 *tmp=CGAL::object_cast<Kernel::Segment_2>(&o)) {
     165        const Point p1=tmp->source();
     166        const Point p2=tmp->target();
    236167#ifdef DEBUG
    237168        fprintf(stderr,"P1 %d %d | P2 %d %d\n",p1.x(),p1.y(),p2.x(),p2.y());
     
    250181        ++ns ;
    251182      }
    252       else if (CGAL::object_cast<K::Ray_2>(&o)) {++nr;}
     183      else if (const Kernel::Ray_2 *tmp=CGAL::object_cast<Kernel::Ray_2>(&o)) {
     184        const Point p1=tmp->source();
     185        const Point p2=tmp->point(2);
     186        OGRFeatureH hFeature = OGR_F_Create( OGR_L_GetLayerDefn( poDstLayer ) );
     187        OGRGeometryH currLine=OGR_G_CreateGeometry(wkbLineString);
     188        OGR_G_AddPoint_2D(currLine,p1.x(),p1.y());
     189        OGR_G_AddPoint_2D(currLine,p2.x(),p2.y());
     190        OGR_F_SetGeometry( hFeature, currLine );
     191        OGR_G_DestroyGeometry(currLine);
     192        if( OGR_L_CreateFeature( poDstLayer, hFeature ) != OGRERR_NONE ){
     193          setMapInMaps(conf,"lenv","message","Failed to create feature in file.\n");
     194          return SERVICE_FAILED;
     195        }
     196        OGR_F_Destroy( hFeature );
     197        ++nr;
     198      }
    253199    }
    254200    OGR_DS_Destroy( poODS );
    255     OGRCleanupAll();
    256201
    257202#ifdef DEBUG
     
    261206#endif
    262207   
    263     char tmp1[1024];
    264 
    265     FILE * fichier=fopen(pszDestDataSource,"r");
    266     struct stat file_status;
    267     stat(pszDestDataSource, &file_status);
    268     char *res1=(char *)malloc(file_status.st_size*sizeof(char));
    269     if(fichier==NULL){
    270       char tmp[1024];
    271       sprintf(tmp,"Failed to open file %s for reading purpose.\n",
    272               pszDestDataSource);
    273       setMapInMaps(conf,"lenv","message",tmp);
    274       return SERVICE_FAILED;
    275     }
    276     fread(res1,1,(file_status.st_size)*sizeof(char),fichier);
    277     res1[strlen(res1)]=0;
    278     fclose(fichier);
    279     unlink(pszDestDataSource);
     208
     209    char *res1=readVSIFile(conf,pszDestDataSource);
     210    if(res1==NULL)
     211      return SERVICE_FAILED;
    280212   
    281213    setMapInMaps(outputs,"Result","value",res1);
     
    290222    fprintf(stderr,"\nService internal print\n===\n");
    291223#endif
    292     xmlCleanupParser();
     224    OGRCleanupAll();
    293225    return SERVICE_SUCCEEDED;
    294226  }
Note: See TracChangeset for help on using the changeset viewer.

Search

Context Navigation

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png