Changeset 360


Ignore:
Timestamp:
Jun 7, 2012, 10:54:31 PM (12 years ago)
Author:
djay
Message:

Add support for multiple inputs values for the same identifier.

Location:
trunk/zoo-project
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/zoo-project/HISTORY.txt

    r342 r360  
    88  * Add the Normalized Difference Vegetation Index service
    99  * Add importScripts function to JavaScript support (ticket #66)
     10  * Add multiple inputs values for the same identifier (ticket #72)
    1011
    1112Version 1.2.0-rc3
  • trunk/zoo-project/zoo-kernel/service.h

    r348 r360  
    22 * Author : Gérald FENOY
    33 *
    4  * Copyright (c) 2009-2010 GeoLabs SARL
     4 * Copyright (c) 2009-2012 GeoLabs SARL
    55 *
    66 * Permission is hereby granted, free of charge, to any person obtaining a copy
     
    596596  }
    597597
     598  static map* getMapArray(map* m,char* key,int index){
     599    char tmp[1024];
     600    if(index>0)
     601      sprintf(tmp,"%s_%d",key,index);
     602    else
     603      sprintf(tmp,key);
     604#ifdef DEBUG
     605    fprintf(stderr,"** KEY %s\n",tmp);
     606#endif
     607    map* tmpMap=getMap(m,tmp);
     608#ifdef DEBUG
     609    if(tmpMap!=NULL)
     610      dumpMap(tmpMap);
     611#endif
     612    return tmpMap;
     613  }
     614
     615
     616  static void setMapArray(map* m,char* key,int index,char* value){
     617    char tmp[1024];
     618    if(index>0)
     619      sprintf(tmp,"%s_%d",key,index);
     620    else
     621      sprintf(tmp,key);
     622    map* tmpSize=getMapArray(m,"size",index);
     623    if(tmpSize!=NULL && strncasecmp(key,"value",5)==0){
     624      fprintf(stderr,"%s\n",tmpSize->value);
     625      map* ptr=getMapOrFill(m,tmp,"");
     626      free(ptr->value);
     627      ptr->value=(char*)malloc((atoi(tmpSize->value)+1)*sizeof(char));
     628      memcpy(ptr->value,value,atoi(tmpSize->value));
     629    }
     630    else
     631      addToMap(m,tmp,value);
     632  }
     633
     634  static map* getMapType(map* mt){
     635    map* tmap=getMap(mt,"mimeType");
     636    if(tmap==NULL){
     637      tmap=getMap(mt,"dataType");
     638      if(tmap==NULL){
     639        tmap=getMap(mt,"CRS");
     640      }
     641    }
     642    dumpMap(tmap);
     643    return tmap;
     644  }
     645
     646  static int addMapsArrayToMaps(maps** mo,maps* mi,char* typ){
     647    maps* tmp=mi;
     648    maps* _cursor=*mo;
     649    maps* tmpMaps=getMaps(_cursor,tmp->name);
     650
     651    if(tmpMaps==NULL)
     652      return -1;
     653
     654    map* tmpLength=getMap(tmpMaps->content,"length");
     655    char tmpLen[10];
     656    int len=1;
     657    if(tmpLength!=NULL){
     658      len=atoi(tmpLength->value);
     659    }
     660
     661    map* tmpValI=getMap(tmp->content,"value");
     662    char *tmpV[8]={
     663      "size",
     664      "value",
     665      "uom",
     666      "Reference",
     667      "xlink:href",
     668      typ,
     669      "schema",
     670      "encoding"
     671    };
     672    sprintf(tmpLen,"%d",len+1);
     673    addToMap(_cursor->content,"length",tmpLen);
     674    int i=0;
     675    map* tmpSizeI=getMap(tmp->content,tmpV[i]);
     676    for(0;i<8;i++){
     677      map* tmpVI=getMap(tmp->content,tmpV[i]);
     678      if(tmpVI!=NULL){
     679        fprintf(stderr,"%s = %s\n",tmpV[i],tmpVI->value);
     680        if(i<5)
     681          setMapArray(_cursor->content,tmpV[i],len,tmpVI->value);
     682        else
     683          if(strncasecmp(tmpV[5],"mimeType",8)==0)
     684            setMapArray(_cursor->content,tmpV[i],len,tmpVI->value);
     685      }
     686    }
     687   
     688    addToMap(_cursor->content,"isArray","true");
     689    return 0;
     690  }
    598691
    599692  static void setMapInMaps(maps* m,const char* key,const char* subkey,const char *value){
  • trunk/zoo-project/zoo-kernel/service_internal.c

    r351 r360  
    22 * Author : Gérald FENOY
    33 *
    4  * Copyright (c) 2009-2011 GeoLabs SARL
     4 * Copyright (c) 2009-2012 GeoLabs SARL
    55 *
    66 * Permission is hereby granted, free of charge, to any person obtaining a copy
     
    21882188        map* tmpContent=tmpIoType->content;
    21892189        map* cval=NULL;
    2190 
     2190        int hasPassed=-1;
    21912191        while(tmpContent!=NULL){
    21922192          if((cval=getMap(tmpMaps->content,tmpContent->name))==NULL){
     
    21982198            else
    21992199              addToMap(tmpMaps->content,tmpContent->name,tmpContent->value);
     2200           
     2201            if(hasPassed<0 && type==0 && getMap(tmpMaps->content,"isArray")!=NULL){
     2202              map* length=getMap(tmpMaps->content,"length");
     2203              int i;
     2204              char *tcn=strdup(tmpContent->name);
     2205              for(i=1;i<atoi(length->value);i++){
     2206                dumpMap(tmpMaps->content);
     2207                fprintf(stderr,"addDefaultValues %s_%d => %s\n",tcn,i,tmpContent->value);
     2208                int len=strlen(tcn);
     2209                char *tmp1=malloc((len+10)*sizeof(char));
     2210                sprintf(tmp1,"%s_%d",tcn,i);
     2211                fprintf(stderr,"addDefaultValues %s => %s\n",tmp1,tmpContent->value);
     2212                addToMap(tmpMaps->content,tmp1,tmpContent->value);
     2213                free(tmp1);
     2214                hasPassed=1;
     2215              }
     2216              free(tcn);
     2217            }
    22002218          }
    22012219          tmpContent=tmpContent->next;
     
    24842502    return errorException(m, _("Unable to download the file."), "InternalError");
    24852503  }
     2504
    24862505  map* tmpMap=getMapOrFill(content,"value","");
     2506   
    24872507  free(tmpMap->value);
    24882508  tmpMap->value=(char*)malloc((fsize+1)*sizeof(char));
    2489   memcpy(tmpMap->value,fcontent,(fsize)*sizeof(char));
     2509  memcpy(tmpMap->value,fcontent,(fsize)*sizeof(char));
     2510
    24902511  char ltmp1[256];
    24912512  sprintf(ltmp1,"%d",fsize);
  • trunk/zoo-project/zoo-kernel/service_internal_java.c

    r355 r360  
    22 * Author : Gérald FENOY
    33 *
    4  * Copyright (c) 2009-2011 GeoLabs SARL
     4 * Copyright (c) 2009-2012 GeoLabs SARL
    55 *
    66 * Permission is hereby granted, free of charge, to any person obtaining a copy
     
    201201    maps* tmp=t;
    202202    while(tmp!=NULL){
     203      map* tmap=getMapType(tmp->content);
    203204      map* tmp1=tmp->content;
    204205      scObject1 = (*env)->NewObject(env, scHashMap_class, scHashMap_constructor);
    205206      map* sizeV=getMap(tmp1,"size");
     207      map* isArray=getMap(tmp1,"isArray");
     208      map* alen=getMap(tmp1,"length");
    206209      while(tmp1!=NULL){
    207         if(sizeV!=NULL && strcmp(tmp1->name,"value")==0){
    208           jbyteArray tmpData=(*env)->NewByteArray(env,atoi(sizeV->value));
    209           (*env)->SetByteArrayRegion(env,tmpData,0,atoi(sizeV->value),tmp1->value);
    210           (*env)->CallObjectMethod(env,scObject1, put_mid, (*env)->NewStringUTF(env,tmp1->name), tmpData);
    211         }else
     210        if(strcmp(tmp1->name,"value")==0){
     211          if(isArray==NULL){
     212            if(sizeV!=NULL && strcmp(tmp1->name,"value")==0){
     213              jbyteArray tmpData=(*env)->NewByteArray(env,atoi(sizeV->value));
     214              (*env)->SetByteArrayRegion(env,tmpData,0,atoi(sizeV->value),tmp1->value);
     215              (*env)->CallObjectMethod(env,scObject1, put_mid, (*env)->NewStringUTF(env,tmp1->name), tmpData);
     216            }else
     217              (*env)->CallObjectMethod(env,scObject1, put_mid, (*env)->NewStringUTF(env,tmp1->name), (*env)->NewStringUTF(env,tmp1->value));
     218          }
     219          else{
     220            int alen1=atoi(alen->value);
     221            fprintf(stderr,"LENGTH %d \n",alen1);
     222           
     223            jclass scArrayListClass,scArrayList_class;
     224            jmethodID scArrayList_constructor;
     225            jobject scObject2,scObject3,scObject4;
     226            scArrayListClass = (*env)->FindClass(env, "java/util/ArrayList");
     227            scArrayList_class = (*env)->NewGlobalRef(env, scArrayListClass);
     228            scArrayList_constructor = (*env)->GetMethodID(env, scArrayList_class, "<init>", "()V");
     229            jmethodID add_mid = 0;
     230            scObject2 = (*env)->NewObject(env, scArrayList_class, scArrayList_constructor);
     231            scObject3 = (*env)->NewObject(env, scArrayList_class, scArrayList_constructor);
     232            scObject4 = (*env)->NewObject(env, scArrayList_class, scArrayList_constructor);
     233
     234            add_mid = (*env)->GetMethodID(env,scArrayListClass,
     235                                          "add","(Ljava/lang/Object;)Z");
     236           
     237            int i;
     238           
     239            for(i=0;i<alen1;i++){
     240              map* vMap=getMapArray(tmp->content,"value",i);       
     241              map* sMap=getMapArray(tmp->content,"size",i);
     242              map* mMap=getMapArray(tmp->content,tmap->value,i);
     243             
     244              if(sMap!=NULL && vMap!=NULL && strncmp(vMap->name,"value",5)==0){
     245                jbyteArray tmpData=(*env)->NewByteArray(env,atoi(sMap->value));
     246                (*env)->SetByteArrayRegion(env,tmpData,0,atoi(sMap->value),vMap->value);
     247                (*env)->CallObjectMethod(env,scObject2, add_mid, tmpData);
     248              }else{
     249                jobject tmpData=(*env)->NewStringUTF(env,vMap->value);
     250                (*env)->CallObjectMethod(env,scObject2, add_mid, tmpData);
     251              }
     252             
     253            }
     254           
     255            (*env)->CallObjectMethod(env,scObject1, put_mid, (*env)->NewStringUTF(env,tmp1->name), scObject2);
     256           
     257          }
     258        }
     259        else
    212260          (*env)->CallObjectMethod(env,scObject1, put_mid, (*env)->NewStringUTF(env,tmp1->name), (*env)->NewStringUTF(env,tmp1->value));
    213261        tmp1=tmp1->next;
  • trunk/zoo-project/zoo-kernel/service_internal_js.c

    r348 r360  
    22 * Author : Gérald FENOY
    33 *
    4  * Copyright (c) 2009-2010 GeoLabs SARL
     4 * Copyright (c) 2009-2012 GeoLabs SARL
    55 *
    66 * Permission is hereby granted, free of charge, to any person obtaining a copy
     
    352352  jsval resf =  OBJECT_TO_JSVAL(res);
    353353  map* tmpm=t;
     354  map* isArray=getMap(t,"isArray");
     355  map* isBinary=getMap(t,"size");
     356  map* tmap=getMapType(t);
     357  if(tmap==NULL)
     358    fprintf(stderr,"tmap is null !\n");
     359  else
     360    fprintf(stderr,"tmap is not null ! (%s = %s)\n",tmap->name,tmap->value);
     361
     362  /* Avoid gesture of binary content which failed due to strlen function use */
     363  if(isBinary!=NULL){
     364    return res;
     365  }
    354366  while(tmpm!=NULL){
    355     jsval jsstr = STRING_TO_JSVAL(JS_NewStringCopyN(cx,tmpm->value,strlen(tmpm->value)));
    356     JS_SetProperty(cx, res, tmpm->name,&jsstr);
    357 #ifdef JS_DEBUG
    358     fprintf(stderr,"%s => %s\n",tmpm->name,tmpm->value);
    359 #endif
     367    if(isArray==NULL || strncasecmp(tmpm->name,"value",5)!=0 ||
     368       (tmap!=NULL && strncasecmp(tmpm->name,tmap->name,strlen(tmap->name))!=0)){
     369      jsval jsstr = STRING_TO_JSVAL(JS_NewStringCopyN(cx,tmpm->value,strlen(tmpm->value)));
     370      JS_SetProperty(cx, res, tmpm->name,&jsstr);
     371#ifdef JS_DEBUG
     372      fprintf(stderr,"%s => %s\n",tmpm->name,tmpm->value);
     373#endif
     374    }
    360375    tmpm=tmpm->next;
     376  }
     377  if(isArray!=NULL){
     378    map* len=getMap(t,"length");
     379    int cnt=atoi(len->value);
     380    JSObject* values=JS_NewArrayObject( cx, cnt, NULL );
     381    JSObject* mvalues=JS_NewArrayObject( cx, cnt, NULL );
     382    map *tmpm1,*tmpm2;
     383    int i=0;
     384    for(i=0;i<cnt;i++){
     385      tmpm1=getMapArray(t,"value",i);
     386      tmpm2=getMapArray(t,tmap->name,i);
     387      if(tmpm1!=NULL){
     388        jsval jsstr = STRING_TO_JSVAL(JS_NewStringCopyN(cx,tmpm1->value,strlen(tmpm1->value)));
     389        JS_SetElement( cx, values, i, &jsstr );
     390      }
     391      if(tmpm2!=NULL){
     392        jsval jsstr = STRING_TO_JSVAL(JS_NewStringCopyN(cx,tmpm2->value,strlen(tmpm2->value)));
     393        JS_SetElement( cx, mvalues, i, &jsstr );
     394      }
     395    }
     396    jsval jvalues=OBJECT_TO_JSVAL(values);
     397    jsval jmvalues=OBJECT_TO_JSVAL(mvalues);
     398    JS_SetProperty(cx, res,"value",&jvalues);
     399    JS_SetProperty(cx, res,tmap->name,&jmvalues);
    361400  }
    362401  return res;
  • trunk/zoo-project/zoo-kernel/service_internal_ms.c

    r357 r360  
    126126
    127127  if(proto>0){
    128     map* test=getMap(tmpI->content,"real_extent");
    129     if(test!=NULL)
    130         extent=test;
    131128    sprintf(webService_url,
    132129            "%s?map=%s/%s_%s.map&request=%s&service=%s&version=%s&%s&format=%s&bbox=%s&crs=%s",
     
    145142  }
    146143  else{
    147     map* test=getMap(tmpI->content,"real_extent_reverse");
    148     if(test!=NULL)
    149         extent=test;
    150144    sprintf(webService_url,
    151145            "%s?map=%s/%s_%s.map&request=%s&service=%s&version=%s&%s&width=%s&height=%s&format=%s&bbox=%s&crs=%s",
     
    281275 
    282276  if(output!=NULL){
     277
    283278    map* test=getMap(output->content,"real_extent");
    284279    if(test!=NULL){
    285280      pointObj min, max;
    286281      projectionObj tempSrs;
    287      
     282
    288283      min.x = m->extent.minx;
    289284      min.y = m->extent.miny;
     
    291286      max.y = m->extent.maxy;
    292287      char tmpSrsStr[1024];
    293      
     288
     289
    294290      msInitProjection(&tempSrs);
    295291      msLoadProjectionStringEPSG(&tempSrs,"EPSG:4326");
    296      
     292
    297293      msProjectPoint(&(m->projection),&tempSrs,&min);
    298294      msProjectPoint(&m->projection,&tempSrs,&max);
    299295     
    300296      sprintf(tmpExtent,"%.3f,%.3f,%.3f,%.3f",min.y,min.x,max.y,max.x);
     297      map* isGeo=getMap(output->content,"crs_isGeographic");
     298      fprintf(stderr,"isGeo = %s\n",isGeo->value);
     299      if(isGeo!=NULL && strcasecmp("true",isGeo->value)==0)
     300        sprintf(tmpExtent,"%f,%f,%f,%f", minY,minX, maxY, maxX);
    301301      addToMap(output->content,"wms_extent",tmpExtent);
    302       sprintf(tmpExtent,"%.3f,%.3f,%.3f,%.3f",min.x,min.y,max.x,max.y);
     302      sprintf(tmpSrsStr,"%.3f,%.3f,%.3f,%.3f",min.x,min.y,max.x,max.y);
    303303      addToMap(output->content,"wcs_extent",tmpExtent);
    304      
     304      dumpMap(output->content);
     305
    305306    }else{
    306307      sprintf(tmpExtent,"%f,%f,%f,%f",minX, minY, maxX, maxY);
     
    308309      fprintf(stderr,"isGeo = %s\n",isGeo->value);
    309310      if(isGeo!=NULL && strcasecmp("true",isGeo->value)==0)
    310         sprintf(tmpExtent,"%f,%f,%f,%f", minY,minX, maxY, maxX);
     311        sprintf(tmpExtent,"%f,%f,%f,%f", minY,minX, maxY, maxX);
    311312      addToMap(output->content,"wms_extent",tmpExtent);
    312313      sprintf(tmpExtent,"%.3f,%.3f,%.3f,%.3f",minX,minY,maxX,maxY);
    313       addToMap(output->content,"wcs_extent",tmpExtent);
    314     }
     314      addToMap(output->content,"wcs_extent",tmpExtent);
     315     
     316    }
     317
    315318  }
    316319
     
    858861   * Firs store the value on disk
    859862   */
     863  map* mime=getMap(outputs->content,"mimeType");
     864  char *ext="data";
     865  if(mime!=NULL)
     866    if(strncasecmp(mime->value,"application/json",16)==0)
     867      ext="json";
     868 
    860869  map* tmpMap=getMapFromMaps(conf,"main","dataPath");
    861870  map* sidMap=getMapFromMaps(conf,"lenv","sid");
    862871  char *pszDataSource=(char*)malloc((strlen(tmpMap->value)+strlen(sidMap->value)+strlen(outputs->name)+17)*sizeof(char));
    863   sprintf(pszDataSource,"%s/ZOO_DATA_%s_%s.data",tmpMap->value,outputs->name,sidMap->value);
     872  sprintf(pszDataSource,"%s/ZOO_DATA_%s_%s.%s",tmpMap->value,outputs->name,sidMap->value,ext);
    864873  int f=open(pszDataSource,O_WRONLY|O_CREAT,S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
    865874  map* sizeMap=getMap(outputs->content,"size");
  • trunk/zoo-project/zoo-kernel/service_internal_python.c

    r348 r360  
    22 * Author : Gérald FENOY
    33 *
    4  * Copyright (c) 2009-2011 GeoLabs SARL
     4 * Copyright (c) 2009-2012 GeoLabs SARL
    55 *
    66 * Permission is hereby granted, free of charge, to any person obtaining a copy
     
    208208  PyObject* res=PyDict_New( );
    209209  map* tmp=t;
     210  int hasSize=0;
     211  map* isArray=getMap(tmp,"isArray");
    210212  map* size=getMap(tmp,"size");
     213  map* tmap=getMapType(tmp);
    211214  while(tmp!=NULL){
    212215    PyObject* name=PyString_FromString(tmp->name);
    213     if(strcasecmp(tmp->name,"value")==0){
    214       if(size!=NULL){
     216    if(strcasecmp(tmp->name,"value")==0) {
     217      if(isArray!=NULL){
     218        map* len=getMap(tmp,"length");
     219        int cnt=atoi(len->value);
     220        PyObject* value=PyList_New(cnt);
     221        PyObject* mvalue=PyList_New(cnt);
     222        PyObject* svalue=PyList_New(cnt);
     223
     224        for(int i=0;i<cnt;i++){
     225         
     226          map* vMap=getMapArray(tmp,"value",i);     
     227          map* sMap=getMapArray(tmp,"size",i);
     228
     229          if(vMap!=NULL){
     230           
     231            PyObject* lvalue;
     232            PyObject* lsvalue;
     233            if(sMap==NULL){
     234              lvalue=PyString_FromString(vMap->value);
     235              lsvalue=Py_None;
     236            }
     237            else{
     238              lvalue=PyString_FromStringAndSize(vMap->value,atoi(sMap->value));
     239              lsvalue=PyString_FromString(sMap->value);
     240              hasSize=1;
     241            }
     242
     243            if(PyList_SetItem(value,i,lvalue)<0){
     244              fprintf(stderr,"Unable to set key value pair...");
     245              return NULL;
     246            }
     247            if(PyList_SetItem(svalue,i,lsvalue)<0){
     248              fprintf(stderr,"Unable to set key value pair...");
     249              return NULL;
     250            }
     251          }
     252         
     253          map* mMap=getMapArray(tmp,tmap->name,i);
     254          PyObject* lmvalue;
     255          if(mMap!=NULL){
     256            lmvalue=PyString_FromString(mMap->value);
     257          }else
     258            lmvalue=Py_None;
     259         
     260          if(PyList_SetItem(mvalue,i,lmvalue)<0){
     261              fprintf(stderr,"Unable to set key value pair...");
     262              return NULL;
     263          }
     264         
     265        }
     266
     267        if(PyDict_SetItem(res,name,value)<0){
     268          fprintf(stderr,"Unable to set key value pair...");
     269          return NULL;
     270        }
     271        if(PyDict_SetItem(res,PyString_FromString(tmap->name),mvalue)<0){
     272          fprintf(stderr,"Unable to set key value pair...");
     273          return NULL;
     274        }
     275        if(hasSize>0)
     276          if(PyDict_SetItem(res,PyString_FromString("size"),svalue)<0){
     277            fprintf(stderr,"Unable to set key value pair...");
     278            return NULL;
     279          }
     280      }
     281      else if(size!=NULL){
    215282        PyObject* value=PyString_FromStringAndSize(tmp->value,atoi(size->value));
    216283        if(PyDict_SetItem(res,name,value)<0){
     
    228295    }
    229296    else{
    230       PyObject* value=PyString_FromString(tmp->value);
    231       if(PyDict_SetItem(res,name,value)<0){
    232         fprintf(stderr,"Unable to set key value pair...");
    233         return NULL;
     297      if(PyDict_GetItem(res,name)==NULL){
     298        PyObject* value=PyString_FromString(tmp->value);
     299        if(PyDict_SetItem(res,name,value)<0){
     300          fprintf(stderr,"Unable to set key value pair...");
     301          return NULL;
     302        }
    234303      }
    235304    }
  • trunk/zoo-project/zoo-kernel/zoo_service_loader.c

    r348 r360  
    22 * Author : Gérald FENOY
    33 *
    4  *  Copyright 2008-2011 GeoLabs SARL. All rights reserved.
     4 *  Copyright 2008-2012 GeoLabs SARL. All rights reserved.
    55 *
    66 * Permission is hereby granted, free of charge, to any person obtaining a copy
     
    9292      str[i]=toReplaceBy;
    9393  }
     94}
     95
     96/**
     97 * Create (or append to) an array valued maps
     98 * value = "["",""]"
     99 */
     100int appendMapsToMaps(maps* m,maps* mo,maps* mi,elements* elem){
     101
     102  map* tmap=getMapType(mo->content);
     103  if(tmap==NULL){
     104    tmap=getMapType(elem->defaults->content);
     105  }
     106
     107  map* testMap=getMap(elem->content,"maxOccurs");
     108  if(testMap!=NULL){
     109    if(strncasecmp(testMap->value,"unbounded",9)!=0 && atoi(testMap->value)>1){
     110      if(addMapsArrayToMaps(&mo,mi,tmap->name)<0){
     111        char emsg[1024];
     112        sprintf(emsg,_("You set maximum occurences for <%s> as %i but you tried to use it more than the limit you set. Please correct your ZCFG file or your request."),mi->name,atoi(testMap->value));
     113        errorException(m,emsg,"InternalError");
     114        return -1;
     115      }
     116    }else{
     117      if(strncasecmp(testMap->value,"unbounded",9)==0){
     118        if(addMapsArrayToMaps(&mo,mi,tmap->name)<0){
     119          char emsg[1024];
     120          map* tmpMap=getMap(mi->content,"length");
     121          sprintf(emsg,_("ZOO-Kernel was unable to load your data for %s position %s."),mi->name,tmpMap->value);
     122          errorException(m,emsg,"InternalError");
     123          return -1;
     124        }
     125      }
     126      else{
     127        char emsg[1024];
     128        sprintf(emsg,_("You set maximum occurences for <%s> to one but you tried to use it more than once. Please correct your ZCFG file or your request."),mi->name);
     129        errorException(m,emsg,"InternalError");
     130        return -1;
     131      }
     132    }
     133  }
     134  return 0;
    94135}
    95136
     
    10681109        if(request_input_real_format==NULL)
    10691110          request_input_real_format=dupMaps(&tmpmaps);
    1070         else
    1071           addMapsToMaps(&request_input_real_format,tmpmaps);
     1111        else{
     1112          maps* testPresence=getMaps(request_input_real_format,tmpmaps->name);
     1113          if(testPresence!=NULL){
     1114            elements* elem=getElements(s1->inputs,tmpmaps->name);
     1115            if(elem!=NULL){
     1116              if(appendMapsToMaps(m,request_input_real_format,tmpmaps,elem)<0){
     1117                freeMaps(&m);
     1118                free(m);
     1119                free(REQUEST);
     1120                free(SERVICE_URL);
     1121                InternetCloseHandle(hInternet);
     1122                freeService(&s1);
     1123                free(s1);
     1124                return 0;
     1125              }
     1126            }
     1127          }
     1128          else
     1129            addMapsToMaps(&request_input_real_format,tmpmaps);
     1130        }
    10721131        freeMaps(&tmpmaps);
    10731132        free(tmpmaps);
     
    14791538        fflush(stderr);
    14801539#endif
    1481         addMapsToMaps(&request_input_real_format,tmpmaps);
     1540
     1541        {
     1542          maps* testPresence=getMaps(request_input_real_format,tmpmaps->name);
     1543          if(testPresence!=NULL){
     1544            elements* elem=getElements(s1->inputs,tmpmaps->name);
     1545            if(elem!=NULL){
     1546              if(appendMapsToMaps(m,request_input_real_format,tmpmaps,elem)<0){
     1547                freeMaps(&m);
     1548                free(m);
     1549                free(REQUEST);
     1550                free(SERVICE_URL);
     1551                InternetCloseHandle(hInternet);
     1552                freeService(&s1);
     1553                free(s1);
     1554                return 0;
     1555              }
     1556            }
     1557          }
     1558          else
     1559            addMapsToMaps(&request_input_real_format,tmpmaps);
     1560        }
    14821561       
    14831562#ifdef DEBUG
  • trunk/zoo-project/zoo-services/ogr/base-vect-ops-py/cgi-env/ogr_sp.py

    r348 r360  
    66import sys
    77
     8def readFileFromBuffer(data,ext):
     9    geometry=[]
     10    osgeo.gdal.FileFromMemBuffer('/vsimem//temp1'+ext,data)
     11    ds = osgeo.ogr.Open('/vsimem//temp1'+ext)
     12    lyr = ds.GetLayer(0)
     13    feat = lyr.GetNextFeature()
     14    while feat is not None:
     15        geometry+=[feat.Clone()]
     16        feat.Destroy()
     17        feat = lyr.GetNextFeature()
     18    ds.Destroy()
     19    osgeo.gdal.Unlink('/vsimem//temp1'+ext)
     20    return geometry
     21
     22def buildFeatureFromGeomtry(conf,geom,driverName,ext):
     23    drv = osgeo.ogr.GetDriverByName( driverName )
     24    ds = drv.CreateDataSource( "/vsimem//store"+conf["lenv"]["sid"]+"0."+ext )
     25    lyr = ds.CreateLayer( "Result", None, osgeo.ogr.wkbUnknown )
     26    field_defn = osgeo.ogr.FieldDefn( "Name", osgeo.ogr.OFTString )
     27    field_defn.SetWidth( len("Result10000") )
     28    lyr.CreateField ( field_defn )
     29    feat = osgeo.ogr.Feature(lyr.GetLayerDefn())
     30    feat.SetField( "Name", "Input0" )
     31    feat.SetGeometry(geom)
     32    lyr.CreateFeature(feat)
     33    ds.Destroy()
     34    return [feat]
     35
    836def createGeometryFromWFS(conf,my_wfs_response):
    9     geometry=[]
    10     try:
    11         # Create virtual file or parse XML file depending on the GDAL Version
    12         gV=int(osgeo.gdal.VersionInfo())
    13         if gV >= 1800:
    14             osgeo.gdal.FileFromMemBuffer('/vsimem//temp', my_wfs_response)
    15             ds = osgeo.ogr.Open('/vsimem//temp')
    16             lyr = ds.GetLayer(0)
    17             feat = lyr.GetNextFeature()
    18             while feat is not None:
    19                 geometry+=[feat.GetGeometryRef().Clone()]
    20                 feat.Destroy()
    21                 feat = lyr.GetNextFeature()
    22             ds.Destroy()
    23             osgeo.gdal.Unlink('/vsimem//temp')
     37    try:
     38        geom=osgeo.ogr.CreateGeometryFromGML(my_wfs_response.replace('<?xml version="1.0" encoding="utf-8"?>\n',''))
     39    except:
     40        geom=None
     41    try:
     42        if geom is None:
     43            return readFileFromBuffer(my_wfs_response,"")
    2444        else:
    25             doc=libxml2.parseMemory(my_wfs_response,len(my_wfs_response))
    26             ctxt = doc.xpathNewContext()
    27             res=ctxt.xpathEval("/*/*/*/*/*[local-name()='Polygon' or local-name()='MultiPolygon' or local-name()='Point' or local-name()='MultiPoint' or local-name()='MultiLineString' or local-name()='LineString' ]")
    28             for node in res:
    29                 geometry_as_string=node.serialize()
    30                 geometry+=[osgeo.ogr.CreateGeometryFromGML(geometry_as_string)]
    31     except:
    32         print >> sys.stderr,"Unable to load file from mem buffer\n\n\n"
    33     return geometry
     45            return buildFeatureFromGeomtry(conf,geom,"GML","xml")
     46    except:
     47        print >> sys.stderr,"Unable to load file input data !!!\n\n\n"
     48
     49def createLayerFromJson(conf,obj):
     50    geom=osgeo.ogr.CreateGeometryFromJson(obj)
     51    if geom is None:
     52        return readFileFromBuffer(obj,".json")
     53    else:
     54        return buildFeatureFromGeomtry(conf,geom,"GeoJSON","json")
    3455
    3556def extractInputs(conf,obj):
    3657    if obj["mimeType"]=="application/json":
    37         return [osgeo.ogr.CreateGeometryFromJson(obj["value"])]
     58        return createLayerFromJson(conf,obj["value"])
    3859    else:
    39         try:
    40                 return createGeometryFromWFS(conf,obj["value"])
    41         except:
    42                 return [osgeo.ogr.CreateGeometryFromJson(obj["value"])]
    43     return null
     60        return createGeometryFromWFS(conf,obj["value"])
    4461   
    4562def outputResult(conf,obj,geom):
     
    4966        driverName = "GeoJSON"
    5067        extension = [ ".js" ]
     68    if obj.keys().count("schema")>0 and \
     69            obj["schema"]=="http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd":
     70        driverName = "KML"
     71        extension = [ ".kml" ]
    5172    drv = osgeo.ogr.GetDriverByName( driverName )
    52     # Create virtual file or real one depending on the GDAL Version
    53     gV=int(osgeo.gdal.VersionInfo())
    54     if gV >= 1800:
    55         ds = drv.CreateDataSource( "/vsimem/store"+conf["lenv"]["sid"]+extension[0] )
    56     else:
    57         ds = drv.CreateDataSource( conf["main"]["tmpPath"]+"/store"+conf["lenv"]["sid"]+extension[0] )
     73    # Create virtual file
     74    ds = drv.CreateDataSource( "/vsimem/store"+conf["lenv"]["sid"]+extension[0] )
    5875    lyr = ds.CreateLayer( "Result", None, osgeo.ogr.wkbUnknown )
    59     field_defn = osgeo.ogr.FieldDefn( "Name", osgeo.ogr.OFTString )
    60     field_defn.SetWidth( len("Result10000") )
    61     lyr.CreateField ( field_defn )
    6276    i=0
    6377    while i < len(geom):
    64         feat = osgeo.ogr.Feature( lyr.GetLayerDefn())
    65         feat.SetField( "Name", "Result"+str(i) )
    66         feat.SetGeometry(geom[i])
    67         lyr.CreateFeature(feat)
    68         feat.Destroy()
     78        lyr.CreateFeature(geom[i])
    6979        geom[i].Destroy()
    7080        i+=1
    7181    ds.Destroy()
    72     if gV >= 1800:
    73         vsiFile=osgeo.gdal.VSIFOpenL("/vsimem/store"+conf["lenv"]["sid"]+extension[0],"r")
    74         i=0
    75         while osgeo.gdal.VSIFSeekL(vsiFile,0,os.SEEK_END)>0:
    76             i+=1
    77         fileSize=osgeo.gdal.VSIFTellL(vsiFile)
    78         osgeo.gdal.VSIFSeekL(vsiFile,0,os.SEEK_SET)
    79         obj["value"]=osgeo.gdal.VSIFReadL(fileSize,1,vsiFile)
    80         osgeo.gdal.Unlink("/vsimem/store"+conf["lenv"]["sid"]+extension[0])
    81     else:
    82         obj["value"]=open(conf["main"]["tmpPath"]+"/store"+conf["lenv"]["sid"]+extension[0],"r").read()
    83         os.unlink(conf["main"]["tmpPath"]+"/store"+conf["lenv"]["sid"]+extension[0])
    84         if len(extension)>1:
    85             os.unlink(conf["main"]["tmpPath"]+"/store"+conf["lenv"]["sid"]+extension[1])
     82    vsiFile=osgeo.gdal.VSIFOpenL("/vsimem/store"+conf["lenv"]["sid"]+extension[0],"r")
     83    i=0
     84    while osgeo.gdal.VSIFSeekL(vsiFile,0,os.SEEK_END)>0:
     85        i+=1
     86    fileSize=osgeo.gdal.VSIFTellL(vsiFile)
     87    osgeo.gdal.VSIFSeekL(vsiFile,0,os.SEEK_SET)
     88    obj["value"]=osgeo.gdal.VSIFReadL(fileSize,1,vsiFile)
     89    osgeo.gdal.Unlink("/vsimem/store"+conf["lenv"]["sid"]+extension[0])
     90
     91def BufferPy(conf,inputs,outputs):
     92    print >> sys.stderr, inputs
     93    print >> sys.stderr, outputs
     94    try:
     95        bdist=float(inputs["BufferDistance"]["value"])
     96    except:
     97        bdist=1
     98    print >> sys.stderr, bdist
    8699   
     100    geometry=extractInputs(conf,inputs["InputPolygon"])
     101    i=0
     102    rgeometries=[]
     103    while i < len(geometry):
     104        tmp=geometry[i].Clone()
     105        resg=geometry[i].GetGeometryRef().Buffer(bdist)
     106        tmp.SetGeometryDirectly(resg)
     107        rgeometries+=[tmp]
     108        geometry[i].Destroy()
     109        resg.thisown=False
     110        tmp.thisown=False
     111        i+=1
     112    outputResult(conf,outputs["Result"],rgeometries)
     113    i=0
     114    return 3
    87115
    88116def BoundaryPy(conf,inputs,outputs):
     
    91119    rgeometries=[]
    92120    while i < len(geometry):
    93         rgeometries+=[geometry[i].GetBoundary()]
     121        tmp=geometry[i].Clone()
     122        resg=geometry[i].GetGeometryRef()
     123        resg=resg.GetBoundary()
     124        tmp.SetGeometryDirectly(resg)
     125        rgeometries+=[tmp]
    94126        geometry[i].Destroy()
    95127        i+=1
     
    102134    rgeometries=[]
    103135    while i < len(geometry):
    104         if geometry[i].GetGeometryType()!=3:
    105             geometry[i]=geometry[i].ConvexHull()
    106         rgeometries+=[geometry[i].Centroid()]
     136        tmp=geometry[i].Clone()
     137        resg=geometry[i].GetGeometryRef()
     138        if resg.GetGeometryType()!=3:
     139            resg=resg.ConvexHull()
     140        resg=resg.Centroid()
     141        tmp.SetGeometryDirectly(resg)
     142        rgeometries+=[tmp]
    107143        geometry[i].Destroy()
    108144        i+=1
     
    115151    rgeometries=[]
    116152    while i < len(geometry):
    117         rgeometries+=[geometry[i].ConvexHull()]
    118         geometry[i].Destroy()
    119         i+=1
    120     outputResult(conf,outputs["Result"],rgeometries)
    121     return 3
    122 
    123 def BufferPy(conf,inputs,outputs):
     153        tmp=geometry[i].Clone()
     154        resg=geometry[i].GetGeometryRef().ConvexHull()
     155        tmp.SetGeometryDirectly(resg)
     156        rgeometries+=[tmp]
     157        geometry[i].Destroy()
     158        i+=1
     159    outputResult(conf,outputs["Result"],rgeometries)
     160    return 3
     161
     162
     163
     164def EnvelopePy(conf,inputs,outputs):
     165    print >> sys.stderr, inputs
    124166    try:
    125167        bdist=float(inputs["BufferDistance"]["value"])
     
    127169        bdist=10
    128170    geometry=extractInputs(conf,inputs["InputPolygon"])
    129     i=0
    130     rgeometries=[]
    131     while i < len(geometry):
    132         rgeometries+=[geometry[i].Buffer(bdist)]
    133         geometry[i].Destroy()
    134         i+=1
    135     outputResult(conf,outputs["Result"],rgeometries)
    136     i=0
     171    tmp=geometry[0].GetGeometryRef().GetEnvelope()
     172    outputs["Result"]["value"]=str(tmp[0])+','+str(tmp[2])+','+str(tmp[1])+','+str(tmp[3])+','+'urn:ogc:def:crs:OGC:1.3:CRS84'
     173    print >> sys.stderr,outputs["Result"]
    137174    return 3
    138175
     
    159196
    160197def IntersectionPy(conf,inputs,outputs):
    161     geometry1=extractInputs(conf,inputs["InputEntity1"])
    162     geometry2=extractInputs(conf,inputs["InputEntity2"])
    163     rgeometries=[]
    164     i=0
    165     while i < len(geometry1):
    166         j=0
    167         while j < len(geometry2):
    168             tres=geometry1[i].Intersection(geometry2[j])
    169             if not(tres.IsEmpty()):
    170                 rgeometries+=[tres]
    171             j+=1
    172         geometry1[i].Destroy()
    173         i+=1
    174     i=0
    175     while i < len(geometry2):
    176         geometry2[i].Destroy()
    177         i+=1
    178     outputResult(conf,outputs["Result"],rgeometries)
     198
     199    geometry1=extractInputs(conf,inputs["InputEntity1"])
     200    print >> sys.stderr,inputs["InputEntity2"]
     201    geometry2=extractInputs(conf,inputs["InputEntity2"])
     202
     203    rgeometries=[]
     204    i=0
     205    while i < len(geometry1):
     206        j=0
     207        while j < len(geometry2):
     208            tmp=geometry2[j].Clone()
     209            resg=geometry2[j].GetGeometryRef()
     210            #resg=resg.Intersection(geometry1[i].GetGeometryRef())
     211            resg=geometry1[i].GetGeometryRef().Intersection(resg)
     212            tmp.SetGeometryDirectly(resg)
     213            if not(resg.IsEmpty()):
     214                rgeometries+=[tmp]
     215            j+=1
     216        geometry1[i].Destroy()
     217        i+=1
     218    i=0
     219    while i < len(geometry2):
     220        geometry2[i].Destroy()
     221        i+=1
     222    outputResult(conf,outputs["Result"],rgeometries)
     223    print >> sys.stderr,"/outputResult"
    179224    return 3
    180225
     
    187232        j=0
    188233        while j < len(geometry2):
    189             tres=geometry1[i].Difference(geometry2[j])
    190             if not(tres.IsEmpty()):
    191                 rgeometries+=[tres]
     234            tmp=geometry2[j].Clone()
     235            resg=geometry1[i].GetGeometryRef()
     236            resg=resg.Difference(geometry2[i].GetGeometryRef())
     237            tmp.SetGeometryDirectly(resg)
     238            if not(resg.IsEmpty()):
     239                rgeometries+=[tmp]
    192240            j+=1
    193241        geometry1[i].Destroy()
     
    208256        j=0
    209257        while j < len(geometry2):
    210             rgeometries+=[geometry1[i].SymmetricDifference(geometry2[j])]
    211             j+=1
    212         geometry1[i].Destroy()
    213         i+=1
    214     i=0
    215     while i < len(geometry2):
    216         geometry2[i].Destroy()
    217         i+=1
    218     outputResult(conf,outputs["Result"],rgeometries)
    219     return 3
     258            tmp=geometry2[j].Clone()
     259            resg=geometry1[i].GetGeometryRef()
     260            resg=resg.SymmetricDifference(geometry2[i].GetGeometryRef())
     261            tmp.SetGeometryDirectly(resg)
     262            rgeometries+=[tmp]
     263            j+=1
     264        geometry1[i].Destroy()
     265        i+=1
     266    i=0
     267    while i < len(geometry2):
     268        geometry2[i].Destroy()
     269        i+=1
     270    outputResult(conf,outputs["Result"],rgeometries)
     271    return 3
     272
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