Ignore:
Timestamp:
May 31, 2011, 3:30:49 AM (13 years ago)
Author:
djay
Message:

Merge trunk r111:r216 into branch-1.2

Location:
branches/branch-1.2
Files:
9 edited
2 copied

Legend:

Unmodified
Added
Removed
  • branches/branch-1.2

  • branches/branch-1.2/zoo-services/arithmetics/cgi-env/Multiply.zcfg

    r106 r217  
    55 storeSupported = true
    66 statusSupported = true
    7  serviceProvider = demo_service.zo
     7 serviceProvider = test_service.zo
    88 serviceType = C
    99 <MetaData>
  • branches/branch-1.2/zoo-services/arithmetics/makefile.vc

    r1 r217  
    11GEODIR=c:/OSGeo4W/
    22TOOLS=c:/Users/djay/GeoLabs/tools/
    3 CFLAGS=-I$(GEODIR)/include -I$(TOOLS)/include -I../../../zoo-kernel/ -I./ -DLINUX_FREE_ISSUE -DDEBUG
     3CFLAGS=-I$(GEODIR)/include -I$(TOOLS)/include -I../../zoo-kernel/ -I./ -DLINUX_FREE_ISSUE -DDEBUG -DWIN32
    44CPP=cl /TP
    55
    6 cgi-env/service.zo: service.c
    7         $(CPP) $(CFLAGS) /c service.c
    8         link /dll /out:cgi-env/ogr_service.zso ../../../zoo-kernel/service_internal.obj ./service.obj -L$(TOOLS)/lib/libssl32.dll.a $(GEODIR)/lib/libxml2.lib $(GEODIR)/lib/gdal_i.lib $(TOOLS)/lib/libeay32.dll.a $(TOOLS)/lib/libcrypto.a $(TOOLS)/lib/libssl32.dll.a
     6cgi-env/test_service.zo: test_service.c
     7        $(CPP) $(CFLAGS) /c test_service.c
     8        link /dll /out:cgi-env/test_service.zo ../../zoo-kernel/service_internal.obj ./test_service.obj -L$(TOOLS)/lib/libssl32.dll.a $(GEODIR)/lib/libxml2.lib $(GEODIR)/lib/gdal_i.lib $(TOOLS)/lib/libeay32.dll.a $(TOOLS)/lib/libcrypto.a $(TOOLS)/lib/libssl32.dll.a $(TOOLS)/lib/libintl.lib
    99
    1010clean:
    11         rm -f cgi-env/ogr_service.zso
     11        erase cgi-env\demo_service.*
  • branches/branch-1.2/zoo-services/arithmetics/test_service.c

    r1 r217  
    33extern "C" {
    44
     5#ifdef WIN32
     6__declspec(dllexport)
     7#endif
    58  int Multiply(maps*& conf,maps*& inputs,maps*& outputs){
    69        fprintf(stderr,"\nService internal print\n");
  • branches/branch-1.2/zoo-services/cgal/Makefile

    r1 r217  
    1 CFLAGS=-I../../zoo-kernel-svn/ -I./ `xml2-config --cflags` `python-config --cflags` -DLINUX_FREE_ISSUE #-DDEBUG
     1CFLAGS=-I../../zoo-kernel/ -I./ `xml2-config --cflags` `python-config --cflags` -DLINUX_FREE_ISSUE #-DDEBUG
    22CC=gcc
    33
    4 cgi-env/service.zo: service.c
    5         g++ ${CFLAGS} -shared -fpic -o cgi-env/service.zo ./service.c -lgdal
     4cgi-env/cgal_service.zo: service.c
     5        g++ ${CFLAGS} -shared -fpic -o cgi-env/cgal_service.zo ./service.c -lgdal -lCGAL
    66
    77clean:
    8         rm -f *.zo *.o *.tab.c *.tab.h *.sr.c* service_loader lex.* *.lreg *.sibling
     8        rm -f cgi-env/*.zo *.o *.tab.c *.tab.h *.sr.c* service_loader lex.* *.lreg *.sibling
    99        rm -rf service_loader.dSYM
  • branches/branch-1.2/zoo-services/cgal/service.c

    r1 r217  
    4646  void printExceptionReportResponse(maps*,map*);
    4747
    48   char *base64(const unsigned char *input, int length){
    49     BIO *bmem, *b64;
    50     BUF_MEM *bptr;
    51 
    52     b64 = BIO_new(BIO_f_base64());
    53     bmem = BIO_new(BIO_s_mem());
    54     b64 = BIO_push(b64, bmem);
    55     BIO_write(b64, input, length);
    56     BIO_flush(b64);
    57     BIO_get_mem_ptr(b64, &bptr);
    58 
    59     char *buff = (char *)malloc(bptr->length+1);
    60     memcpy(buff, bptr->data, bptr->length);
    61     buff[bptr->length] = 0;
    62 
    63     BIO_free_all(b64);
    64 
    65     return buff;
    66   }
    67 
    68   OGRGeometryH createGeometryFromGML(maps* conf,char* inputStr){
    69     xmlInitParser();
    70     xmlDocPtr doc = xmlParseMemory(inputStr,strlen(inputStr));
    71     xmlChar *xmlbuff;
    72     int buffersize;
    73     xmlXPathContextPtr xpathCtx;
    74     xmlXPathObjectPtr xpathObj;
    75     char * xpathExpr="/*/*/*/*/*[local-name()='Polygon' or local-name()='MultiPolygon']";
    76     xpathCtx = xmlXPathNewContext(doc);
    77     xpathObj = xmlXPathEvalExpression(BAD_CAST xpathExpr,xpathCtx);
    78     if(!xpathObj->nodesetval){
    79       map* tmp=createMap("text","Unable to parse Input Polygon");
    80       addToMap(tmp,"code","InvalidParameterValue");
    81       printExceptionReportResponse(conf,tmp);
    82       exit(0);
    83     }
    84     int size = (xpathObj->nodesetval) ? xpathObj->nodesetval->nodeNr : 0;
    85     /**
    86      * Create a temporary XML document
    87      */
    88     xmlDocPtr ndoc = xmlNewDoc(BAD_CAST "1.0");
    89     /**
    90      * Only one polygon should be provided so we use it as the root node.
    91      */
    92     for(int k=size-1;k>=0;k--){
    93       xmlDocSetRootElement(ndoc, xpathObj->nodesetval->nodeTab[k]);
    94     }
    95     xmlDocDumpFormatMemory(ndoc, &xmlbuff, &buffersize, 1);
    96     char *tmp=strdup(strstr((char*)xmlbuff,"?>")+2);
    97     xmlXPathFreeObject(xpathObj);
    98     xmlXPathFreeContext(xpathCtx);
    99     xmlFree(xmlbuff);
    100     xmlFreeDoc(doc);
    101     xmlCleanupParser();
    102     fprintf(stderr,"\nService internal print\n Loading the geometry from GML string ...");
    103     OGRGeometryH res=OGR_G_CreateFromGML(tmp);
    104     if(res==NULL){
    105       map* tmp=createMap("text","Unable to call OGR_G_CreatFromGML");
    106       addToMap(tmp,"code","NoApplicableCode");
    107       printExceptionReportResponse(conf,tmp);
    108       exit(0);
    109     }
    110     else
    111       return OGR_G_CreateFromGML(tmp);
    112   }
    113 
    114  
    115   int Delaunay(maps*& conf,maps*& inputs,maps*& outputs){
     48  int Voronoi(maps*& conf,maps*& inputs,maps*& outputs){
     49#ifdef DEBUG
    11650    fprintf(stderr,"\nService internal print\nStarting\n");
     51#endif
    11752    maps* cursor=inputs;
    11853    OGRGeometryH geometry,res;
     
    12156    map* tmpm=NULL;
    12257    tmpm=getMapFromMaps(inputs,"InputPoints","value");
    123 
     58   
    12459    xmlInitParser();
    12560    xmlDocPtr doc =
     
    13570    xpathObj = xmlXPathEvalExpression(BAD_CAST "/*/*[local-name()='featureMember']/*/*/*[local-name()='Point']/*[local-name()='coordinates']",xpathCtx);
    13671    xmlXPathFreeContext(xpathCtx);
    137     xmlNodeSet* toto=xpathObj->nodesetval;
    138 
    139     if(toto==NULL)
    140       fprintf(stderr,"IMPOSSIBLE DE CONTINUER !!!!\n");
     72    xmlNodeSet* nSet=xpathObj->nodesetval;
     73
     74    if(nSet==NULL){
     75      setMapInMaps(conf,"lenv","message","Unable to continue !!!");
     76      return SERVICE_FAILED;
     77    }
    14178    char filepath[2048];
    14279    map* tmpMap=getMapFromMaps(conf,"main","tmpPath");
     
    14582    }
    14683    FILE *fo=fopen(filepath,"w");
    147     fprintf(stderr,"File Creation (%s) OK\nPrinting %d Points.\n",filepath,toto->nodeNr);
    148     for(int k=0;k<toto->nodeNr;k++){
    149       xmlNodePtr cur=toto->nodeTab[k];
     84#ifdef DEBUG
     85    fprintf(stderr,"File Creation (%s) OK\nPrinting %d Points.\n",filepath,nSet->nodeNr);
     86#endif
     87    for(int k=0;k<nSet->nodeNr;k++){
     88      xmlNodePtr cur=nSet->nodeTab[k];
    15089      char *val=
    15190        (char*)xmlNodeListGetString(doc,cur->xmlChildrenNode,1);
     
    15998    }
    16099    fclose(fo);
     100#ifdef DEBUG
    161101    fprintf(stderr,"File Close (%s) OK\n",filepath);
     102#endif
    162103
    163104    std::ifstream in(filepath);
    164 
    165     std::istream_iterator<Point1> begin(in);
    166     std::istream_iterator<Point1> end;
    167 
    168     DelaunayTriangulation dt1;
    169     dt1.insert(begin, end);
     105    std::istream_iterator<Point> begin(in);
     106    std::istream_iterator<Point> end;
     107    Triangulation T;
     108    T.insert(begin, end);
    170109
    171110    OGRRegisterAll();
     
    180119
    181120    tmpMap=getMapFromMaps(outputs,"Result","mimeType");
    182     char *oDriver=(char*)malloc(7*sizeof(char));
     121    const char *oDriver;
    183122    oDriver="GeoJSON";
    184123    if(tmpMap!=NULL){
    185124      if(strcmp(tmpMap->value,"text/xml")==0){
    186         fprintf(stderr,"USEING GML \n");
    187125        oDriver="GML";
    188126      }
     
    212150            sprintf( emessage,  "%s  -> `%s'\n", emessage, poR->GetDriver(iDriver)->GetName() );
    213151          }
    214        
    215         fprintf(stderr,"{\"type\": \"error\", \"%s\"}",emessage);   
    216         exit( 1 );
     152
     153        setMapInMaps(conf,"lenv","message",emessage);
     154        return SERVICE_FAILED;
     155
    217156      }
    218157
     
    221160      sprintf( emessage,  "%s driver does not support data source creation.\n",
    222161               "json" );
    223       fprintf(stderr,"{\"type\": \"error\", \"%s\"}",emessage);   
    224       exit( 1 );
    225     }
    226 
    227     /* -------------------------------------------------------------------- */
    228     /*      Create the output data source.                                  */
    229     /* -------------------------------------------------------------------- */
    230     map* tpath=getMapFromMaps(conf,"main","tmpPath");
    231     char *pszDestDataSource=(char*)malloc(strlen(tpath->value)+20);
    232     char **papszDSCO=NULL;
    233     sprintf(pszDestDataSource,"%s/result_%d.json",tpath->value,getpid());
    234     fprintf(stderr,"\n *%s* \n",pszDestDataSource);
    235     poODS = poDriver->CreateDataSource( pszDestDataSource, papszDSCO );
    236     if( poODS == NULL ){
    237       char emessage[1024];     
    238       sprintf( emessage,  "%s driver failed to create %s\n",
    239                "json", pszDestDataSource );
    240       fprintf(stderr,"{\"type\": \"error\", \"%s\"}",emessage);   
    241       exit( 1 );
    242     }
    243 
    244     /* -------------------------------------------------------------------- */
    245     /*      Create the layer.                                               */
    246     /* -------------------------------------------------------------------- */
    247     if( !poODS->TestCapability( ODsCCreateLayer ) )
    248       {
    249         char emessage[1024];
    250         sprintf( emessage,
    251                  "Layer %s not found, and CreateLayer not supported by driver.",
    252                  "Result" );
    253         fprintf(stderr,"{\"type\": \"error\",\"message\": \"%s\"}",emessage);
    254         return FALSE;
    255       }
    256    
    257     CPLErrorReset();
    258    
    259     OGRLayer *poDstLayer = poODS->CreateLayer( "Result", NULL,wkbLineString,NULL);
    260     if( poDstLayer == NULL ){
    261       fprintf( stderr,"Layer creation failed.\n" );
    262       exit( 1 );
    263     }
    264 
    265     Vertex_circulator vc = dt1.incident_vertices(dt1.infinite_vertex()),
    266       done(vc);
    267     if (vc != 0) {
    268       do {std::cout << vc->point() << std::endl;}while(++vc != done);
    269     }
    270 
    271     DelaunayTriangulation::Edge_iterator eit=dt1.edges_begin();
    272     int i=0;
    273     for ( ; eit !=dt1.edges_end(); ++eit) {
    274       fprintf(stderr,"Edge %d\n",i);
    275       i++;
    276       /*CGAL::Object o = dt1.dual(eit);
    277       if (const K::Segment_2 *tmp=CGAL::object_cast<K::Segment_2>(&o)) {
    278         const K::Point_2 p1=tmp->source();
    279         const K::Point_2 p2=tmp->target();
    280         //#ifdef DEBUG
    281         fprintf(stderr,"P1 %d %d | P2 %d %d\n",p1.x(),p1.y(),p2.x(),p2.y());
    282         //#endif
    283         }*/
    284       /*if (const K::Segment_3 *tmp=CGAL::object_cast<K::Segment_3>(eit)) {
    285         const K::Point_3 p1=tmp->source();
    286         const K::Point_3 p2=tmp->target();
    287 #ifdef DEBUG
    288         fprintf(stderr,"P1 %d %d | P2 %d %d\n",p1.x(),p1.y(),p2.x(),p2.y());
    289 #endif
    290         OGRFeatureH hFeature = OGR_F_Create( OGR_L_GetLayerDefn( poDstLayer ) );
    291         OGRGeometryH currLine=OGR_G_CreateGeometry(wkbLineString);
    292         OGR_G_AddPoint_2D(currLine,p1.x(),p1.y());
    293         OGR_G_AddPoint_2D(currLine,p2.x(),p2.y());
    294         OGR_F_SetGeometry( hFeature, currLine );
    295         OGR_G_DestroyGeometry(currLine);
    296         if( OGR_L_CreateFeature( poDstLayer, hFeature ) != OGRERR_NONE ){
    297           fprintf( stderr,"Failed to create feature in file.\n" );
    298           exit( 1 );
    299           }
    300           OGR_F_Destroy( hFeature );*/
    301     }
    302  
    303     int idg=0;
    304     for (DelaunayTriangulation::Face_iterator fit = dt1.faces_begin(); fit!=
    305            dt1.faces_end(); ++fit) {
    306       int idx = 0;
    307       int i0, i1, i2;
    308 
    309       OGRFeatureH hFeature = OGR_F_Create( OGR_L_GetLayerDefn( poDstLayer ) );
    310       OGRGeometryH currLine=OGR_G_CreateGeometry(wkbLineString);
    311      
    312       for(i0=0;i0<3;i0++){
    313         if(!dt1.is_infinite((*fit).vertex(i0)))
    314           OGR_G_AddPoint_2D(currLine,(*fit).vertex(i0)->point().x(),
    315                             (*fit).vertex(i0)->point().y());
    316         if(i0==2 && !dt1.is_infinite((*fit).vertex(0)))
    317           OGR_G_AddPoint_2D(currLine,(*fit).vertex(0)->point().x(),
    318                             (*fit).vertex(0)->point().y());
    319       }
    320       OGR_F_SetGeometry( hFeature, currLine );
    321       OGR_G_DestroyGeometry(currLine);
    322       if( OGR_L_CreateFeature( poDstLayer, hFeature ) != OGRERR_NONE ){
    323         fprintf( stderr,"Failed to create feature in file.\n" );
    324         exit( 1 );
    325       }
    326       OGR_F_Destroy( hFeature );
    327 
    328       /*OGRFeatureH hFeature=NULL;
    329       OGRGeometryH currLine=NULL;
    330       if(idg==0) {
    331         hFeature = OGR_F_Create( OGR_L_GetLayerDefn( poDstLayer ) );
    332         currLine=OGR_G_CreateGeometry(wkbLineString);     
    333         }*/
    334 
    335       for (DelaunayTriangulation::Vertex_iterator vit = dt1.vertices_begin(); vit!=
    336              dt1.vertices_end(); ++vit) {
    337         idx++;
    338         /*if(idg==0)
    339           OGR_G_AddPoint_2D(currLine,(*vit).point().x(),
    340           (*vit).point().y());*/
    341 
    342 
    343         if ((*vit).point() == (*fit).vertex(0)->point()){
    344           i0 = idx;
    345           /*OGR_G_AddPoint_2D(currLine,(*fit).vertex(i0)->point().x(),
    346             (*fit).vertex(i0)->point().y());**/
    347         }
    348         if ((*vit).point() == (*fit).vertex(1)->point()){ 
    349           i1 = idx;
    350           /*OGR_G_AddPoint_2D(currLine,(*fit).vertex(i1)->point().x(),
    351             (*fit).vertex(i1)->point().y());*/
    352         }
    353         if ((*vit).point() == (*fit).vertex(2)->point()){ 
    354           i2 = idx;
    355           /*OGR_G_AddPoint_2D(currLine,(*fit).vertex(i2)->point().x(),
    356             (*fit).vertex(i2)->point().y());*/
    357         }
    358       }
    359       /*if(idg==0){
    360         OGR_F_SetGeometry( hFeature, currLine );
    361         OGR_G_DestroyGeometry(currLine);
    362         if( OGR_L_CreateFeature( poDstLayer, hFeature ) != OGRERR_NONE ){
    363           fprintf( stderr,"Failed to create feature in file.\n" );
    364           exit( 1 );
    365         }
    366         OGR_F_Destroy( hFeature );
    367         idg++;
    368         }*/
    369 
    370       std::cerr << "f " << i0 << " " << dt1.triangle(fit) << std::endl;
    371      
    372     }
    373     OGR_DS_Destroy( poODS );
    374     OGRCleanupAll();
    375 
    376  
    377     char tmp1[1024];
    378     outputs=(maps*)malloc(sizeof(maps*));
    379     outputs->name="Result";
    380 
    381     FILE * fichier=fopen(pszDestDataSource,"r");
    382     struct stat file_status;
    383     stat(pszDestDataSource, &file_status);
    384     fprintf(stderr,"%s (%d)",pszDestDataSource,file_status.st_size);
    385     char *res1=(char *)malloc(file_status.st_size*sizeof(char));
    386     if(fichier==NULL)
    387       fprintf(stderr,"Failed to open file %s for reading purpose.\n",pszDestDataSource);
    388     fread(res1,1,(file_status.st_size)*sizeof(char),fichier);
    389     res1[strlen(res1)]=0;
    390     fclose(fichier);
    391     //unlink(pszDestDataSource);
    392     //fprintf(stderr,"Read (%s).\n",res1);
    393    
    394     outputs->content=createMap("value",res1);
    395    
    396     if(strcmp(oDriver,"GML")==0)
    397       addMapToMap(&outputs->content,createMap("mimeType","text/xml"));
    398     else
    399       addMapToMap(&outputs->content,createMap("mimeType","text/plain"));
    400 
    401     addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
    402     outputs->next=NULL;
    403     fprintf(stderr,"\nService internal print\n===\n");
    404     xmlCleanupParser();
    405 
    406     return SERVICE_SUCCEEDED;
    407   }
    408  
    409 
    410   int Voronoi(maps*& conf,maps*& inputs,maps*& outputs){
    411     fprintf(stderr,"\nService internal print\nStarting\n");
    412     maps* cursor=inputs;
    413     OGRGeometryH geometry,res;
    414     int bufferDistance;
    415     xmlInitParser();
    416     map* tmpm=NULL;
    417     tmpm=getMapFromMaps(inputs,"InputPoints","value");
    418    
    419     xmlInitParser();
    420     xmlDocPtr doc =
    421       xmlParseMemory(tmpm->value,strlen(tmpm->value));
    422     xmlNodePtr cur = xmlDocGetRootElement(doc);
    423     /**
    424      * Parse every Input in DataInputs node.
    425      */
    426     maps* tempMaps=NULL;
    427     xmlXPathContextPtr xpathCtx;
    428     xmlXPathObjectPtr xpathObj;
    429     xpathCtx = xmlXPathNewContext(doc);
    430     xpathObj = xmlXPathEvalExpression(BAD_CAST "/*/*[local-name()='featureMember']/*/*/*[local-name()='Point']/*[local-name()='coordinates']",xpathCtx);
    431     xmlXPathFreeContext(xpathCtx);
    432     xmlNodeSet* toto=xpathObj->nodesetval;
    433 
    434     if(toto==NULL)
    435       fprintf(stderr,"IMPOSSIBLE DE CONTINUER !!!!\n");
    436     char filepath[2048];
    437     map* tmpMap=getMapFromMaps(conf,"main","tmpPath");
    438     if(tmpMap!=NULL){
    439       sprintf(filepath,"%s/varonoi_%d.tmp",tmpMap->value,getpid());
    440     }
    441     FILE *fo=fopen(filepath,"w");
    442     fprintf(stderr,"File Creation (%s) OK\nPrinting %d Points.\n",filepath,toto->nodeNr);
    443     for(int k=0;k<toto->nodeNr;k++){
    444       xmlNodePtr cur=toto->nodeTab[k];
    445       char *val=
    446         (char*)xmlNodeListGetString(doc,cur->xmlChildrenNode,1);
    447       char *tmp=strstr(val,",");
    448       char tmp1[1024];
    449       strncpy(tmp1,val,strlen(val)-strlen(tmp));
    450       tmp1[strlen(val)-strlen(tmp)]=0;
    451       char buff[1024];
    452       sprintf(buff,"%s %s\n",tmp1,tmp+1);
    453       fwrite(buff,1,strlen(buff)*sizeof(char),fo);
    454     }
    455     fclose(fo);
    456     fprintf(stderr,"File Close (%s) OK\n",filepath);
    457 
    458     std::ifstream in(filepath);
    459     std::istream_iterator<Point> begin(in);
    460     std::istream_iterator<Point> end;
    461     Triangulation T;
    462     T.insert(begin, end);
    463 
    464     OGRRegisterAll();
    465     /* -------------------------------------------------------------------- */
    466     /*      Try opening the output datasource as an existing, writable      */
    467     /* -------------------------------------------------------------------- */
    468     OGRDataSource       *poODS;
    469    
    470     OGRSFDriverRegistrar *poR = OGRSFDriverRegistrar::GetRegistrar();
    471     OGRSFDriver          *poDriver = NULL;
    472     int                  iDriver;
    473 
    474     tmpMap=getMapFromMaps(outputs,"Result","mimeType");
    475     char *oDriver=(char*)malloc(7*sizeof(char));
    476     oDriver="GeoJSON";
    477     if(tmpMap!=NULL){
    478       if(strcmp(tmpMap->value,"text/xml")==0){
    479         fprintf(stderr,"USEING GML \n");
    480         oDriver="GML";
    481       }
    482     }
    483    
    484     for( iDriver = 0;
    485          iDriver < poR->GetDriverCount() && poDriver == NULL;
    486          iDriver++ )
    487       {
    488 #ifdef DEBUG
    489         fprintf(stderr,"D:%s\n",poR->GetDriver(iDriver)->GetName());
    490 #endif
    491         if( EQUAL(poR->GetDriver(iDriver)->GetName(),oDriver) )
    492           {
    493             poDriver = poR->GetDriver(iDriver);
    494           }
    495       }
    496 
    497     if( poDriver == NULL )
    498       {
    499         char emessage[8192];
    500         sprintf( emessage, "Unable to find driver `%s'.\n", oDriver );
    501         sprintf( emessage,  "%sThe following drivers are available:\n",emessage );
    502        
    503         for( iDriver = 0; iDriver < poR->GetDriverCount(); iDriver++ )
    504           {
    505             sprintf( emessage,  "%s  -> `%s'\n", emessage, poR->GetDriver(iDriver)->GetName() );
    506           }
    507        
    508         fprintf(stderr,"{\"type\": \"error\", \"%s\"}",emessage);   
    509         exit( 1 );
    510       }
    511 
    512     if( !poDriver->TestCapability( ODrCCreateDataSource ) ){
    513       char emessage[1024];
    514       sprintf( emessage,  "%s driver does not support data source creation.\n",
    515                "json" );
    516       fprintf(stderr,"{\"type\": \"error\", \"%s\"}",emessage);   
    517       exit( 1 );
     162      setMapInMaps(conf,"lenv","message",emessage);
     163      return SERVICE_FAILED;
    518164    }
    519165
     
    530176      sprintf( emessage,  "%s driver failed to create %s\n",
    531177               "json", pszDestDataSource );
    532       fprintf(stderr,"{\"type\": \"error\", \"%s\"}",emessage);   
    533       exit( 1 );
     178      setMapInMaps(conf,"lenv","message",emessage);
     179      return SERVICE_FAILED;
    534180    }
    535181
     
    543189                 "Layer %s not found, and CreateLayer not supported by driver.",
    544190                 "Result" );
    545         fprintf(stderr,"{\"type\": \"error\",\"message\": \"%s\"}",emessage);
    546         return FALSE;
     191        setMapInMaps(conf,"lenv","message",emessage);
     192        return SERVICE_FAILED;
    547193      }
    548194   
     
    551197    OGRLayer *poDstLayer = poODS->CreateLayer( "Result", NULL,wkbLineString,NULL);
    552198    if( poDstLayer == NULL ){
    553       fprintf( stderr,"Layer creation failed.\n" );
    554       exit( 1 );
     199      setMapInMaps(conf,"lenv","message","Layer creation failed.\n");
     200      return SERVICE_FAILED;
    555201    }
    556202
     
    574220        OGR_G_DestroyGeometry(currLine);
    575221        if( OGR_L_CreateFeature( poDstLayer, hFeature ) != OGRERR_NONE ){
    576           fprintf( stderr,"Failed to create feature in file.\n" );
    577           exit( 1 );
     222          setMapInMaps(conf,"lenv","message","Failed to create feature in file.\n");
     223          return SERVICE_FAILED;
    578224        }
    579225        OGR_F_Destroy( hFeature );
     
    592238   
    593239    char tmp1[1024];
    594     outputs=(maps*)malloc(sizeof(maps*));
    595     outputs->name="Result";
    596240
    597241    FILE * fichier=fopen(pszDestDataSource,"r");
    598242    struct stat file_status;
    599243    stat(pszDestDataSource, &file_status);
    600     //fprintf(stderr,"%s (%d)",pszDestDataSource,file_status.st_size);
    601244    char *res1=(char *)malloc(file_status.st_size*sizeof(char));
    602     if(fichier==NULL)
    603       fprintf(stderr,"Failed to open file %s for reading purpose.\n",pszDestDataSource);
     245    if(fichier==NULL){
     246      char tmp[1024];
     247      sprintf(tmp,"Failed to open file %s for reading purpose.\n",
     248              pszDestDataSource);
     249      setMapInMaps(conf,"lenv","message",tmp);
     250      return SERVICE_FAILED;
     251    }
    604252    fread(res1,1,(file_status.st_size)*sizeof(char),fichier);
    605253    res1[strlen(res1)]=0;
    606254    fclose(fichier);
    607255    unlink(pszDestDataSource);
    608     //fprintf(stderr,"Read (%s).\n",res1);
    609    
    610     outputs->content=createMap("value",res1);
     256   
     257    setMapInMaps(outputs,"Result","value",res1);
    611258   
    612259    if(strcmp(oDriver,"GML")==0)
    613       addMapToMap(&outputs->content,createMap("mimeType","text/xml"));
     260      setMapInMaps(outputs,"Result","mimeType","text/xml");
    614261    else
    615       addMapToMap(&outputs->content,createMap("mimeType","text/plain"));
    616 
    617     addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
    618     outputs->next=NULL;
     262      setMapInMaps(outputs,"Result","mimeType","text/plain");
     263
     264    setMapInMaps(outputs,"Result","encoding","UTF-8");
     265#ifdef DEBUG
    619266    fprintf(stderr,"\nService internal print\n===\n");
     267#endif
    620268    xmlCleanupParser();
    621269    return SERVICE_SUCCEEDED;
  • branches/branch-1.2/zoo-services/ogr/base-vect-ops/makefile.vc

    r1 r217  
    1 GEODIR=c:/OSGeo4W/
    2 TOOLS=c:/Users/djay/GeoLabs/tools/
    3 CFLAGS=-I$(GEODIR)/include -I$(TOOLS)/include -I../../../zoo-kernel/ -I./ -DLINUX_FREE_ISSUE -DDEBUG
     1ZOODIR=../../../zoo-kernel
     2THIRDSDIR=../../../thirds
     3!INCLUDE $(ZOODIR)/nmake.opt
     4CFLAGS=-I$(GEODIR)/include -I$(TPATH)/include -I$(ZOODIR) -I./ -DLINUX_FREE_ISSUE -DWIN32 #-DDEBUG
    45CPP=cl /TP
    56
    6 cgi-env/service.zo: service.c
     7cgi-env/ogr_service.zo: service.c
    78        $(CPP) $(CFLAGS) /c service.c
    8         link /dll /out:cgi-env/ogr_service.zso ../../../zoo-kernel/service_internal.obj ./service.obj -L$(TOOLS)/lib/libssl32.dll.a $(GEODIR)/lib/libxml2.lib $(GEODIR)/lib/gdal_i.lib $(TOOLS)/lib/libeay32.dll.a $(TOOLS)/lib/libcrypto.a $(TOOLS)/lib/libssl32.dll.a
     9        link /dll /out:cgi-env/ogr_service.zo ../../../zoo-kernel/service_internal.obj ./service.obj -L$(TOOLS)/lib/libssl32.dll.a $(GEODIR)/lib/libxml2.lib $(GEODIR)/lib/gdal_i.lib $(GEODIR)/lib/geos_c_i.lib $(TPATH)/lib/libeay32.dll.a $(TPATH)/lib/libcrypto.a $(TPATH)/lib/libssl32.dll.a $(LIBINTL_CPATH)/lib/libintl.lib
    910
    1011clean:
    11         rm -f cgi-env/ogr_service.zso
     12        erase cgi-env\ogr_service.*
  • branches/branch-1.2/zoo-services/ogr/base-vect-ops/service.c

    r55 r217  
    4343
    4444  void printExceptionReportResponse(maps*,map*);
    45   char *base64(const unsigned char *input, int length);
     45  char *base64(const char *input, int length);
    4646
    4747  OGRGeometryH createGeometryFromGML(maps* conf,char* inputStr){
     
    5656    xpathObj = xmlXPathEvalExpression(BAD_CAST xpathExpr,xpathCtx);
    5757    if(!xpathObj->nodesetval){
    58       map* tmp=createMap("text","Unable to parse Input Polygon");
    59       addToMap(tmp,"code","InvalidParameterValue");
    60       printExceptionReportResponse(conf,tmp);
    61       exit(0);
     58      setMapInMaps(conf,"lenv","message",_ss("Unable to parse Input Polygon"));
     59      setMapInMaps(conf,"lenv","code","InvalidParameterValue");
     60      return NULL;
    6261    }
    6362    int size = (xpathObj->nodesetval) ? xpathObj->nodesetval->nodeNr : 0;
     
    8079    xmlFreeDoc(doc);
    8180    xmlFreeDoc(ndoc);
     81#ifndef WIN32
    8282    xmlCleanupParser();
     83#endif
    8384#ifdef DEBUG
    8485    fprintf(stderr,"\nService internal print\n Loading the geometry from GML string ...");
     
    9495  }
    9596
     97#ifdef WIN32
     98  __declspec(dllexport)
     99#endif
    96100  int Simplify(maps*& conf,maps*& inputs,maps*& outputs){
    97101    maps* cursor=inputs;
     
    104108    else
    105109      tolerance=atof(tmp0->value);
     110#ifdef DEBUG
    106111    fprintf(stderr,"Tolerance for Simplify %f",tolerance);
     112#endif
    107113    map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
    108114    if(!tmp){
     
    126132      return SERVICE_FAILED;
    127133    }
     134#ifdef DEBUG
    128135    fprintf(stderr,"Create GEOSGeometry object");
     136#endif
    129137    GEOSGeometry* ggeometry=((OGRGeometry *) geometry)->exportToGEOS();
    130138    GEOSGeometry* gres=GEOSTopologyPreserveSimplify(ggeometry,tolerance);
    131     res=OGRGeometryFactory::createFromGEOS(gres);
     139    res=(OGRGeometryH)OGRGeometryFactory::createFromGEOS(gres);
    132140    tmp1=getMapFromMaps(outputs,"Result","mimeType");
    133141    if(tmp1!=NULL){
     
    136144        char *tmpS=OGR_G_ExportToJson(res);
    137145        setMapInMaps(outputs,"Result","value",tmpS);
     146#ifndef WIN32
    138147        setMapInMaps(outputs,"Result","mimeType","text/plain");
    139148        setMapInMaps(outputs,"Result","encoding","UTF-8");
    140149        free(tmpS);
     150#endif
    141151      }
    142152      else{
    143153        char *tmpS=OGR_G_ExportToGML(res);
    144154        setMapInMaps(outputs,"Result","value",tmpS);
     155#ifndef WIN32
    145156        setMapInMaps(outputs,"Result","mimeType","text/xml");
    146157        setMapInMaps(outputs,"Result","encoding","UTF-8");
    147158        setMapInMaps(outputs,"Result","schema","http://fooa/gml/3.1.0/polygon.xsd");
    148159        free(tmpS);
     160#endif
    149161      }
    150162    }else{
    151       char *tmpS=OGR_G_ExportToJson(tmp->value);
     163      char *tmpS=OGR_G_ExportToJson(res);
    152164      setMapInMaps(outputs,"Result","value",tmpS);
     165#ifndef WIN32
    153166      setMapInMaps(outputs,"Result","mimeType","text/plain");
    154167      setMapInMaps(outputs,"Result","encoding","UTF-8");
    155168      free(tmpS);
     169#endif
    156170    }
    157171    outputs->next=NULL;
     
    178192      return SERVICE_FAILED;
    179193    }
     194#ifdef DEBUG
    180195    fprintf(stderr,"Service internal print \n");
    181196    dumpMaps(inputs);
    182197    fprintf(stderr,"/Service internal print \n");
     198#endif
    183199    map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType");
     200#ifdef DEBUG
    184201    fprintf(stderr,"Service internal print \n");
    185202    dumpMap(tmp1);
    186203    fprintf(stderr,"/Service internal print \n");
     204#endif
    187205    if(tmp1!=NULL){
    188206      if(strncmp(tmp1->value,"text/js",7)==0 ||
     
    199217    }
    200218    res=(*myFunc)(geometry);
     219#ifdef DEBUG
    201220    fprintf(stderr,"Service internal print \n");
    202221    dumpMaps(outputs);
    203222    fprintf(stderr,"/Service internal print \n");
     223#endif
    204224    map *tmp_2=getMapFromMaps(outputs,"Result","mimeType");
     225#ifdef DEBUG
    205226    fprintf(stderr,"Service internal print \n");
    206227    dumpMap(tmp_2);
    207228    fprintf(stderr,"/Service internal print \n");
     229#endif
    208230    if(tmp_2!=NULL){
    209231      if(strncmp(tmp_2->value,"text/js",7)==0 ||
     
    211233        char *tmpS=OGR_G_ExportToJson(res);
    212234        setMapInMaps(outputs,"Result","value",tmpS);
     235#ifndef WIN32
    213236        setMapInMaps(outputs,"Result","mimeType","text/plain");
    214237        setMapInMaps(outputs,"Result","encoding","UTF-8");
    215238        free(tmpS);
     239#endif
    216240      }
    217241      else{
    218242        char *tmpS=OGR_G_ExportToGML(res);
    219243        setMapInMaps(outputs,"Result","value",tmpS);
     244#ifndef WIN32
    220245        setMapInMaps(outputs,"Result","mimeType","text/xml");
    221246        setMapInMaps(outputs,"Result","encoding","UTF-8");
    222247        setMapInMaps(outputs,"Result","schema",schema);
    223248        free(tmpS);
     249#endif
    224250      }
    225251    }else{
    226252      char *tmpS=OGR_G_ExportToJson(res);
    227253      setMapInMaps(outputs,"Result","value",tmpS);
     254#ifndef WIN32
    228255      setMapInMaps(outputs,"Result","mimeType","text/plain");
    229256      setMapInMaps(outputs,"Result","encoding","UTF-8");
    230257      free(tmpS);
    231     }
    232     outputs->next=NULL;
     258#endif
     259    }
     260    //outputs->next=NULL;
    233261#ifdef DEBUG
    234262    dumpMaps(outputs);
     
    239267    //CPLFree(res);
    240268    //CPLFree(geometry);
     269#ifdef DEBUG
    241270    fprintf(stderr,"Service internal print \n");
    242271    dumpMaps(outputs);
    243272    fprintf(stderr,"/Service internal print \n");
     273#endif
    244274    return SERVICE_SUCCEEDED;
    245275  }
     
    276306     bufferDistance=atof(tmp->value);
    277307   res=OGR_G_Buffer(geometry,bufferDistance,30);
     308   dumpMap(tmp);
    278309   tmp1=getMapFromMaps(outputs,"Result","mimeType");
     310   dumpMap(tmp);
    279311   if(strncmp(tmp1->value,"application/json",16)==0){
    280312     char *tmpS=OGR_G_ExportToJson(res);
    281313     setMapInMaps(outputs,"Result","value",tmpS);
     314     dumpMap(tmp);
     315#ifndef WIN32
    282316     setMapInMaps(outputs,"Result","mimeType","text/plain");
    283317     setMapInMaps(outputs,"Result","encoding","UTF-8");
    284318     free(tmpS);
     319#endif
    285320   }
    286321   else{
    287322     char *tmpS=OGR_G_ExportToGML(res);
    288323     setMapInMaps(outputs,"Result","value",tmpS);
     324     dumpMap(tmp);
     325#ifndef WIN32
    289326     free(tmpS);
    290327     setMapInMaps(outputs,"Result","mimeType","text/xml");
    291328     setMapInMaps(outputs,"Result","encoding","UTF-8");
    292329     setMapInMaps(outputs,"Result","schema","http://fooa/gml/3.1.0/polygon.xsd");
     330#endif
    293331   }
    294    outputs->next=NULL;
     332   //outputs->next=NULL;
    295333   OGR_G_DestroyGeometry(geometry);
    296334   OGR_G_DestroyGeometry(res);
     
    335373    fprintf(stderr,"\nService internal print1\n");
    336374    fflush(stderr);
    337 #endif
    338375    fprintf(stderr,"\nService internal print1\n");
    339376    dumpMaps(inputs);
    340377    fprintf(stderr,"\nService internal print1\n");
     378#endif
    341379
    342380    maps* cursor=inputs;
     
    357395    if(geometry1==NULL){
    358396      setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry for InputEntity1."));
     397#ifdef DEBUG
    359398      fprintf(stderr,"SERVICE FAILED !\n");
    360       return SERVICE_FAILED;
    361     }
     399#endif
     400      return SERVICE_FAILED;
     401    }
     402#ifdef DEBUG
    362403    fprintf(stderr,"\nService internal print1 InputEntity1\n");
     404#endif
    363405    {
    364406      map* tmp=getMapFromMaps(inputs,"InputEntity2","value");
    365407      map* tmp1=getMapFromMaps(inputs,"InputEntity2","mimeType");
    366       //#ifdef DEBUG
     408#ifdef DEBUG
    367409      fprintf(stderr,"MY MAP \n[%s] - %i\n",tmp1->value,strncmp(tmp1->value,"application/json",16));
    368410      //dumpMap(tmp);
    369411      fprintf(stderr,"MY MAP\n");
    370       ///#endif
    371412      fprintf(stderr,"\nService internal print1 InputEntity2\n");
     413#endif
    372414      if(tmp1!=NULL){
    373415        if(strncmp(tmp1->value,"application/json",16)==0){
     416#ifdef DEBUG
    374417          fprintf(stderr,"\nService internal print1 InputEntity2 as JSON\n");
     418#endif
    375419          geometry2=OGR_G_CreateGeometryFromJson(tmp->value);
    376420        }
    377421        else{
     422#ifdef DEBUG
    378423          fprintf(stderr,"\nService internal print1 InputEntity2 as GML\n");
     424#endif
    379425          geometry2=createGeometryFromGML(conf,tmp->value);
    380426        }
     
    382428      else
    383429        geometry2=createGeometryFromGML(conf,tmp->value);
     430#ifdef DEBUG
    384431      fprintf(stderr,"\nService internal print1 InputEntity2 PreFinal\n");
    385     }
     432#endif
     433    }
     434#ifdef DEBUG
    386435    fprintf(stderr,"\nService internal print1 InputEntity2 Final\n");
     436#endif
    387437    if(geometry2==NULL){
    388438      setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry for InputEntity2."));
     439#ifdef DEBUG
    389440      fprintf(stderr,"SERVICE FAILED !\n");
    390       return SERVICE_FAILED;
    391     }
     441#endif
     442      return SERVICE_FAILED;
     443    }
     444#ifdef DEBUG
    392445    fprintf(stderr,"\nService internal print1\n");
     446#endif
    393447    res=(*myFunc)(geometry1,geometry2);
     448#ifdef DEBUG
    394449    fprintf(stderr,"\nService internal print1\n");
    395    
     450#endif   
    396451    /* nuova parte */
    397452    map* tmp2=getMapFromMaps(outputs,"Result","mimeType");
     
    399454      char *tmpS=OGR_G_ExportToJson(res);
    400455      setMapInMaps(outputs,"Result","value",tmpS);
     456#ifndef WIN32
    401457      setMapInMaps(outputs,"Result","mimeType","text/plain");
    402458      setMapInMaps(outputs,"Result","encoding","UTF-8");
    403459      free(tmpS);
     460#endif
    404461    }
    405462    else{
    406463      char *tmpS=OGR_G_ExportToGML(res);
    407464      setMapInMaps(outputs,"Result","value",tmpS);
     465#ifndef WIN32
    408466      setMapInMaps(outputs,"Result","mimeType","text/xml");
    409467      setMapInMaps(outputs,"Result","encoding","UTF-8");
    410468      setMapInMaps(outputs,"Result","schema","http://fooa/gml/3.1.0/polygon.xsd");
    411469      free(tmpS);
     470#endif
    412471    }
    413472   
  • branches/branch-1.2/zoo-services/utils/status/service.c

    r34 r217  
    2424
    2525#include "service.h"
     26#ifdef WIN32
     27#include <windows.h>
     28#endif
    2629
    2730extern "C" {
     
    135138      setMapInMaps(conf,"lenv","status",tmp);
    136139      updateStatus(conf);
     140#ifndef WIN32
    137141      sleep(1);
     142#else
     143      Sleep(1000);
     144#endif
    138145      i+=5;
    139146    }
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