Changeset 491 for trunk/zoo-project


Ignore:
Timestamp:
Jun 27, 2014, 1:43:56 AM (10 years ago)
Author:
djay
Message:

Update ogr base-vector-ops services suite. Fixing issue #100.

Location:
trunk/zoo-project/zoo-services/ogr/base-vect-ops
Files:
9 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/zoo-project/zoo-services/ogr/base-vect-ops/Makefile

    r284 r491  
    33CFLAGS=${ZOO_CFLAGS} ${JSCFLAGS} ${XML2CFLAGS} ${GDAL_CFLAGS} `geos-config --cflags` -DLINUX_FREE_ISSUE #-DDEBUG
    44
     5ifneq ($(MS_FILE),)
     6        MS_FILES=${ZRPATH}/zoo-kernel/${MS_FILE} -lmapserver
     7else
     8        MS_FILES=
     9endif
     10
    511cgi-env/ogr_service.zo: service.c
    6         g++ ${CFLAGS} -shared -fpic -o cgi-env/ogr_service.zo ./service.c ../../../zoo-kernel/service_internal.o ${JS_LDFLAGS} ${JSLDFLAGS} ${GDAL_LIBS} ${XML2LDFLAGS} ${MACOS_LD_FLAGS} ${ZOO_LDFLAGS} ${MACOS_LD_NET_FLAGS} `geos-config --libs`
     12        g++ ${CFLAGS} -shared -fpic -o cgi-env/ogr_service.zo ./service.c ../../../zoo-kernel/service_internal.o ${JS_LDFLAGS} ${JSLDFLAGS} ${GDAL_LIBS} ${XML2LDFLAGS} ${MACOS_LD_FLAGS} ${ZOO_LDFLAGS} ${MACOS_LD_NET_FLAGS} `geos-config --libs` ${MS_FILES} -lfcgi
    713
    814clean:
  • trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/Boundary.zcfg

    r106 r491  
    11[Boundary]
    22 Title = Compute boundary.
    3  Abstract = A new geometry object is created and returned containing the boundary of the geometry on which the method is invoked.
     3 Abstract = This service shall return a feature callection representing the combinatorial boundary of each geometry in the InputPolygon feature collection.
    44 processVersion = 1
    55 storeSupported = true
  • trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/Buffer.zcfg

    r106 r491  
    11[Buffer]
    22 Title = Create a buffer around a polygon.
    3  Abstract = Create a buffer around a single polygon. Accepts the polygon as GML and provides GML output for the buffered feature.
     3 Abstract = This service shall return a feature collection representing the buffer of geometry InputPolygon at distance BufferDistance. The buffer of a geometry at distance d is the Polygon or MultiPolygon which contains all points within a distance d of the geometry.
    44 Profile = urn:ogc:wps:1.0.0:buffer
    55 processVersion = 2
     
    6363    </Default>
    6464    <Supported>
    65      mimeType = text/xml
    66      encoding = base64
    67      schema = http://fooa/gml/3.1.0/polygon.xsd
    68      extension = xml
    69     </Supported>
    70     <Supported>
    7165     mimeType = application/json
    7266     encoding = UTF-8
  • trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/Centroid.zcfg

    r106 r491  
    11[Centroid]
    22 Title = Get the centroid of a polygon.
    3  Abstract = Compute the geometry centroid.
     3 Abstract = This service shall return the point that is the geometric centre of gravity of the geometry InputPolygon.
    44 Profile = urn:ogc:wps:1.0.0:centroid
    55 processVersion = 2
  • trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/ConvexHull.zcfg

    r106 r491  
    11[ConvexHull]
    22 Title = Compute convex hull.
    3  Abstract = A new geometry object is created and returned containing the convex hull of the geometry on which the method is invoked.
     3 Abstract = This service shall return a feature collection that represents the convex hull of geometry InputPolygon. The convex hull is the smallest convex polygon that contains all points of the geometry. The convex Hull for a geometry of encoding data type Point is the point itself
    44 processVersion = 1
    55 storeSupported = true
  • trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/Difference.zcfg

    r106 r491  
    11[Difference]
    22 Title = Compute difference. .
    3  Abstract = Generates a new geometry which is the region of this geometry with the region of the other geometry removed.
     3 Abstract = This function SHALL return a bag of geometry values representing the closure of the set difference between the two geometries InputEntity1 and InputEntity2. The difference is the set of all points which lie on InputEntity1 but not on InputEntity2.
    44 Profile = urn:ogc:wps:1.0.0:difference
    55 processVersion = 2
  • trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/Intersection.zcfg

    r106 r491  
    11[Intersection]
    22 Title = Compute intersection.
    3  Abstract = Generates a new geometry which is the region of intersection of the two geometries operated on.
     3 Abstract = This function SHALL return a bag of geometry values representing the Point set intersection of geometry InputEntity1 and geometry InputEntity2.
    44 Profile = urn:ogc:wps:1.0.0:union
    55 processVersion = 2
  • trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/SymDifference.zcfg

    r106 r491  
    11[SymDifference]
    22 Title = Compute symmetric difference.
    3  Abstract = Generates a new geometry which is the symmetric difference of this geometry and the other geometry.
     3 Abstract = This service shall return a feature collection representing the closure of the symmetric difference of two Geometries. The symmetric difference is the set of points which lie on either InputEntity1 or InputEntity2 but not in both.
    44 Profile = urn:ogc:wps:1.0.0:symmetricdifference
    55 processVersion = 2
  • trunk/zoo-project/zoo-services/ogr/base-vect-ops/cgi-env/Union.zcfg

    r106 r491  
    11[Union]
    22 Title = Compute union.
    3  Abstract = Generates a new geometry which is the region of union of the two geometries operated on.
    4  Profile = urn:ogc:wps:1.0.0:union
     3 Abstract = This service shall return a bag of geometry values representing a Point set union of geometry InputEntity1 with geometry InputEntity2.
     4 profile = urn:ogc:wps:1.0.0:union
    55 processVersion = 2
    66 storeSupported = true
  • trunk/zoo-project/zoo-services/ogr/base-vect-ops/service.c

    r348 r491  
    2626#include "ogr_api.h"
    2727#include "ogr_geometry.h"
     28
     29#include "cpl_minixml.h"
     30#include "ogr_api.h"
     31#include "ogrsf_frmts.h"
     32
    2833#include "geos_c.h"
    2934#include "service.h"
     
    4449  void printExceptionReportResponse(maps*,map*);
    4550  char *base64(const char *input, int length);
    46   int errorException(maps *m, const char *message, const char *errorcode);
    4751
    4852  OGRGeometryH createGeometryFromGML(maps* conf,char* inputStr){
     
    5357    xmlXPathContextPtr xpathCtx;
    5458    xmlXPathObjectPtr xpathObj;
    55     char * xpathExpr="/*/*/*/*/*[local-name()='Polygon' or local-name()='MultiPolygon']";
     59    const char * xpathExpr="/*/*/*/*/*[local-name()='Polygon' or local-name()='MultiPolygon']";
    5660    xpathCtx = xmlXPathNewContext(doc);
    5761    xpathObj = xmlXPathEvalExpression(BAD_CAST xpathExpr,xpathCtx);
     
    179183
    180184
    181   int applyOne(maps*& conf,maps*& inputs,maps*& outputs,OGRGeometryH (*myFunc)(OGRGeometryH),char* schema){
    182 #ifdef DEBUG
    183     fprintf(stderr,"\nService internal print\n");
    184 #endif
     185  int applyOne(maps*& conf,maps*& inputs,maps*& outputs,OGRGeometry* (OGRGeometry::*myFunc)() const,const char* schema){
     186    OGRRegisterAll();
     187
    185188    maps* cursor=inputs;
    186189    OGRGeometryH geometry,res;
    187 #ifdef DEBUG
    188     dumpMaps(cursor);
    189 #endif
     190    OGRLayer *poDstLayer;
     191    const char *oDriver1;
     192    OGRDataSource       *poODS;
    190193    map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
    191194    if(!tmp){
     
    193196      return SERVICE_FAILED;
    194197    }
    195 #ifdef DEBUG
    196     fprintf(stderr,"Service internal print \n");
    197     dumpMaps(inputs);
    198     fprintf(stderr,"/Service internal print \n");
    199 #endif
     198    char filename[1024];
    200199    map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType");
    201 #ifdef DEBUG
    202     fprintf(stderr,"Service internal print \n");
    203     dumpMap(tmp1);
    204     fprintf(stderr,"/Service internal print \n");
    205 #endif
     200    const char *oDriver;
     201    oDriver="GeoJSON";
     202    sprintf(filename,"/vsimem/input_%d.json",getpid());
    206203    if(tmp1!=NULL){
    207       if(strncmp(tmp1->value,"text/js",7)==0 ||
    208          strncmp(tmp1->value,"application/json",7)==0)
    209         geometry=OGR_G_CreateGeometryFromJson(tmp->value);
    210       else
    211         geometry=createGeometryFromGML(conf,tmp->value);
     204      if(strcmp(tmp1->value,"text/xml")==0){
     205        sprintf(filename,"/vsimem/input_%d.xml",getpid());
     206        oDriver="GML";
     207      }
     208    }
     209    VSILFILE *ifile=VSIFileFromMemBuffer(filename,(GByte*)tmp->value,strlen(tmp->value),FALSE);
     210    VSIFCloseL(ifile);
     211    OGRDataSource* ipoDS = OGRSFDriverRegistrar::Open(filename,FALSE);
     212    char pszDestDataSource[100];
     213    if( ipoDS == NULL )
     214      {
     215        OGRSFDriverRegistrar    *poR = OGRSFDriverRegistrar::GetRegistrar();
     216       
     217        fprintf( stderr, "FAILURE:\n"
     218                 "Unable to open datasource `%s' with the following drivers.\n",
     219                 filename );
     220       
     221        for( int iDriver = 0; iDriver < poR->GetDriverCount(); iDriver++ )
     222          {
     223            fprintf( stderr, "  -> %s\n", poR->GetDriver(iDriver)->GetName() );
     224          }
     225        char tmp[1024];
     226        sprintf(tmp,"Unable to open datasource `%s' with the following drivers.",filename);
     227        setMapInMaps(conf,"lenv","message",tmp);
     228        return SERVICE_FAILED;
     229      }
     230    for( int iLayer = 0; iLayer < ipoDS->GetLayerCount();
     231         iLayer++ )
     232      {
     233        OGRLayer        *poLayer = ipoDS->GetLayer(iLayer);
     234       
     235        if( poLayer == NULL )
     236          {
     237            fprintf( stderr, "FAILURE: Couldn't fetch advertised layer %d!\n",
     238                     iLayer );
     239            char tmp[1024];
     240            sprintf(tmp,"Couldn't fetch advertised layer %d!",iLayer);
     241            setMapInMaps(conf,"lenv","message",tmp);
     242            return SERVICE_FAILED;
     243          }
     244       
     245        OGRFeature  *poFeature;
     246
     247        /* -------------------------------------------------------------------- */
     248        /*      Try opening the output datasource as an existing, writable      */
     249        /* -------------------------------------------------------------------- */
     250       
     251        OGRSFDriverRegistrar *poR = OGRSFDriverRegistrar::GetRegistrar();
     252        OGRSFDriver          *poDriver = NULL;
     253        int                  iDriver;
     254       
     255        map* tmpMap=getMapFromMaps(outputs,"Result","mimeType");
     256        oDriver1="GeoJSON";
     257        sprintf(pszDestDataSource,"/vsimem/result_%d.json",getpid());
     258        if(tmpMap!=NULL){
     259          if(strcmp(tmpMap->value,"text/xml")==0){
     260            sprintf(pszDestDataSource,"/vsimem/result_%d.xml",getpid());
     261            oDriver1="GML";
     262          }
     263        }
     264       
     265        for( iDriver = 0;
     266             iDriver < poR->GetDriverCount() && poDriver == NULL;
     267             iDriver++ )
     268          {
     269            if( EQUAL(poR->GetDriver(iDriver)->GetName(),oDriver1) )
     270              {
     271                poDriver = poR->GetDriver(iDriver);
     272              }
     273          }
     274       
     275        if( poDriver == NULL )
     276          {
     277            char emessage[8192];
     278            sprintf( emessage, "Unable to find driver `%s'.\n", oDriver );
     279            sprintf( emessage,  "%sThe following drivers are available:\n",emessage );
     280           
     281            for( iDriver = 0; iDriver < poR->GetDriverCount(); iDriver++ )
     282              {
     283                sprintf( emessage,  "%s  -> `%s'\n", emessage, poR->GetDriver(iDriver)->GetName() );
     284              }
     285           
     286            setMapInMaps(conf,"lenv","message",emessage);
     287            return SERVICE_FAILED;
     288           
     289          }
     290       
     291        if( !poDriver->TestCapability( ODrCCreateDataSource ) ){
     292          char emessage[1024];
     293          sprintf( emessage,  "%s driver does not support data source creation.\n",
     294                   "json" );
     295          setMapInMaps(conf,"lenv","message",emessage);
     296          return SERVICE_FAILED;
     297        }
     298       
     299        /* -------------------------------------------------------------------- */
     300        /*      Create the output data source.                                  */
     301        /* -------------------------------------------------------------------- */
     302        //map* tpath=getMapFromMaps(conf,"main","tmpPath");
     303        char **papszDSCO=NULL;
     304        poODS = poDriver->CreateDataSource( pszDestDataSource, papszDSCO );
     305        if( poODS == NULL ){
     306          char emessage[1024];     
     307          sprintf( emessage,  "%s driver failed to create %s\n",
     308                   "json", pszDestDataSource );
     309          setMapInMaps(conf,"lenv","message",emessage);
     310          return SERVICE_FAILED;
     311        }
     312       
     313        /* -------------------------------------------------------------------- */
     314        /*      Create the layer.                                               */
     315        /* -------------------------------------------------------------------- */
     316        if( !poODS->TestCapability( ODsCCreateLayer ) )
     317          {
     318            char emessage[1024];
     319            sprintf( emessage,
     320                     "Layer %s not found, and CreateLayer not supported by driver.",
     321                     "Result" );
     322            setMapInMaps(conf,"lenv","message",emessage);
     323            return SERVICE_FAILED;
     324          }
     325       
     326        //CPLErrorReset();
     327       
     328        poDstLayer = poODS->CreateLayer( "Result", NULL,wkbUnknown,NULL);
     329        if( poDstLayer == NULL ){
     330          setMapInMaps(conf,"lenv","message","Layer creation failed.\n");
     331          return SERVICE_FAILED;
     332        }
     333       
     334        OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
     335        int iField;
     336        int hasMmField=0;
     337       
     338        for( iField = 0; iField < poFDefn->GetFieldCount(); iField++ )
     339          {
     340            OGRFieldDefn *tmp=poFDefn->GetFieldDefn(iField);
     341            if (iField >= 0)
     342                poDstLayer->CreateField( poFDefn->GetFieldDefn(iField) );
     343            else
     344            {
     345                fprintf( stderr, "Field '%s' not found in source layer.\n",
     346                        iField );
     347                return SERVICE_FAILED;
     348            }
     349          }
     350
     351        while(TRUE){
     352          OGRFeature      *poDstFeature = NULL;
     353          poFeature = poLayer->GetNextFeature();
     354          if( poFeature == NULL )
     355            break;
     356          if(poFeature->GetGeometryRef() != NULL){
     357            // DO SOMETHING HERE !!
     358            poDstFeature = OGRFeature::CreateFeature( poDstLayer->GetLayerDefn() );
     359            if( poDstFeature->SetFrom( poFeature, TRUE ) != OGRERR_NONE )
     360              {
     361                char tmpMsg[1024];
     362                sprintf( tmpMsg,"Unable to translate feature %ld from layer %s.\n",
     363                         poFeature->GetFID(), poFDefn->GetName() );
     364               
     365                OGRFeature::DestroyFeature( poFeature );
     366                OGRFeature::DestroyFeature( poDstFeature );
     367                return SERVICE_FAILED;
     368              }
     369            if(poDstFeature->SetGeometryDirectly((poDstFeature->GetGeometryRef()->*myFunc)()) != OGRERR_NONE )
     370              {
     371                char tmpMsg[1024];
     372                sprintf( tmpMsg,"Unable to translate feature %ld from layer %s.\n",
     373                         poFeature->GetFID(), poFDefn->GetName() );
     374               
     375                OGRFeature::DestroyFeature( poFeature );
     376                OGRFeature::DestroyFeature( poDstFeature );
     377                return SERVICE_FAILED;
     378              }
     379            OGRFeature::DestroyFeature( poFeature );
     380            if( poDstLayer->CreateFeature( poDstFeature ) != OGRERR_NONE )
     381              {         
     382                OGRFeature::DestroyFeature( poDstFeature );
     383                return SERVICE_FAILED;
     384              }
     385            OGRFeature::DestroyFeature( poDstFeature );
     386          }
     387        }
     388
     389      }
     390
     391    delete poODS;
     392    delete ipoDS;
     393
     394    char *res1=readVSIFile(conf,pszDestDataSource);
     395    if(res1==NULL)
     396      return SERVICE_FAILED;
     397    setMapInMaps(outputs,"Result","value",res1);
     398    free(res1);
     399
     400    OGRCleanupAll();
     401    return SERVICE_SUCCEEDED;
     402  }
     403
     404#ifdef WIN32
     405  __declspec(dllexport)
     406#endif
     407int Buffer(maps*& conf,maps*& inputs,maps*& outputs){
     408    OGRRegisterAll();
     409
     410    double bufferDistance;
     411    map* tmp0=getMapFromMaps(inputs,"BufferDistance","value");
     412    if(tmp0==NULL){
     413      bufferDistance=atof("10.0");
    212414    }
    213415    else
    214       geometry=createGeometryFromGML(conf,tmp->value);
    215     if(geometry==NULL){
     416      bufferDistance=atof(tmp0->value);
     417
     418    maps* cursor=inputs;
     419    OGRGeometryH geometry,res;
     420    OGRLayer *poDstLayer;
     421    const char *oDriver1;
     422    OGRDataSource       *poODS;
     423    map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
     424    if(!tmp){
    216425      setMapInMaps(conf,"lenv","message",_ss("Unable to parse the input geometry from InputPolygon"));
    217426      return SERVICE_FAILED;
    218427    }
    219     res=(*myFunc)(geometry);
     428    char filename[1024];
     429    map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType");
     430    const char *oDriver;
     431    oDriver="GeoJSON";
     432    sprintf(filename,"/vsimem/input_%d.json",getpid());
     433    if(tmp1!=NULL){
     434      if(strcmp(tmp1->value,"text/xml")==0){
     435        sprintf(filename,"/vsimem/input_%d.xml",getpid());
     436        oDriver="GML";
     437      }
     438    }
     439    VSILFILE *ifile=VSIFileFromMemBuffer(filename,(GByte*)tmp->value,strlen(tmp->value),FALSE);
     440    VSIFCloseL(ifile);
     441    OGRDataSource* ipoDS = OGRSFDriverRegistrar::Open(filename,FALSE);
     442    char pszDestDataSource[100];
     443    if( ipoDS == NULL )
     444      {
     445        OGRSFDriverRegistrar    *poR = OGRSFDriverRegistrar::GetRegistrar();
     446       
     447        fprintf( stderr, "FAILURE:\n"
     448                 "Unable to open datasource `%s' with the following drivers.\n",
     449                 filename );
     450       
     451        for( int iDriver = 0; iDriver < poR->GetDriverCount(); iDriver++ )
     452          {
     453            fprintf( stderr, "  -> %s\n", poR->GetDriver(iDriver)->GetName() );
     454          }
     455        char tmp[1024];
     456        sprintf(tmp,"Unable to open datasource `%s' with the following drivers.",filename);
     457        setMapInMaps(conf,"lenv","message",tmp);
     458        return SERVICE_FAILED;
     459      }
     460    for( int iLayer = 0; iLayer < ipoDS->GetLayerCount();
     461         iLayer++ )
     462      {
     463        OGRLayer        *poLayer = ipoDS->GetLayer(iLayer);
     464       
     465        if( poLayer == NULL )
     466          {
     467            fprintf( stderr, "FAILURE: Couldn't fetch advertised layer %d!\n",
     468                     iLayer );
     469            char tmp[1024];
     470            sprintf(tmp,"Couldn't fetch advertised layer %d!",iLayer);
     471            setMapInMaps(conf,"lenv","message",tmp);
     472            return SERVICE_FAILED;
     473          }
     474       
     475        OGRFeature  *poFeature;
     476
     477        /* -------------------------------------------------------------------- */
     478        /*      Try opening the output datasource as an existing, writable      */
     479        /* -------------------------------------------------------------------- */
     480       
     481        OGRSFDriverRegistrar *poR = OGRSFDriverRegistrar::GetRegistrar();
     482        OGRSFDriver          *poDriver = NULL;
     483        int                  iDriver;
     484       
     485        map* tmpMap=getMapFromMaps(outputs,"Result","mimeType");
     486        oDriver1="GeoJSON";
     487        sprintf(pszDestDataSource,"/vsimem/result_%d.json",getpid());
     488        if(tmpMap!=NULL){
     489          if(strcmp(tmpMap->value,"text/xml")==0){
     490            sprintf(pszDestDataSource,"/vsimem/result_%d.xml",getpid());
     491            oDriver1="GML";
     492          }
     493        }
     494       
     495        for( iDriver = 0;
     496             iDriver < poR->GetDriverCount() && poDriver == NULL;
     497             iDriver++ )
     498          {
     499            if( EQUAL(poR->GetDriver(iDriver)->GetName(),oDriver1) )
     500              {
     501                poDriver = poR->GetDriver(iDriver);
     502              }
     503          }
     504       
     505        if( poDriver == NULL )
     506          {
     507            char emessage[8192];
     508            sprintf( emessage, "Unable to find driver `%s'.\n", oDriver );
     509            sprintf( emessage,  "%sThe following drivers are available:\n",emessage );
     510           
     511            for( iDriver = 0; iDriver < poR->GetDriverCount(); iDriver++ )
     512              {
     513                sprintf( emessage,  "%s  -> `%s'\n", emessage, poR->GetDriver(iDriver)->GetName() );
     514              }
     515           
     516            setMapInMaps(conf,"lenv","message",emessage);
     517            return SERVICE_FAILED;
     518           
     519          }
     520       
     521        if( !poDriver->TestCapability( ODrCCreateDataSource ) ){
     522          char emessage[1024];
     523          sprintf( emessage,  "%s driver does not support data source creation.\n",
     524                   "json" );
     525          setMapInMaps(conf,"lenv","message",emessage);
     526          return SERVICE_FAILED;
     527        }
     528       
     529        /* -------------------------------------------------------------------- */
     530        /*      Create the output data source.                                  */
     531        /* -------------------------------------------------------------------- */
     532        //map* tpath=getMapFromMaps(conf,"main","tmpPath");
     533        char **papszDSCO=NULL;
     534        poODS = poDriver->CreateDataSource( pszDestDataSource, papszDSCO );
     535        if( poODS == NULL ){
     536          char emessage[1024];     
     537          sprintf( emessage,  "%s driver failed to create %s\n",
     538                   "json", pszDestDataSource );
     539          setMapInMaps(conf,"lenv","message",emessage);
     540          return SERVICE_FAILED;
     541        }
     542       
     543        /* -------------------------------------------------------------------- */
     544        /*      Create the layer.                                               */
     545        /* -------------------------------------------------------------------- */
     546        if( !poODS->TestCapability( ODsCCreateLayer ) )
     547          {
     548            char emessage[1024];
     549            sprintf( emessage,
     550                     "Layer %s not found, and CreateLayer not supported by driver.",
     551                     "Result" );
     552            setMapInMaps(conf,"lenv","message",emessage);
     553            return SERVICE_FAILED;
     554          }
     555       
     556        //CPLErrorReset();
     557       
     558        poDstLayer = poODS->CreateLayer( "Result", NULL,wkbUnknown,NULL);
     559        if( poDstLayer == NULL ){
     560          setMapInMaps(conf,"lenv","message","Layer creation failed.\n");
     561          return SERVICE_FAILED;
     562        }
     563       
     564        OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
     565        int iField;
     566        int hasMmField=0;
     567       
     568        for( iField = 0; iField < poFDefn->GetFieldCount(); iField++ )
     569          {
     570            OGRFieldDefn *tmp=poFDefn->GetFieldDefn(iField);
     571            if (iField >= 0)
     572                poDstLayer->CreateField( poFDefn->GetFieldDefn(iField) );
     573            else
     574            {
     575                fprintf( stderr, "Field '%s' not found in source layer.\n",
     576                        iField );
     577                return SERVICE_FAILED;
     578            }
     579          }
     580
     581        while(TRUE){
     582          OGRFeature      *poDstFeature = NULL;
     583          poFeature = poLayer->GetNextFeature();
     584          if( poFeature == NULL )
     585            break;
     586          if(poFeature->GetGeometryRef() != NULL){
     587            // DO SOMETHING HERE !!
     588            poDstFeature = OGRFeature::CreateFeature( poDstLayer->GetLayerDefn() );
     589            if( poDstFeature->SetFrom( poFeature, TRUE ) != OGRERR_NONE )
     590              {
     591                char tmpMsg[1024];
     592                sprintf( tmpMsg,"Unable to translate feature %ld from layer %s.\n",
     593                         poFeature->GetFID(), poFDefn->GetName() );
     594               
     595                OGRFeature::DestroyFeature( poFeature );
     596                OGRFeature::DestroyFeature( poDstFeature );
     597                return SERVICE_FAILED;
     598              }
     599            if(poDstFeature->SetGeometryDirectly(poDstFeature->GetGeometryRef()->Buffer(bufferDistance,30)) != OGRERR_NONE )
     600              {
     601                char tmpMsg[1024];
     602                sprintf( tmpMsg,"Unable to translate feature %ld from layer %s.\n",
     603                         poFeature->GetFID(), poFDefn->GetName() );
     604               
     605                OGRFeature::DestroyFeature( poFeature );
     606                OGRFeature::DestroyFeature( poDstFeature );
     607                return SERVICE_FAILED;
     608              }
     609            OGRFeature::DestroyFeature( poFeature );
     610            if( poDstLayer->CreateFeature( poDstFeature ) != OGRERR_NONE )
     611              {         
     612                OGRFeature::DestroyFeature( poDstFeature );
     613                return SERVICE_FAILED;
     614              }
     615            OGRFeature::DestroyFeature( poDstFeature );
     616          }
     617        }
     618
     619      }
     620
     621    delete poODS;
     622    delete ipoDS;
     623
     624    char *res1=readVSIFile(conf,pszDestDataSource);
     625    if(res1==NULL)
     626      return SERVICE_FAILED;
     627    setMapInMaps(outputs,"Result","value",res1);
     628    free(res1);
     629
     630    OGRCleanupAll();
     631    return SERVICE_SUCCEEDED;
     632
     633}
     634
     635#ifdef WIN32
     636  __declspec(dllexport)
     637#endif
     638  int Boundary(maps*& conf,maps*& inputs,maps*& outputs){
     639    return applyOne(conf,inputs,outputs,&OGRGeometry::Boundary,"http://fooa/gml/3.1.0/polygon.xsd");
     640  }
     641
     642#ifdef WIN32
     643  __declspec(dllexport)
     644#endif
     645  int ConvexHull(maps*& conf,maps*& inputs,maps*& outputs){
     646    return applyOne(conf,inputs,outputs,&OGRGeometry::ConvexHull,"http://fooa/gml/3.1.0/polygon.xsd");
     647  }
     648
     649
     650  OGRDataSource* loadEntity(maps* conf,maps* inputs,char **filename,const char **oDriver,const char *entity,int iter){
     651    map* tmp=getMapFromMaps(inputs,entity,"value");
     652    map* tmp1=getMapFromMaps(inputs,entity,"mimeType");
     653    *oDriver="GeoJSON";
     654    sprintf(*filename,"/vsimem/input_%d.json",getpid()+iter);
     655    if(tmp1!=NULL){
     656      if(strcmp(tmp1->value,"text/xml")==0){
     657        sprintf(*filename,"/vsimem/input_%d.xml",getpid()+iter);
     658        *oDriver="GML";
     659      }
     660    }
     661    VSILFILE *ifile=VSIFileFromMemBuffer(*filename,(GByte*)tmp->value,strlen(tmp->value),FALSE);
     662    VSIFCloseL(ifile);
     663    return OGRSFDriverRegistrar::Open(*filename,FALSE);   
     664  }
     665
     666  int applyOneBool(maps*& conf,maps*& inputs,maps*& outputs,OGRBoolean (OGRGeometry::*myFunc)() const){
    220667#ifdef DEBUG
    221     fprintf(stderr,"Service internal print \n");
    222     dumpMaps(outputs);
    223     fprintf(stderr,"/Service internal print \n");
    224 #endif
    225     map *tmp_2=getMapFromMaps(outputs,"Result","mimeType");
     668    fprintf(stderr,"\nService internal print\n");
     669#endif
     670    OGRRegisterAll();
     671
     672    maps* cursor=inputs;
     673    OGRGeometryH geometry,res;
     674    OGRLayer *poDstLayer;
     675    const char *oDriver1;
     676    OGRDataSource       *poODS;
    226677#ifdef DEBUG
    227     fprintf(stderr,"Service internal print \n");
    228     dumpMap(tmp_2);
    229     fprintf(stderr,"/Service internal print \n");
    230 #endif
    231     if(tmp_2!=NULL){
    232       if(strncmp(tmp_2->value,"text/js",7)==0 ||
    233          strncmp(tmp_2->value,"application/json",16)==0){
    234         char *tmpS=OGR_G_ExportToJson(res);
    235         setMapInMaps(outputs,"Result","value",tmpS);
    236 #ifndef WIN32
    237         setMapInMaps(outputs,"Result","mimeType","text/plain");
    238         setMapInMaps(outputs,"Result","encoding","UTF-8");
    239         free(tmpS);
    240 #endif
    241       }
    242       else{
    243         char *tmpS=OGR_G_ExportToGML(res);
    244         setMapInMaps(outputs,"Result","value",tmpS);
    245 #ifndef WIN32
    246         setMapInMaps(outputs,"Result","mimeType","text/xml");
    247         setMapInMaps(outputs,"Result","encoding","UTF-8");
    248         setMapInMaps(outputs,"Result","schema",schema);
    249         free(tmpS);
    250 #endif
    251       }
    252     }else{
    253       char *tmpS=OGR_G_ExportToJson(res);
    254       setMapInMaps(outputs,"Result","value",tmpS);
    255 #ifndef WIN32
    256       setMapInMaps(outputs,"Result","mimeType","text/plain");
    257       setMapInMaps(outputs,"Result","encoding","UTF-8");
    258       free(tmpS);
    259 #endif
    260     }
    261     //outputs->next=NULL;
     678    dumpMaps(cursor);
     679#endif
     680    map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
     681    if(!tmp){
     682      setMapInMaps(conf,"lenv","message",_ss("Unable to parse the input geometry from InputPolygon"));
     683      return SERVICE_FAILED;
     684    }
     685    char filename[1024];
     686    map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType");
     687    const char *oDriver;
     688    oDriver="GeoJSON";
     689    sprintf(filename,"/vsimem/input_%d.json",getpid());
     690    if(tmp1!=NULL){
     691      if(strcmp(tmp1->value,"text/xml")==0){
     692        sprintf(filename,"/vsimem/input_%d.xml",getpid());
     693        oDriver="GML";
     694      }
     695    }
     696    VSILFILE *ifile=VSIFileFromMemBuffer(filename,(GByte*)tmp->value,strlen(tmp->value),FALSE);
     697    VSIFCloseL(ifile);
     698    OGRDataSource* ipoDS = OGRSFDriverRegistrar::Open(filename,FALSE);
     699    char pszDestDataSource[100];
     700    if( ipoDS == NULL )
     701      {
     702        OGRSFDriverRegistrar    *poR = OGRSFDriverRegistrar::GetRegistrar();
     703       
     704        fprintf( stderr, "FAILURE:\n"
     705                 "Unable to open datasource `%s' with the following drivers.\n",
     706                 filename );
     707       
     708        for( int iDriver = 0; iDriver < poR->GetDriverCount(); iDriver++ )
     709          {
     710            fprintf( stderr, "  -> %s\n", poR->GetDriver(iDriver)->GetName() );
     711          }
     712        char tmp[1024];
     713        sprintf(tmp,"Unable to open datasource `%s' with the following drivers.",filename);
     714        setMapInMaps(conf,"lenv","message",tmp);
     715        return SERVICE_FAILED;
     716      }
     717    for( int iLayer = 0; iLayer < ipoDS->GetLayerCount();
     718         iLayer++ )
     719      {
     720        OGRLayer        *poLayer = ipoDS->GetLayer(iLayer);
     721       
     722        if( poLayer == NULL )
     723          {
     724            fprintf( stderr, "FAILURE: Couldn't fetch advertised layer %d!\n",
     725                     iLayer );
     726            char tmp[1024];
     727            sprintf(tmp,"Couldn't fetch advertised layer %d!",iLayer);
     728            setMapInMaps(conf,"lenv","message",tmp);
     729            return SERVICE_FAILED;
     730          }
     731       
     732        OGRFeature  *poFeature;
     733
     734
     735        while(TRUE){
     736          OGRFeature      *poDstFeature = NULL;
     737          poFeature = poLayer->GetNextFeature();
     738          if( poFeature == NULL )
     739            break;
     740          if(poFeature->GetGeometryRef() != NULL){
     741            // DO SOMETHING HERE !!
     742            if((poFeature->GetGeometryRef()->*myFunc)()==0){
     743              setMapInMaps(outputs,"Result","value","false");
     744              OGRFeature::DestroyFeature( poFeature );
     745              delete ipoDS;
     746              return SERVICE_SUCCEEDED;
     747            }
     748          }
     749          OGRFeature::DestroyFeature( poFeature );
     750        }
     751
     752      }
     753
     754    delete ipoDS;
     755    setMapInMaps(outputs,"Result","value","true");
     756
     757    OGRCleanupAll();
     758    return SERVICE_SUCCEEDED;
     759  }
     760
     761#ifdef WIN32
     762  __declspec(dllexport)
     763#endif
     764  int IsSimple(maps*& conf,maps*& inputs,maps*& outputs){
     765    return applyOneBool(conf,inputs,outputs,&OGRGeometry::IsSimple);
     766  }
     767
     768#ifdef WIN32
     769  __declspec(dllexport)
     770#endif
     771  int IsClosed(maps*& conf,maps*& inputs,maps*& outputs){
     772    return applyOneBool(conf,inputs,outputs,&OGRGeometry::IsRing);
     773  }
     774
     775#ifdef WIN32
     776  __declspec(dllexport)
     777#endif
     778  int IsValid(maps*& conf,maps*& inputs,maps*& outputs){
     779    return applyOneBool(conf,inputs,outputs,&OGRGeometry::IsValid);
     780  }
     781
     782 
     783  int applyTwo(maps*& conf,maps*& inputs,maps*& outputs,OGRGeometry* (OGRGeometry::*myFunc)(const OGRGeometry*) const){
    262784#ifdef DEBUG
    263     dumpMaps(outputs);
    264     fprintf(stderr,"\nService internal print\n===\n");
    265 #endif
    266     OGR_G_DestroyGeometry(res);
    267     OGR_G_DestroyGeometry(geometry);
    268     //CPLFree(res);
    269     //CPLFree(geometry);
     785    fprintf(stderr,"\nService internal print\n");
     786#endif
     787    OGRRegisterAll();
     788
     789    maps* cursor=inputs;
     790    OGRGeometryH geometry,res;
     791    OGRLayer *poDstLayer;
     792    //const char *oDriver1;
     793    OGRDataSource       *poODS;
    270794#ifdef DEBUG
    271     fprintf(stderr,"Service internal print \n");
    272     dumpMaps(outputs);
    273     fprintf(stderr,"/Service internal print \n");
    274 #endif
     795    dumpMaps(cursor);
     796#endif
     797
     798    char *filename=(char*)malloc(1024*sizeof(char));
     799    const char *oDriver1;
     800    OGRDataSource* ipoDS1 = loadEntity(conf,inputs,&filename,&oDriver1,"InputEntity1",1);
     801
     802    char *filename1=(char*)malloc(1024*sizeof(char));
     803    const char *oDriver2;
     804    OGRDataSource* ipoDS2 = loadEntity(conf,inputs,&filename1,&oDriver2,"InputEntity2",2);
     805    const char *oDriver3;
     806    char pszDestDataSource[100];
     807    if( ipoDS1 == NULL || ipoDS2 == NULL )
     808      {
     809        OGRSFDriverRegistrar    *poR = OGRSFDriverRegistrar::GetRegistrar();
     810       
     811        fprintf( stderr, "FAILURE:\n"
     812                 "Unable to open datasource `%s' with the following drivers.\n",
     813                 filename );
     814       
     815        for( int iDriver = 0; iDriver < poR->GetDriverCount(); iDriver++ )
     816          {
     817            fprintf( stderr, "  -> %s\n", poR->GetDriver(iDriver)->GetName() );
     818          }
     819        char tmp[1024];
     820        if( ipoDS1 == NULL )
     821          sprintf(tmp,"Unable to open datasource `%s' with the following drivers.",filename);
     822        if( ipoDS2 == NULL )
     823          sprintf(tmp,"Unable to open datasource `%s' with the following drivers.",filename1);
     824        setMapInMaps(conf,"lenv","message",tmp);
     825        return SERVICE_FAILED;
     826      }
     827    for( int iLayer = 0; iLayer < ipoDS1->GetLayerCount();
     828         iLayer++ )
     829      {
     830        OGRLayer        *poLayer1 = ipoDS1->GetLayer(iLayer);
     831       
     832        if( poLayer1 == NULL )
     833          {
     834            fprintf( stderr, "FAILURE: Couldn't fetch advertised layer %d!\n",
     835                     iLayer );
     836            char tmp[1024];
     837            sprintf(tmp,"Couldn't fetch advertised layer %d!",iLayer);
     838            setMapInMaps(conf,"lenv","message",tmp);
     839            return SERVICE_FAILED;
     840          }
     841
     842        for( int iLayer1 = 0; iLayer1 < ipoDS2->GetLayerCount();
     843             iLayer1++ )
     844          {
     845            OGRLayer        *poLayer2 = ipoDS2->GetLayer(iLayer1);
     846           
     847            if( poLayer1 == NULL )
     848              {
     849                fprintf( stderr, "FAILURE: Couldn't fetch advertised layer %d!\n",
     850                         iLayer1 );
     851                char tmp[1024];
     852                sprintf(tmp,"Couldn't fetch advertised layer %d!",iLayer1);
     853                setMapInMaps(conf,"lenv","message",tmp);
     854                return SERVICE_FAILED;
     855              }
     856       
     857            OGRFeature  *poFeature1,*poFeature2;
     858
     859            /* -------------------------------------------------------------------- */
     860            /*      Try opening the output datasource as an existing, writable      */
     861            /* -------------------------------------------------------------------- */
     862           
     863            OGRSFDriverRegistrar *poR = OGRSFDriverRegistrar::GetRegistrar();
     864            OGRSFDriver          *poDriver = NULL;
     865            int                  iDriver;
     866           
     867            map* tmpMap=getMapFromMaps(outputs,"Result","mimeType");
     868            oDriver3="GeoJSON";
     869            sprintf(pszDestDataSource,"/vsimem/result_%d.json",getpid());
     870            if(tmpMap!=NULL){
     871              if(strcmp(tmpMap->value,"text/xml")==0){
     872                sprintf(pszDestDataSource,"/vsimem/result_%d.xml",getpid());
     873                oDriver3="GML";
     874              }
     875            }
     876           
     877            for( iDriver = 0;
     878                 iDriver < poR->GetDriverCount() && poDriver == NULL;
     879                 iDriver++ )
     880              {
     881#ifdef DEBUG
     882                fprintf(stderr,"D:%s\n",poR->GetDriver(iDriver)->GetName());
     883#endif
     884                if( EQUAL(poR->GetDriver(iDriver)->GetName(),oDriver3) )
     885                  {
     886                    poDriver = poR->GetDriver(iDriver);
     887                  }
     888              }
     889           
     890            if( poDriver == NULL )
     891              {
     892                char emessage[8192];
     893                sprintf( emessage, "Unable to find driver `%s'.\n", oDriver1 );
     894                sprintf( emessage,  "%sThe following drivers are available:\n",emessage );
     895               
     896                for( iDriver = 0; iDriver < poR->GetDriverCount(); iDriver++ )
     897                  {
     898                    sprintf( emessage,  "%s  -> `%s'\n", emessage, poR->GetDriver(iDriver)->GetName() );
     899                  }
     900               
     901                setMapInMaps(conf,"lenv","message",emessage);
     902                return SERVICE_FAILED;
     903               
     904              }
     905           
     906            if( !poDriver->TestCapability( ODrCCreateDataSource ) ){
     907              char emessage[1024];
     908              sprintf( emessage,  "%s driver does not support data source creation.\n",
     909                       "json" );
     910              setMapInMaps(conf,"lenv","message",emessage);
     911              return SERVICE_FAILED;
     912            }
     913           
     914            /* -------------------------------------------------------------------- */
     915            /*      Create the output data source.                                  */
     916            /* -------------------------------------------------------------------- */
     917            //map* tpath=getMapFromMaps(conf,"main","tmpPath");
     918            char **papszDSCO=NULL;
     919            poODS = poDriver->CreateDataSource( pszDestDataSource, papszDSCO );
     920            if( poODS == NULL ){
     921              char emessage[1024];     
     922              sprintf( emessage,  "%s driver failed to create %s\n",
     923                       "json", pszDestDataSource );
     924              setMapInMaps(conf,"lenv","message",emessage);
     925              return SERVICE_FAILED;
     926            }
     927           
     928            /* -------------------------------------------------------------------- */
     929            /*      Create the layer.                                               */
     930            /* -------------------------------------------------------------------- */
     931            if( !poODS->TestCapability( ODsCCreateLayer ) )
     932              {
     933                char emessage[1024];
     934                sprintf( emessage,
     935                         "Layer %s not found, and CreateLayer not supported by driver.",
     936                         "Result" );
     937                setMapInMaps(conf,"lenv","message",emessage);
     938                return SERVICE_FAILED;
     939              }
     940           
     941            //CPLErrorReset();
     942           
     943            poDstLayer = poODS->CreateLayer( "Result", NULL,wkbUnknown,NULL);
     944            if( poDstLayer == NULL ){
     945              setMapInMaps(conf,"lenv","message","Layer creation failed.\n");
     946              return SERVICE_FAILED;
     947            }
     948           
     949            OGRFeatureDefn *poFDefn = poLayer1->GetLayerDefn();
     950            int iField;
     951            int hasMmField=0;
     952           
     953            for( iField = 0; iField < poFDefn->GetFieldCount(); iField++ )
     954              {
     955                OGRFieldDefn *tmp=poFDefn->GetFieldDefn(iField);
     956                if (iField >= 0)
     957                  poDstLayer->CreateField( poFDefn->GetFieldDefn(iField) );
     958                else
     959                  {
     960                    fprintf( stderr, "Field '%s' not found in source layer.\n",
     961                             iField );
     962                    return SERVICE_FAILED;
     963                  }
     964              }
     965           
     966            while(TRUE){
     967              OGRFeature      *poDstFeature = NULL;
     968              poFeature1 = poLayer1->GetNextFeature();
     969              if( poFeature1 == NULL )
     970                break;
     971              while(TRUE){
     972                poFeature2 = poLayer2->GetNextFeature();
     973                if( poFeature2 == NULL )
     974                  break;
     975
     976                if(poFeature1->GetGeometryRef() != NULL && poFeature2->GetGeometryRef() != NULL){
     977                  // DO SOMETHING HERE !!
     978                  poDstFeature = OGRFeature::CreateFeature( poDstLayer->GetLayerDefn() );
     979                  if( poDstFeature->SetFrom( poFeature2, TRUE ) != OGRERR_NONE )
     980                    {
     981                      char tmpMsg[1024];
     982                      sprintf( tmpMsg,"Unable to translate feature %ld from layer %s.\n",
     983                               poFeature2->GetFID(), poFDefn->GetName() );
     984                     
     985                      OGRFeature::DestroyFeature( poFeature1 );
     986                      OGRFeature::DestroyFeature( poFeature2 );
     987                      OGRFeature::DestroyFeature( poDstFeature );
     988                      return SERVICE_FAILED;
     989                    }
     990                  if(poDstFeature->SetGeometryDirectly((poFeature1->GetGeometryRef()->*myFunc)(poFeature2->GetGeometryRef())) != OGRERR_NONE )
     991                    {
     992                      char tmpMsg[1024];
     993                      sprintf( tmpMsg,"Unable to translate feature %ld from layer %s.\n",
     994                               poFeature2->GetFID(), poFDefn->GetName() );
     995                     
     996                      OGRFeature::DestroyFeature( poFeature1 );
     997                      OGRFeature::DestroyFeature( poFeature2 );
     998                      OGRFeature::DestroyFeature( poDstFeature );
     999                      return SERVICE_FAILED;
     1000                    }
     1001                  OGRFeature::DestroyFeature( poFeature1 );
     1002                  OGRFeature::DestroyFeature( poFeature2 );
     1003                  if(!poDstFeature->GetGeometryRef()->IsEmpty())
     1004                    if( poDstLayer->CreateFeature( poDstFeature ) != OGRERR_NONE )
     1005                      {         
     1006                        OGRFeature::DestroyFeature( poDstFeature );
     1007                        return SERVICE_FAILED;
     1008                      }
     1009                  OGRFeature::DestroyFeature( poDstFeature );
     1010                }
     1011              }
     1012            }
     1013          }
     1014      }
     1015
     1016    delete poODS;
     1017    delete ipoDS1;
     1018    delete ipoDS2;
     1019    free(filename);
     1020    free(filename1);
     1021
     1022    char *res1=readVSIFile(conf,pszDestDataSource);
     1023    if(res1==NULL)
     1024      return SERVICE_FAILED;
     1025    setMapInMaps(outputs,"Result","value",res1);
     1026    free(res1);
     1027    OGRCleanupAll();
    2751028    return SERVICE_SUCCEEDED;
    2761029  }
    277 
    278 #ifdef WIN32
    279   __declspec(dllexport)
    280 #endif
    281 int Buffer(maps*& conf,maps*& inputs,maps*& outputs){
    282    OGRGeometryH geometry,res;
    283    map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
    284    if(tmp==NULL){
    285      setMapInMaps(conf,"lenv","message",_ss("Unable to fetch input geometry"));
    286      return SERVICE_FAILED;
    287    }else
    288      if(strlen(tmp->value)<=0){
    289        setMapInMaps(conf,"lenv","message",_ss("Unable to fetch input geometry"));
    290        return SERVICE_FAILED;
    291      }
    292    map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType");
    293    if(strncmp(tmp1->value,"application/json",16)==0)
    294      geometry=OGR_G_CreateGeometryFromJson(tmp->value);
    295    else
    296      geometry=createGeometryFromGML(conf,tmp->value);
    297    if(geometry==NULL){
    298      setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry"));
    299      return SERVICE_FAILED;
    300    }
    301    double bufferDistance;
    302    tmp=getMapFromMaps(inputs,"BufferDistance","value");
    303    if(tmp==NULL){
    304      bufferDistance=atof("10.0");
    305    }
    306    else
    307      bufferDistance=atof(tmp->value);
    308    res=OGR_G_Buffer(geometry,bufferDistance,30);
    309    dumpMap(tmp);
    310    tmp1=getMapFromMaps(outputs,"Result","mimeType");
    311    dumpMap(tmp);
    312    if(strncmp(tmp1->value,"application/json",16)==0){
    313      char *tmpS=OGR_G_ExportToJson(res);
    314      setMapInMaps(outputs,"Result","value",tmpS);
    315      dumpMap(tmp);
    316 #ifndef WIN32
    317      setMapInMaps(outputs,"Result","mimeType","text/plain");
    318      setMapInMaps(outputs,"Result","encoding","UTF-8");
    319      free(tmpS);
    320 #endif
    321    }
    322    else{
    323      char *tmpS=OGR_G_ExportToGML(res);
    324      setMapInMaps(outputs,"Result","value",tmpS);
    325      dumpMap(tmp);
    326 #ifndef WIN32
    327      free(tmpS);
    328      setMapInMaps(outputs,"Result","mimeType","text/xml");
    329      setMapInMaps(outputs,"Result","encoding","UTF-8");
    330      setMapInMaps(outputs,"Result","schema","http://fooa/gml/3.1.0/polygon.xsd");
    331 #endif
    332    }
    333    //outputs->next=NULL;
    334    OGR_G_DestroyGeometry(geometry);
    335    OGR_G_DestroyGeometry(res);
    336    return SERVICE_SUCCEEDED;
    337 }
    338 
    339 #ifdef WIN32
    340   __declspec(dllexport)
    341 #endif
    342   int Boundary(maps*& conf,maps*& inputs,maps*& outputs){
    343     return applyOne(conf,inputs,outputs,&OGR_G_GetBoundary,"http://fooa/gml/3.1.0/polygon.xsd");
    344   }
    345 
    346 #ifdef WIN32
    347   __declspec(dllexport)
    348 #endif
    349   int ConvexHull(maps*& conf,maps*& inputs,maps*& outputs){
    350     return applyOne(conf,inputs,outputs,&OGR_G_ConvexHull,"http://fooa/gml/3.1.0/polygon.xsd");
    351   }
    352 
    353 
    354   OGRGeometryH MY_OGR_G_Centroid(OGRGeometryH hTarget){
    355     OGRGeometryH res;
    356     res=OGR_G_CreateGeometryFromJson("{\"type\": \"Point\", \"coordinates\": [0,0] }");
    357     OGRwkbGeometryType gtype=OGR_G_GetGeometryType(hTarget);
    358     if(gtype!=wkbPolygon){
    359       hTarget=OGR_G_ConvexHull(hTarget);
    360     }
    361     int c=OGR_G_Centroid(hTarget,res);
    362     return res;
    363   }
    364 
    365 #ifdef WIN32
    366   __declspec(dllexport)
    367 #endif
    368   int Centroid(maps*& conf,maps*& inputs,maps*& outputs){
    369     return applyOne(conf,inputs,outputs,&MY_OGR_G_Centroid,"http://fooa/gml/3.1.0/point.xsd");
    370   }
    371 
    372   int applyTwo(maps*& conf,maps*& inputs,maps*& outputs,OGRGeometryH (*myFunc)(OGRGeometryH,OGRGeometryH)){
    373 #ifdef DEBUG
    374     fprintf(stderr,"\nService internal print1\n");
    375     fflush(stderr);
    376     fprintf(stderr,"\nService internal print1\n");
    377     dumpMaps(inputs);
    378     fprintf(stderr,"\nService internal print1\n");
    379 #endif
     1030 
     1031#ifdef WIN32
     1032  __declspec(dllexport)
     1033#endif
     1034  int Difference(maps*& conf,maps*& inputs,maps*& outputs){
     1035    return applyTwo(conf,inputs,outputs,&OGRGeometry::Difference);
     1036  }
     1037
     1038#ifdef WIN32
     1039  __declspec(dllexport)
     1040#endif
     1041  int SymDifference(maps*& conf,maps*& inputs,maps*& outputs){
     1042    return applyTwo(conf,inputs,outputs,&OGRGeometry::SymDifference);
     1043  }
     1044
     1045#ifdef WIN32
     1046  __declspec(dllexport)
     1047#endif
     1048  int Intersection(maps*& conf,maps*& inputs,maps*& outputs){
     1049    return applyTwo(conf,inputs,outputs,&OGRGeometry::Intersection);
     1050  }
     1051
     1052#ifdef WIN32
     1053  __declspec(dllexport)
     1054#endif
     1055  int Union(maps*& conf,maps*& inputs,maps*& outputs){
     1056    return applyTwo(conf,inputs,outputs,&OGRGeometry::Union);
     1057  }
     1058
     1059  int applyTwoBool(maps*& conf,maps*& inputs,maps*& outputs,OGRBoolean (OGRGeometry::*myFunc)(const OGRGeometry*) const){
     1060    OGRRegisterAll();
    3801061
    3811062    maps* cursor=inputs;
    382     OGRGeometryH geometry1,geometry2;
    383     OGRGeometryH res;
    384     {
    385       map* tmp=getMapFromMaps(inputs,"InputEntity1","value");
    386       map* tmp1=getMapFromMaps(inputs,"InputEntity1","mimeType");
    387       if(tmp1!=NULL){
    388         if(strncmp(tmp1->value,"application/json",16)==0)
    389           geometry1=OGR_G_CreateGeometryFromJson(tmp->value);
    390         else
    391           geometry1=createGeometryFromGML(conf,tmp->value);
    392       }
    393       else
    394         geometry1=createGeometryFromGML(conf,tmp->value);
    395     }
    396     if(geometry1==NULL){
    397       setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry for InputEntity1."));
    398 #ifdef DEBUG
    399       fprintf(stderr,"SERVICE FAILED !\n");
    400 #endif
    401       return SERVICE_FAILED;
    402     }
    403 #ifdef DEBUG
    404     fprintf(stderr,"\nService internal print1 InputEntity1\n");
    405 #endif
    406     {
    407       map* tmp=getMapFromMaps(inputs,"InputEntity2","value");
    408       map* tmp1=getMapFromMaps(inputs,"InputEntity2","mimeType");
    409 #ifdef DEBUG
    410       fprintf(stderr,"MY MAP \n[%s] - %i\n",tmp1->value,strncmp(tmp1->value,"application/json",16));
    411       //dumpMap(tmp);
    412       fprintf(stderr,"MY MAP\n");
    413       fprintf(stderr,"\nService internal print1 InputEntity2\n");
    414 #endif
    415       if(tmp1!=NULL){
    416         if(strncmp(tmp1->value,"application/json",16)==0){
    417 #ifdef DEBUG
    418           fprintf(stderr,"\nService internal print1 InputEntity2 as JSON\n");
    419 #endif
    420           geometry2=OGR_G_CreateGeometryFromJson(tmp->value);
    421         }
    422         else{
    423 #ifdef DEBUG
    424           fprintf(stderr,"\nService internal print1 InputEntity2 as GML\n");
    425 #endif
    426           geometry2=createGeometryFromGML(conf,tmp->value);
    427         }
    428       }
    429       else
    430         geometry2=createGeometryFromGML(conf,tmp->value);
    431 #ifdef DEBUG
    432       fprintf(stderr,"\nService internal print1 InputEntity2 PreFinal\n");
    433 #endif
    434     }
    435 #ifdef DEBUG
    436     fprintf(stderr,"\nService internal print1 InputEntity2 Final\n");
    437 #endif
    438     if(geometry2==NULL){
    439       setMapInMaps(conf,"lenv","message",_ss("Unable to parse input geometry for InputEntity2."));
    440 #ifdef DEBUG
    441       fprintf(stderr,"SERVICE FAILED !\n");
    442 #endif
    443       return SERVICE_FAILED;
    444     }
    445 #ifdef DEBUG
    446     fprintf(stderr,"\nService internal print1\n");
    447 #endif
    448     res=(*myFunc)(geometry1,geometry2);
    449 #ifdef DEBUG
    450     fprintf(stderr,"\nService internal print1\n");
    451 #endif   
    452     /* nuova parte */
    453     map* tmp2=getMapFromMaps(outputs,"Result","mimeType");
    454     if(strncmp(tmp2->value,"application/json",16)==0){
    455       char *tmpS=OGR_G_ExportToJson(res);
    456       setMapInMaps(outputs,"Result","value",tmpS);
    457 #ifndef WIN32
    458       setMapInMaps(outputs,"Result","mimeType","text/plain");
    459       setMapInMaps(outputs,"Result","encoding","UTF-8");
    460       free(tmpS);
    461 #endif
    462     }
    463     else{
    464       char *tmpS=OGR_G_ExportToGML(res);
    465       setMapInMaps(outputs,"Result","value",tmpS);
    466 #ifndef WIN32
    467       setMapInMaps(outputs,"Result","mimeType","text/xml");
    468       setMapInMaps(outputs,"Result","encoding","UTF-8");
    469       setMapInMaps(outputs,"Result","schema","http://fooa/gml/3.1.0/polygon.xsd");
    470       free(tmpS);
    471 #endif
    472     }
    473    
    474     /* vecchia da togliere */
    475     /*
    476     char *tmpS=OGR_G_ExportToJson(res);
    477     setMapInMaps(outputs,"Result","value",tmpS);
    478     setMapInMaps(outputs,"Result","mimeType","text/plain");
    479     setMapInMaps(outputs,"Result","encoding","UTF-8");
    480     free(tmpS);
    481     */
    482     OGR_G_DestroyGeometry(geometry1);
    483     OGR_G_DestroyGeometry(geometry2);
    484     OGR_G_DestroyGeometry(res);
     1063    OGRGeometryH geometry,res;
     1064    OGRLayer *poDstLayer;
     1065    OGRDataSource       *poODS;
     1066
     1067    char *filename=(char*)malloc(1024*sizeof(char));
     1068    const char *oDriver1;
     1069    OGRDataSource* ipoDS1 = loadEntity(conf,inputs,&filename,&oDriver1,"InputEntity1",1);
     1070
     1071    char *filename1=(char*)malloc(1024*sizeof(char));
     1072    const char *oDriver2;
     1073    OGRDataSource* ipoDS2 = loadEntity(conf,inputs,&filename1,&oDriver2,"InputEntity2",2);
     1074    const char *oDriver3;
     1075    char pszDestDataSource[100];
     1076    if( ipoDS1 == NULL || ipoDS2 == NULL )
     1077      {
     1078        OGRSFDriverRegistrar    *poR = OGRSFDriverRegistrar::GetRegistrar();
     1079       
     1080        fprintf( stderr, "FAILURE:\n"
     1081                 "Unable to open datasource `%s' with the following drivers.\n",
     1082                 filename );
     1083       
     1084        for( int iDriver = 0; iDriver < poR->GetDriverCount(); iDriver++ )
     1085          {
     1086            fprintf( stderr, "  -> %s\n", poR->GetDriver(iDriver)->GetName() );
     1087          }
     1088        char tmp[1024];
     1089        if( ipoDS1 == NULL )
     1090          sprintf(tmp,"Unable to open datasource `%s' with the following drivers.",filename);
     1091        if( ipoDS2 == NULL )
     1092          sprintf(tmp,"Unable to open datasource `%s' with the following drivers.",filename1);
     1093        setMapInMaps(conf,"lenv","message",tmp);
     1094        return SERVICE_FAILED;
     1095      }
     1096    for( int iLayer = 0; iLayer < ipoDS1->GetLayerCount();
     1097         iLayer++ )
     1098      {
     1099        OGRLayer        *poLayer1 = ipoDS1->GetLayer(iLayer);
     1100       
     1101        if( poLayer1 == NULL )
     1102          {
     1103            fprintf( stderr, "FAILURE: Couldn't fetch advertised layer %d!\n",
     1104                     iLayer );
     1105            char tmp[1024];
     1106            sprintf(tmp,"Couldn't fetch advertised layer %d!",iLayer);
     1107            setMapInMaps(conf,"lenv","message",tmp);
     1108            return SERVICE_FAILED;
     1109          }
     1110
     1111        for( int iLayer1 = 0; iLayer1 < ipoDS2->GetLayerCount();
     1112             iLayer1++ )
     1113          {
     1114            OGRLayer        *poLayer2 = ipoDS2->GetLayer(iLayer1);
     1115           
     1116            if( poLayer1 == NULL )
     1117              {
     1118                fprintf( stderr, "FAILURE: Couldn't fetch advertised layer %d!\n",
     1119                         iLayer1 );
     1120                char tmp[1024];
     1121                sprintf(tmp,"Couldn't fetch advertised layer %d!",iLayer1);
     1122                setMapInMaps(conf,"lenv","message",tmp);
     1123                return SERVICE_FAILED;
     1124              }
     1125       
     1126            OGRFeature  *poFeature1,*poFeature2;
     1127
     1128
     1129            while(TRUE){
     1130              OGRFeature      *poDstFeature = NULL;
     1131              poFeature1 = poLayer1->GetNextFeature();
     1132              if( poFeature1 == NULL )
     1133                break;
     1134              while(TRUE){
     1135                poFeature2 = poLayer2->GetNextFeature();
     1136                if( poFeature2 == NULL )
     1137                  break;
     1138                if(poFeature1->GetGeometryRef() != NULL && poFeature2->GetGeometryRef() != NULL){
     1139                  // DO SOMETHING HERE !!
     1140                  if((poFeature1->GetGeometryRef()->*myFunc)(poFeature2->GetGeometryRef())==0){
     1141                    setMapInMaps(outputs,"Result","value","false");
     1142                    OGRFeature::DestroyFeature( poFeature1 );
     1143                    OGRFeature::DestroyFeature( poFeature2 );
     1144                    delete ipoDS1;
     1145                    delete ipoDS2;
     1146                    free(filename);
     1147                    free(filename1);
     1148                    return SERVICE_SUCCEEDED;
     1149                  }
     1150                }
     1151                OGRFeature::DestroyFeature( poFeature2 );
     1152              }
     1153              OGRFeature::DestroyFeature( poFeature1 );
     1154            }
     1155          }
     1156      }
     1157
     1158    delete ipoDS1;
     1159    delete ipoDS2;
     1160    free(filename);
     1161    free(filename1);
     1162
     1163    setMapInMaps(outputs,"Result","value","true");
     1164
     1165    OGRCleanupAll();
    4851166    return SERVICE_SUCCEEDED;
    4861167  }
    487  
    488 #ifdef WIN32
    489   __declspec(dllexport)
    490 #endif
    491   int Difference(maps*& conf,maps*& inputs,maps*& outputs){
    492     return applyTwo(conf,inputs,outputs,&OGR_G_Difference);
    493   }
    494 
    495 #ifdef WIN32
    496   __declspec(dllexport)
    497 #endif
    498   int SymDifference(maps*& conf,maps*& inputs,maps*& outputs){
    499     return applyTwo(conf,inputs,outputs,&OGR_G_SymmetricDifference);
    500   }
    501 
    502 #ifdef WIN32
    503   __declspec(dllexport)
    504 #endif
    505   int Intersection(maps*& conf,maps*& inputs,maps*& outputs){
    506     return applyTwo(conf,inputs,outputs,&OGR_G_Intersection);
    507   }
    508 
    509 #ifdef WIN32
    510   __declspec(dllexport)
    511 #endif
    512   int Union(maps*& conf,maps*& inputs,maps*& outputs){
    513     return applyTwo(conf,inputs,outputs,&OGR_G_Union);
     1168
     1169
     1170#ifdef WIN32
     1171  __declspec(dllexport)
     1172#endif
     1173  int Equals(maps*& conf,maps*& inputs,maps*& outputs){
     1174    return applyTwoBool(conf,inputs,outputs,(OGRBoolean (OGRGeometry::*)(const OGRGeometry *) const)&OGRGeometry::Equals);
     1175  }
     1176
     1177#ifdef WIN32
     1178  __declspec(dllexport)
     1179#endif
     1180  int Disjoint(maps*& conf,maps*& inputs,maps*& outputs){
     1181    return applyTwoBool(conf,inputs,outputs,&OGRGeometry::Disjoint);
     1182  }
     1183
     1184#ifdef WIN32
     1185  __declspec(dllexport)
     1186#endif
     1187  int Touches(maps*& conf,maps*& inputs,maps*& outputs){
     1188    return applyTwoBool(conf,inputs,outputs,&OGRGeometry::Touches);
     1189  }
     1190
     1191#ifdef WIN32
     1192  __declspec(dllexport)
     1193#endif
     1194  int Crosses(maps*& conf,maps*& inputs,maps*& outputs){
     1195    return applyTwoBool(conf,inputs,outputs,&OGRGeometry::Crosses);
     1196  }
     1197
     1198#ifdef WIN32
     1199  __declspec(dllexport)
     1200#endif
     1201  int Within(maps*& conf,maps*& inputs,maps*& outputs){
     1202    return applyTwoBool(conf,inputs,outputs,&OGRGeometry::Within);
     1203  }
     1204
     1205#ifdef WIN32
     1206  __declspec(dllexport)
     1207#endif
     1208  int Contains(maps*& conf,maps*& inputs,maps*& outputs){
     1209    return applyTwoBool(conf,inputs,outputs,&OGRGeometry::Contains);
     1210  }
     1211
     1212#ifdef WIN32
     1213  __declspec(dllexport)
     1214#endif
     1215  int Overlaps(maps*& conf,maps*& inputs,maps*& outputs){
     1216    return applyTwoBool(conf,inputs,outputs,&OGRGeometry::Overlaps);
     1217  }
     1218
     1219#ifdef WIN32
     1220  __declspec(dllexport)
     1221#endif
     1222  int Intersects(maps*& conf,maps*& inputs,maps*& outputs){
     1223    return applyTwoBool(conf,inputs,outputs,(OGRBoolean (OGRGeometry::*)(const OGRGeometry *) const)&OGRGeometry::Intersects);
    5141224  }
    5151225
     
    6051315    }
    6061316    fprintf(stderr,"geometry created %s \n",tmp->value);
    607     res=OGR_G_GetArea(geometry);
     1317    res=OGR_G_Area(geometry);
    6081318    fprintf(stderr,"area %d \n",res);
    6091319    /**
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