Ignore:
Timestamp:
Sep 14, 2010, 2:04:55 PM (14 years ago)
Author:
djay
Message:

Update of both ZOO Kernel and ZOO Services (ogr base-vect-ops ServicesProvider?).
All the ZCFG files have been corrected to remove all references to wrong metadata (Test = Demo) to avoid validation issues.
Main Memory leaks has been removed from this version.
Addition of the Simplify Service in the C ogr base-vect-ops ServicesProvider? and addition of the Python version (without Simplify).
Update of the configure.ac and Makefile.in to follow dicussions on the mailing list and ensure to use our cgic206 and not another one, path to our cgic library is now directly in the Makefile.in file.
Accept the "-" character to name inputs, to solve issue on GRASS 7 integration.
Addition of the extension keyword for ZCFG file to be able to store resulting outputs in a file name using the extension suffix.
This version after a testing period shall be considerate as 1.0.1 version of the ZOO Project.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/zoo-services/ogr/base-vect-ops/service.c

    r1 r9  
    2323 */
    2424
    25 #include "cpl_minixml.h"
     25#include "cpl_conv.h"
    2626#include "ogr_api.h"
     27#include "ogr_geometry.h"
     28#include "geos_c.h"
    2729#include "service.h"
    2830
     
    3941#include <openssl/buffer.h>
    4042
    41   xmlNodeSet* extractFromDoc(xmlDocPtr,char*);
    4243  void printExceptionReportResponse(maps*,map*);
    4344  char *base64(const unsigned char *input, int length);
     
    7172    }
    7273    xmlDocDumpFormatMemory(ndoc, &xmlbuff, &buffersize, 1);
    73     char *tmp=strdup(strstr((char*)xmlbuff,"?>")+2);
     74    char *tmp=(char*)calloc((xmlStrlen(xmlStrstr(xmlbuff,BAD_CAST "?>"))-1),sizeof(char));
     75    sprintf(tmp,"%s",xmlStrstr(xmlbuff,BAD_CAST "?>")+2);
     76    //strdup(strstr((char*)xmlbuff,"?>")+2);
    7477    xmlXPathFreeObject(xpathObj);
    75     xmlXPathFreeContext(xpathCtx); 
     78    xmlXPathFreeContext(xpathCtx);
    7679    xmlFree(xmlbuff);
    7780    xmlFreeDoc(doc);
     81    xmlFreeDoc(ndoc);
    7882    xmlCleanupParser();
    7983#ifdef DEBUG
     
    8185#endif
    8286    OGRGeometryH res=OGR_G_CreateFromGML(tmp);
     87    free(tmp);
    8388    if(res==NULL){
    84         map* tmp=createMap("text","Unable to call OGR_G_CreatFromGML");
    85         addToMap(tmp,"code","NoApplicableCode");
    86         printExceptionReportResponse(conf,tmp);
    87         exit(0);
     89      map* tmp=createMap("text","Unable to call OGR_G_CreatFromGML");
     90      addToMap(tmp,"code","NoApplicableCode");
     91      printExceptionReportResponse(conf,tmp);
     92      exit(0);
    8893    }
    8994    else
    90         return OGR_G_CreateFromGML(tmp);
     95      return res;//OGR_G_CreateFromGML(tmp);
     96  }
     97
     98  int Simplify(maps*& conf,maps*& inputs,maps*& outputs){
     99    maps* cursor=inputs;
     100    OGRGeometryH geometry,res;
     101    double tolerance;
     102    map* tmp0=getMapFromMaps(cursor,"Tolerance","value");
     103    if(tmp0==NULL){
     104      tolerance=atof("2.0");
     105    }
     106    else
     107      tolerance=atof(tmp0->value);
     108    fprintf(stderr,"Tolerance for Simplify %f",tolerance);
     109    map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
     110    if(!tmp)
     111      return SERVICE_FAILED;
     112    map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeTime");
     113    if(tmp1!=NULL){
     114      if(strncmp(tmp1->value,"text/js",7)==0 ||
     115         strncmp(tmp1->value,"application/json",7)==0)
     116        geometry=OGR_G_CreateGeometryFromJson(tmp->value);
     117      else
     118        geometry=createGeometryFromGML(conf,tmp->value);
     119    }
     120    else
     121      geometry=createGeometryFromGML(conf,tmp->value);
     122    GEOSGeometry* ggeometry=((OGRGeometry *) geometry)->exportToGEOS();
     123    GEOSGeometry* gres=GEOSTopologyPreserveSimplify(ggeometry,tolerance);
     124    res=OGRGeometryFactory::createFromGEOS(gres);
     125    if(tmp1!=NULL){
     126      if(strncmp(tmp1->value,"text/js",7)==0 ||
     127         strncmp(tmp1->value,"application/json",16)==0){
     128        outputs->content=createMap("value",OGR_G_ExportToJson(tmp->value));
     129        addMapToMap(&outputs->content,createMap("mimeType","text/plain"));
     130        addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
     131      }
     132      else{
     133        outputs->content=createMap("value",OGR_G_ExportToGML(res));
     134        addMapToMap(&outputs->content,createMap("mimeType","text/xml"));
     135        addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
     136        addMapToMap(&outputs->content,createMap("schema","http://fooa/gml/3.1.0/polygon.xsd"));
     137      }
     138    }else{
     139      outputs->content=createMap("value",OGR_G_ExportToJson(res));
     140      addMapToMap(&outputs->content,createMap("mimeType","text/plain"));
     141      addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
     142    }
     143    outputs->next=NULL;
     144    //GEOSFree(ggeometry);
     145    //GEOSFree(gres);
     146    OGR_G_DestroyGeometry(res);
     147    OGR_G_DestroyGeometry(geometry);
     148    return SERVICE_SUCCEEDED;
     149  }
     150
     151
     152  int applyOne(maps*& conf,maps*& inputs,maps*& outputs,OGRGeometryH (*myFunc)(OGRGeometryH)){
     153#ifdef DEBUG
     154    fprintf(stderr,"\nService internal print\n");
     155#endif
     156    maps* cursor=inputs;
     157    OGRGeometryH geometry,res;
     158#ifdef DEBUG
     159    dumpMaps(cursor);
     160#endif
     161    map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
     162    if(!tmp)
     163      return SERVICE_FAILED;
     164    fprintf(stderr,"Service internal print \n");
     165    dumpMaps(inputs);
     166    fprintf(stderr,"/Service internal print \n");
     167    map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType");
     168    fprintf(stderr,"Service internal print \n");
     169    dumpMap(tmp1);
     170    fprintf(stderr,"/Service internal print \n");
     171    if(tmp1!=NULL){
     172      if(strncmp(tmp1->value,"text/js",7)==0 ||
     173         strncmp(tmp1->value,"application/json",7)==0)
     174        geometry=OGR_G_CreateGeometryFromJson(tmp->value);
     175      else
     176        geometry=createGeometryFromGML(conf,tmp->value);
     177    }
     178    else
     179      geometry=createGeometryFromGML(conf,tmp->value);
     180    res=(*myFunc)(geometry);
     181    fprintf(stderr,"Service internal print \n");
     182    dumpMaps(outputs);
     183    fprintf(stderr,"/Service internal print \n");
     184    map *tmp_2=getMapFromMaps(outputs,"Result","mimeType");
     185    fprintf(stderr,"Service internal print \n");
     186    dumpMap(tmp_2);
     187    fprintf(stderr,"/Service internal print \n");
     188    if(tmp_2!=NULL){
     189      if(strncmp(tmp_2->value,"text/js",7)==0 ||
     190         strncmp(tmp_2->value,"application/json",16)==0){
     191        char *tres=OGR_G_ExportToJson(res);
     192        addToMap(outputs->content,"value",tres);
     193        free(tres);
     194        addToMap(outputs->content,"mimeType","text/plain");
     195        addToMap(outputs->content,"encoding","UTF-8");
     196      }
     197      else{
     198        char *tres=OGR_G_ExportToGML(res);
     199        addToMap(outputs->content,"value",tres);
     200        free(tres);
     201      }
     202    }else{
     203      char *tres=OGR_G_ExportToJson(res);
     204      addToMap(outputs->content,"value",tres);
     205      free(tres);
     206      addToMap(outputs->content,"mimeType","text/plain");
     207      addToMap(outputs->content,"encoding","UTF-8");
     208    }
     209    outputs->next=NULL;
     210#ifdef DEBUG
     211    dumpMaps(outputs);
     212    fprintf(stderr,"\nService internal print\n===\n");
     213#endif
     214    OGR_G_DestroyGeometry(res);
     215    OGR_G_DestroyGeometry(geometry);
     216    //CPLFree(res);
     217    //CPLFree(geometry);
     218    fprintf(stderr,"Service internal print \n");
     219    dumpMaps(outputs);
     220    fprintf(stderr,"/Service internal print \n");
     221    return SERVICE_SUCCEEDED;
     222  }
     223
     224#ifdef WIN32
     225  __declspec(dllexport)
     226#endif
     227int Buffer(maps*& conf,maps*& inputs,maps*& outputs){
     228   OGRGeometryH geometry,res;
     229   map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
     230   if(tmp==NULL)
     231     return SERVICE_FAILED;
     232   map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType");
     233   if(strncmp(tmp1->value,"application/json",16)==0)
     234     geometry=OGR_G_CreateGeometryFromJson(tmp->value);
     235   else
     236     geometry=createGeometryFromGML(conf,tmp->value);
     237   int bufferDistance=1;
     238   tmp=getMapFromMaps(inputs,"BufferDistance","value");
     239   if(tmp!=NULL)
     240                bufferDistance=atoi(tmp->value);
     241   res=OGR_G_Buffer(geometry,bufferDistance,30);
     242   tmp1=getMapFromMaps(outputs,"Result","mimeType");
     243   if(strncmp(tmp1->value,"application/json",16)==0){
     244                addToMap(outputs->content,"value",OGR_G_ExportToJson(res));
     245                addToMap(outputs->content,"mimeType","text/plain");
     246   }
     247   else{
     248                addToMap(outputs->content,"value",OGR_G_ExportToGML(res));
     249   }
     250   outputs->next=NULL;
     251   OGR_G_DestroyGeometry(geometry);
     252   OGR_G_DestroyGeometry(res);
     253   return SERVICE_SUCCEEDED;
     254}
     255
     256/*  int Buffer(maps*& conf,maps*& inputs,maps*& outputs){
     257#ifdef DEBUG
     258    fprintf(stderr,"\nService internal print\n");
     259#endif
     260    maps* cursor=inputs;
     261    OGRGeometryH geometry,res;
     262    int bufferDistance;   
     263    if(cursor!=NULL){
     264#ifdef DEBUG
     265      fprintf(stderr,"\nService internal print\n");
     266      dumpMaps(cursor);
     267      fprintf(stderr,"\nService internal print\n");
     268      dumpMaps(inputs);
     269      fprintf(stderr,"\nService internal print\n");
     270#endif
     271      map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
     272      map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType");
     273      if(tmp1!=NULL){
     274        if(strncmp(tmp1->value,"application/json",16)==0 ||
     275           strncmp(tmp1->value,"text/js",7)==0)
     276          geometry=OGR_G_CreateGeometryFromJson(tmp->value);
     277        else
     278          geometry=createGeometryFromGML(conf,tmp->value);
     279      }
     280      else
     281        geometry=createGeometryFromGML(conf,tmp->value);
     282    }
     283    if(cursor!=NULL){
     284      map* tmp=getMapFromMaps(cursor,"BufferDistance","value");
     285      if(tmp==NULL){
     286        bufferDistance=10;
     287      }
     288      else
     289        bufferDistance=atoi(tmp->value);
     290#ifdef DEBUG
     291      fprintf(stderr,"\nService internal print (BufferDistance value: %i)\n",bufferDistance);
     292#endif
     293    }
     294#ifdef DEBUG
     295    dumpMaps(outputs);
     296#endif
     297    map* tmp=getMapFromMaps(outputs,"Result","mimeType");
     298    res=OGR_G_Buffer(geometry,bufferDistance,30);
     299#ifdef DEBUG
     300    dumpMap(tmp);
     301#endif
     302    if(tmp!=NULL){
     303#ifdef DEBUG
     304      dumpMap(tmp);
     305#endif
     306      if(strncmp(tmp->value,"application/json",16)==0){
     307        addToMap(outputs->content,"value",OGR_G_ExportToJson(res));
     308        addToMap(outputs->content,"mimeType","text/plain");
     309        addToMap(outputs->content,"encoding","UTF-8");
     310      }
     311      else if(strcmp(tmp->value,"text/xml")==0){
     312        xmlInitParser();
     313        xmlDocPtr doc = xmlParseMemory(tmp->value,strlen(tmp->value));
     314        xmlChar *xmlbuff;
     315        int buffersize;
     316        char *buff=OGR_G_ExportToGML(res);
     317        addToMap(outputs->content,"value",buff);
     318        map* tmp1=getMapFromMaps(outputs,"Result","encoding");
     319        if(tmp1!=NULL)
     320          addToMap(outputs->content,"encoding",tmp1->value);
     321        else
     322          addToMap(outputs->content,"encoding","UTF-8");
     323        xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1);
     324        xmlFree(xmlbuff);
     325        xmlFreeDoc(doc);
     326        xmlCleanupParser();
     327      }
     328      else{
     329        addToMap(outputs->content,"value",OGR_G_ExportToJson(res));
     330        addToMap(outputs->content,"mimeType","text/plain");
     331        addToMap(outputs->content,"encoding","UTF-8");
     332        outputs->next=NULL;
     333      }
     334      outputs->next=NULL;
     335    }
     336    else{
     337      addToMap(outputs->content,"value",OGR_G_ExportToJson(res));
     338      addToMap(outputs->content,"mimeType","text/plain");
     339      addToMap(outputs->content,"encoding","UTF-8");
     340      outputs->next=NULL;
     341    }
     342    outputs->next=NULL;
     343#ifdef DEBUG
     344    dumpMaps(outputs);
     345    fprintf(stderr,"\nService internal print\n===\n");
     346#endif
     347    OGR_G_DestroyGeometry(geometry);
     348    OGR_G_DestroyGeometry(res);
     349    return SERVICE_SUCCEEDED;
     350  }
     351*/
     352
     353#ifdef WIN32
     354  __declspec(dllexport)
     355#endif
     356  int Boundary(maps*& conf,maps*& inputs,maps*& outputs){
     357    return applyOne(conf,inputs,outputs,&OGR_G_GetBoundary);
     358  }
     359
     360#ifdef WIN32
     361  __declspec(dllexport)
     362#endif
     363  int ConvexHull(maps*& conf,maps*& inputs,maps*& outputs){
     364    return applyOne(conf,inputs,outputs,&OGR_G_ConvexHull);
     365  }
     366
     367
     368  OGRGeometryH MY_OGR_G_Centroid(OGRGeometryH hTarget){
     369    OGRGeometryH res;
     370    res=OGR_G_CreateGeometryFromJson("{\"type\": \"Point\", \"coordinates\": [0,0] }");
     371    OGRwkbGeometryType gtype=OGR_G_GetGeometryType(hTarget);
     372    if(gtype!=wkbPolygon){
     373      hTarget=OGR_G_ConvexHull(hTarget);
     374    }
     375    int c=OGR_G_Centroid(hTarget,res);
     376    return res;
     377  }
     378
     379#ifdef WIN32
     380  __declspec(dllexport)
     381#endif
     382  int Centroid(maps*& conf,maps*& inputs,maps*& outputs){
     383    return applyOne(conf,inputs,outputs,&MY_OGR_G_Centroid);
    91384  }
    92385
     
    130423    }
    131424    res=(*myFunc)(geometry1,geometry2);
    132     outputs=(maps*)malloc(sizeof(maps*));
    133     outputs->name="Result";
    134     char tmpres[100];
    135     sprintf(tmpres,"%d",res);
    136     outputs->content=createMap("value",OGR_G_ExportToJson(res));
    137     addMapToMap(&outputs->content,createMap("mimeType","text/plain"));
    138     addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
     425    addToMap(outputs->content,"value",OGR_G_ExportToJson(res));
     426    addToMap(outputs->content,"mimeType","text/plain");
     427    addToMap(outputs->content,"encoding","UTF-8");
    139428    outputs->next=NULL;
     429    OGR_G_DestroyGeometry(geometry1);
     430    OGR_G_DestroyGeometry(geometry2);
     431    OGR_G_DestroyGeometry(res);
    140432    return SERVICE_SUCCEEDED;
    141433  }
    142 
     434 
    143435#ifdef WIN32
    144436  __declspec(dllexport)
     
    162454  }
    163455
    164   int applyOne(maps*& conf,maps*& inputs,maps*& outputs,OGRGeometryH (*myFunc)(OGRGeometryH)){
    165 #ifdef DEBUG
    166     fprintf(stderr,"\nService internal print\n");
    167 #endif
    168     maps* cursor=inputs;
    169     OGRGeometryH geometry,res;
    170     int bufferDistance;
    171 #ifdef DEBUG
    172     dumpMaps(cursor);
    173 #endif
    174     map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
    175     if(!tmp)
    176       return SERVICE_FAILED;
    177     map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeTime");
    178     if(tmp1!=NULL){
    179       if(strncmp(tmp1->value,"text/js",7)==0)
    180         geometry=OGR_G_CreateGeometryFromJson(tmp->value);
    181       else
    182         geometry=createGeometryFromGML(conf,tmp->value);
    183       }
    184     else
    185       geometry=createGeometryFromGML(conf,tmp->value);
    186     res=(*myFunc)(geometry);
    187     /**
    188      * Here we should check what is the requested output.
    189      * Let's use JSON per default.
    190      */
    191     //outputs=(maps*)malloc(sizeof(maps*));
    192     outputs->name="Result";
    193     if(tmp1!=NULL){
    194       if(strncmp(tmp1->value,"text/js",7)==0){
    195         outputs->content=createMap("value",OGR_G_ExportToJson(tmp->value));
    196         addMapToMap(&outputs->content,createMap("mimeType","text/plain"));
    197         addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
    198       }
    199       else{
    200         outputs->content=createMap("value",OGR_G_ExportToGML(res));
    201         addMapToMap(&outputs->content,createMap("mimeType","text/xml"));
    202         addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
    203         addMapToMap(&outputs->content,createMap("schema","http://fooa/gml/3.1.0/polygon.xsd"));
    204       }
    205     }else{
    206       outputs->content=createMap("value",OGR_G_ExportToJson(res));
    207       addMapToMap(&outputs->content,createMap("mimeType","text/plain"));
    208       addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
    209     }
    210     outputs->next=NULL;
    211 #ifdef DEBUG
    212     dumpMaps(outputs);
    213     fprintf(stderr,"\nService internal print\n===\n");
    214 #endif
    215     return SERVICE_SUCCEEDED;
    216   }
    217 
    218 #ifdef WIN32
    219   __declspec(dllexport)
    220 #endif
    221   int ConvexHull(maps*& conf,maps*& inputs,maps*& outputs){
    222     return applyOne(conf,inputs,outputs,&OGR_G_ConvexHull);
    223   }
    224 
    225 #ifdef WIN32
    226   __declspec(dllexport)
    227 #endif
    228   int Boundary(maps*& conf,maps*& inputs,maps*& outputs){
    229 #ifdef DEBUG
    230     fprintf(stderr,"\nService internal print\nStarting\n");
    231 #endif
    232     maps* cursor=inputs;
    233     OGRGeometryH geometry,res;
    234     int bufferDistance;
    235     xmlInitParser();
    236    
    237     if(cursor!=NULL){
    238       map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
    239       map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType");
    240       if(tmp1!=NULL){
    241         if(strncmp(tmp1->value,"text/js",7)==0)
    242           geometry=OGR_G_CreateGeometryFromJson(tmp->value);
    243         else
    244           geometry=createGeometryFromGML(conf,tmp->value);
    245       }
    246       else
    247         geometry=createGeometryFromGML(conf,tmp->value);
    248     }
    249     res=OGR_G_GetBoundary(geometry);
    250     outputs=(maps*)malloc(sizeof(maps*));
    251     outputs->name="Boundary";
    252     outputs->content=createMap("value",OGR_G_ExportToJson(res));
    253     addMapToMap(&outputs->content,createMap("mimeType","text/plain"));
    254     addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
    255     /*
    256     outputs->content=createMap("value",OGR_G_ExportToGML(res));
    257     addMapToMap(&outputs->content,createMap("mimeType","text/xml"));
    258     addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
    259     addMapToMap(&outputs->content,createMap("schema","http://fooa/gml/3.1.0/polygon.xsd"));
    260     */
    261     outputs->next=NULL;
    262 #ifdef DEBUG
    263     fprintf(stderr,"\nService internal print\n===\n");
    264 #endif
    265     xmlCleanupParser();
    266     return SERVICE_SUCCEEDED;
    267     }
    268 
    269 #ifdef WIN32
    270   __declspec(dllexport)
    271 #endif
    272   int Centroid(maps*& conf,maps*& inputs,maps*& outputs){
    273 #ifdef DEBUG
    274     fprintf(stderr,"\nService internal print\n");
    275 #endif
    276     maps* cursor=inputs;
    277     OGRGeometryH geometry,res=NULL;
    278     int bufferDistance;   
    279     if(cursor!=NULL){
    280 #ifdef DEBUG
    281       fprintf(stderr,"\nService internal print\n");
    282       dumpMaps(cursor);
    283       fprintf(stderr,"\nService internal print\n");
    284       dumpMaps(inputs);
    285       fprintf(stderr,"\nService internal print\n");
    286 #endif
    287       map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
    288       map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType");
    289       if(tmp1!=NULL){
    290         if(strncmp(tmp1->value,"application/json",16)==0)
    291           geometry=OGR_G_CreateGeometryFromJson(tmp->value);
    292         else
    293           geometry=createGeometryFromGML(conf,tmp->value);
    294       }
    295       else
    296         geometry=createGeometryFromGML(conf,tmp->value);
    297     }else{
    298     /**
    299      * Print WPSExceptionError message here !!
    300      */
    301     }
    302 #ifdef DEBUG
    303     dumpMaps(outputs);
    304 #endif
    305     res=OGR_G_CreateGeometryFromJson("{\"type\": \"Point\", \"coordinates\": [0,0] }");
    306     OGRwkbGeometryType gtype=OGR_G_GetGeometryType(geometry);
    307     if(gtype!=wkbPolygon){
    308         fprintf(stderr,"\n\nGeometry Type is not Polygon, let us use the ConvexHull !\n\n");
    309         geometry=OGR_G_ConvexHull(OGR_G_Clone(geometry));
    310     }else{
    311         fprintf(stderr,"\n\nGeometry Type is Polygon, thanks !\n\n");
    312     }
    313     int c=OGR_G_Centroid(geometry,res);
    314 #ifdef DEBUG
    315     fprintf(stderr,"\n\nC VALUE : %d\n\n",c);
    316 #endif
    317     map* tmp=getMapFromMaps(outputs,"Result","mimeType");
    318 #ifdef DEBUG
    319     dumpMaps(outputs);
    320 #endif
    321     if(tmp!=NULL){
    322 #ifdef DEBUG
    323       dumpMap(tmp);
    324 #endif
    325       if(strncmp(mtoupper(tmp->value),mtoupper("application/json"),16)==0){
    326         outputs->content=createMap("value",OGR_G_ExportToJson(res));
    327         addMapToMap(&outputs->content,createMap("mimeType","text/plain"));
    328         addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
    329       }
    330       else if(strncmp(mtoupper(tmp->value),mtoupper("text/xml"),8)==0){
    331         /*xmlInitParser();
    332         xmlDocPtr doc = xmlParseMemory(tmp->value,strlen(tmp->value));
    333         xmlChar *xmlbuff;
    334         int buffersize;*/
    335         outputs->content=createMap("value",OGR_G_ExportToGML(res));
    336         addMapToMap(&outputs->content,createMap("mimeType","text/xml"));
    337         map* tmp1=getMapFromMaps(outputs,"Result","encoding");
    338         if(tmp1!=NULL)
    339           addMapToMap(&outputs->content,createMap("encoding",tmp1->value));
    340         else
    341           addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
    342         /*xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1);
    343         outputs->content=createMap("value",OGR_G_ExportToGML(res));
    344         xmlFree(xmlbuff);
    345         xmlFreeDoc(doc);
    346         xmlCleanupParser();
    347         */
    348       }
    349     else{
    350       outputs=(maps*)malloc(sizeof(maps*));
    351       outputs->name="Result";
    352       outputs->content=createMap("value",OGR_G_ExportToJson(res));
    353       addMapToMap(&outputs->content,createMap("mimeType","text/plain"));
    354       addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
    355       outputs->next=NULL;
    356     }
    357     outputs->next=NULL;
    358     }
    359     else{
    360       outputs=(maps*)malloc(sizeof(maps*));
    361       outputs->name="Result";
    362       outputs->content=createMap("value",OGR_G_ExportToJson(res));
    363       addMapToMap(&outputs->content,createMap("mimeType","text/plain"));
    364       addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
    365       outputs->next=NULL;
    366     }
    367     outputs->next=NULL;
    368 #ifdef DEBUG
    369     dumpMaps(outputs);
    370     fprintf(stderr,"\nService internal print\n===\n");
    371 #endif
    372     return SERVICE_SUCCEEDED;
    373   }
    374 
    375 #ifdef WIN32
    376   __declspec(dllexport)
    377 #endif
    378   int Buffer(maps*& conf,maps*& inputs,maps*& outputs){
    379 #ifdef DEBUG
    380     fprintf(stderr,"\nService internal print\n");
    381 #endif
    382     maps* cursor=inputs;
    383     OGRGeometryH geometry,res;
    384     int bufferDistance;   
    385     if(cursor!=NULL){
    386 #ifdef DEBUG
    387       fprintf(stderr,"\nService internal print\n");
    388       dumpMaps(cursor);
    389       fprintf(stderr,"\nService internal print\n");
    390       dumpMaps(inputs);
    391       fprintf(stderr,"\nService internal print\n");
    392 #endif
    393       map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
    394       map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType");
    395       if(tmp1!=NULL){
    396         if(strncmp(tmp1->value,"application/json",16)==0)
    397           geometry=OGR_G_CreateGeometryFromJson(tmp->value);
    398         else
    399           geometry=createGeometryFromGML(conf,tmp->value);
    400       }
    401       else
    402         geometry=createGeometryFromGML(conf,tmp->value);
    403     }
    404     if(cursor!=NULL){
    405       map* tmp=getMapFromMaps(cursor,"BufferDistance","value");
    406       if(tmp==NULL){
    407         bufferDistance=10;
    408       }
    409       else
    410         bufferDistance=atoi(tmp->value);
    411 #ifdef DEBUG
    412       fprintf(stderr,"\nService internal print (BufferDistance value: %i)\n",bufferDistance);
    413 #endif
    414     }
    415 #ifdef DEBUG
    416     dumpMaps(outputs);
    417 #endif
    418     map* tmp=getMapFromMaps(outputs,"BufferedPolygon","mimeType");
    419     res=OGR_G_Buffer(geometry,bufferDistance,30);
    420 #ifdef DEBUG
    421     dumpMap(tmp);
    422 #endif
    423     if(tmp!=NULL){
    424 #ifdef DEBUG
    425       dumpMap(tmp);
    426 #endif
    427       if(strncmp(mtoupper(tmp->value),mtoupper("application/json"),16)==0){
    428         outputs->content=createMap("value",OGR_G_ExportToJson(res));
    429         addMapToMap(&outputs->content,createMap("mimeType","text/plain"));
    430         addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
    431       }
    432       else if(strcmp(mtoupper(tmp->value),mtoupper("text/xml"))==0){
    433         xmlInitParser();
    434         xmlDocPtr doc = xmlParseMemory(tmp->value,strlen(tmp->value));
    435         xmlChar *xmlbuff;
    436         int buffersize;
    437         outputs->content=createMap("value",OGR_G_ExportToGML(res));
    438         addMapToMap(&outputs->content,createMap("mimeType","text/xml"));
    439         map* tmp1=getMapFromMaps(outputs,"BufferedPolygon","encoding");
    440         if(tmp1!=NULL)
    441           addMapToMap(&outputs->content,createMap("encoding",tmp1->value));
    442         else
    443           addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
    444         xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1);
    445         outputs->content=createMap("value",OGR_G_ExportToGML(res));
    446         xmlFree(xmlbuff);
    447         xmlFreeDoc(doc);
    448         xmlCleanupParser();
    449       }
    450     else{
    451       outputs=(maps*)malloc(sizeof(maps*));
    452       outputs->name="BufferedPolygon";
    453       outputs->content=createMap("value",OGR_G_ExportToJson(res));
    454       addMapToMap(&outputs->content,createMap("mimeType","text/plain"));
    455       addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
    456       outputs->next=NULL;
    457     }
    458     outputs->next=NULL;
    459     }
    460     else{
    461       outputs=(maps*)malloc(sizeof(maps*));
    462       outputs->name="BufferedPolygon";
    463       outputs->content=createMap("value",OGR_G_ExportToJson(res));
    464       addMapToMap(&outputs->content,createMap("mimeType","text/plain"));
    465       addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
    466       outputs->next=NULL;
    467     }
    468     outputs->next=NULL;
    469 #ifdef DEBUG
    470     dumpMaps(outputs);
    471     fprintf(stderr,"\nService internal print\n===\n");
    472 #endif
    473     return SERVICE_SUCCEEDED;
    474   }
    475 
    476456#ifdef WIN32
    477457  __declspec(dllexport)
    478458#endif
    479459  int Union(maps*& conf,maps*& inputs,maps*& outputs){
    480 #ifdef DEBUG
    481     fprintf(stderr,"\nService internal print1\n");
    482     fflush(stderr);
    483 #endif
    484     maps* cursor=inputs;
    485     OGRGeometryH geometry1,geometry2;
    486     OGRGeometryH res;
    487     {
    488       map* tmp=getMapFromMaps(inputs,"InputEntity1","value");
    489       map* tmp1=getMapFromMaps(inputs,"InputEntity1","mimeType");
    490       if(tmp1!=NULL){
    491         if(strncmp(tmp1->value,"application/json",16)==0)
    492           geometry1=OGR_G_CreateGeometryFromJson(tmp->value);
    493         else
    494           geometry1=createGeometryFromGML(conf,tmp->value);
    495       }
    496       else
    497         geometry1=createGeometryFromGML(conf,tmp->value);
    498     }
    499     {
    500       map* tmp=getMapFromMaps(inputs,"InputEntity2","value");
    501       map* tmp1=getMapFromMaps(inputs,"InputEntity2","mimeType");
    502 #ifdef DEBUG
    503       fprintf(stderr,"MY MAP\n");
    504       dumpMap(tmp1);
    505       fprintf(stderr,"MY MAP\n");
    506 #endif
    507       if(tmp1!=NULL){
    508         if(strncmp(tmp1->value,"application/json",16)==0)
    509           geometry2=OGR_G_CreateGeometryFromJson(tmp->value);
    510         else
    511           geometry2=createGeometryFromGML(conf,tmp->value);
    512       }
    513       else
    514         geometry2=createGeometryFromGML(conf,tmp->value);
    515     }
    516     res=OGR_G_Union(geometry1,geometry2);
    517     outputs=(maps*)malloc(sizeof(maps*));
    518     outputs->name="Result";
    519     char tmpres[100];
    520     sprintf(tmpres,"%d",res);
    521     outputs->content=createMap("value",OGR_G_ExportToJson(res));
    522     addMapToMap(&outputs->content,createMap("mimeType","text/plain"));
    523     addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
    524     outputs->next=NULL;
    525     return SERVICE_SUCCEEDED;
     460    return applyTwo(conf,inputs,outputs,&OGR_G_Union);
    526461  }
    527462
     
    589524  }
    590525
     526#ifdef WIN32
     527  __declspec(dllexport)
     528#endif
    591529  int GetArea(maps*& conf,maps*& inputs,maps*& outputs){
    592530    fprintf(stderr,"GETAREA \n");
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