Changes between Version 25 and Version 26 of ZooWorkshop/FOSS4GJapan/CreatingOGRBasedWebServices


Ignore:
Timestamp:
Oct 16, 2010, 12:00:23 AM (9 years ago)
Author:
djay
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ZooWorkshop/FOSS4GJapan/CreatingOGRBasedWebServices

    v25 v26  
    161161==== C Version ====
    162162
    163 As explained before, ZOO Kernel will pass the parameters to your Service function in a specific datatype called maps. In order to code your Service in C language, you also need to learn how to access this datatype in read/write mode.
    164 
    165 The maps are simple map named linked list containing a name, a content map and a pointer to the next map in the list (or {{{NULL}}} if there is no more map in the list). Here is the datatype definition as you can find in the zoo-kernel/service.h file :
     163As explained before, ZOO Kernel will pass the parameters to your Service function in a specific datatype called {{{maps}}}. In order to code your Service in C language, you also need to learn how to access this datatype in read/write mode.
     164
     165The {{{maps}}} are simple {{{map}}} named linked list containing a {{{name}}}, a {{{content}}} {{{map}}} and a pointer to the next {{{map}}} in the list (or {{{NULL}}} if there is no more {{{map}}} in the list). Here is the datatype definition as you can find in the {{{zoo-kernel/service.h}}} file :
    166166
    167167{{{
     
    174174}}}
    175175
    176 The map included in the maps is also a simple linked list and is used to store Key Value Pair values. A map is thus a couple of name and value and a pointer to the next element in the list. Here is the datatype definition you can find in the {{{zoo-kernel/service.h}}} file :
     176The {{{map}}} included in the {{{maps}}} is also a simple linked list and is used to store Key Value Pair values. A {{{map}}} is thus a couple of {{{name}}} and {{{value}}} and a pointer to the next {{{map}}} in the list. Here is the datatype definition you can find in the {{{zoo-kernel/service.h}}} file :
    177177
    178178{{{
     
    185185}}}
    186186
    187 As partially or fully filled datastructures will be passed by the ZOO Kernel to your Services, this means that you do not need to deal with maps creation but directly with existing map, in other words the content of each maps. The first function you need to know is {{{getMapFromMaps}}} (defined in the {{{zoo-kernel/service.h}}} file) which let you access to a specific map of a maps.
     187As partially or fully filled datastructures will be passed by the ZOO Kernel to your Services, this means that you do not need to deal with maps creation but directly with existing {{{map}}}, in other words the content of each {{{maps}}}. The first function you need to know is {{{getMapFromMaps}}} (defined in the {{{zoo-kernel/service.h}}} file) which let you access to a specific map of a maps.
    188188
    189189This function takes three parameters listed bellow :
     
    193193 * {{{key}}} : a specific key in the map named name
    194194
    195 For example, the following syntax will be used to access the InputPolygon value map of a maps named inputs, your C code should be :
     195For example, the following syntax will be used to access the InputPolygon value map of a {{{maps}}} named {{{inputs}}}, your C code should be :
    196196
    197197{{{
     
    223223}}}
    224224
    225 Please note that the {{{addToMap}}} function is able to create or update an existing map. Indeed, if a map called « value » allready exists, then its value will be updated automatically.
     225Please note that the {{{addToMap}}} function is able to create or update an existing {{{map}}}. Indeed, if a {{{map}}} called « value » allready exists, then its value will be updated automatically.
    226226
    227227This datatype is really important cause it is used in every C based ZOO Services. It is also the same representation used in other languages but using their respectives datatypes. For Example in Python, the dictionaries datatype is used, so manipulation is much easier.
    228228
    229 Here is an example of a maps used in Python language (this is a summarized version of the main configaration maps) :
     229Here is an example of a {{{maps}}} used in Python language (this is a summarized version of the main configaration {{{maps}}}) :
    230230
    231231{{{
     
    323323  tmp1=getMapFromMaps(outputs,"Result","mimeType");
    324324  if(strncmp(tmp1->value,"application/json",16)==0){
    325     addToMap(outputs->content,"value",OGR_G_ExportToJson(res));
    326     addToMap(outputs->content,"mimeType","text/plain");
     325    char *tmp=OGR_G_ExportToJson(res);
     326    setMapInMaps(outputs,"Result","value",tmp);
     327    setMapInMaps(outputs,"Result","mimeType","text/plain");
     328    free(tmp);
    327329  }
    328330  else{
    329     addToMap(outputs->content,"value",OGR_G_ExportToGML(res));
     331    char *tmp=OGR_G_ExportToGML(res);
     332    setMapInMaps(outputs,"Result","value",tmp);
     333    free(tmp);
    330334  }
    331335  outputs->next=NULL;
     
    347351}}}
    348352
    349 Basicaly, if we get an input with a {{{mimeType}}} set to {{{application/json}}}, then we will use our OGR_G_CreateGeometryFromJson in other case, our createGeometryFromGML local function.
    350 
    351 Please note that in some sense the data inputs are not really of the same kind. Indeed as we used directly OGR_G_CreateGeometryFromJson it means that the JSON string include only the geometry object and not the full GeoJSON string. Nevertheless, you can easily change this code to be able to use a full GeoJSON string, simply by creating a function which will extract the geometry object from the GeoJSON string (using the json-c library for instance, which is also used by the OGR GeoJSON Driver).
     353Basicaly, if we get an input with a {{{mimeType}}} set to {{{application/json}}}, then we will use our {{{OGR_G_CreateGeometryFromJson}}} in other case, our {{{createGeometryFromGML}}} local function.
     354
     355Please note that in some sense the data inputs are not really of the same kind. Indeed as we used directly {{{OGR_G_CreateGeometryFromJson}}} it means that the JSON string include only the geometry object and not the full GeoJSON string. Nevertheless, you can easily change this code to be able to use a full GeoJSON string, simply by creating a function which will extract the geometry object from the GeoJSON string (using the json-c library for instance, which is also used by the OGR GeoJSON Driver).
    352356
    353357Once you can access the input geometry object, you can use the [http://www.gdal.org/ogr/ogr__api_8h.html#a797af4266c02846d52b9cf3207ef958 OGR_G_GetBoundary] function and store the result in the res geometry variable. Then, you only have to store the value in the right format : GeoJSON per default or GML as we declared it as a supported output format.
     
    359363  tmp1=getMapFromMaps(outputs,"Result","mimeType");
    360364  if(strncmp(tmp1->value,"application/json",16)==0){
    361     addToMap(outputs->content,"value",OGR_G_ExportToJson(res));
    362     addToMap(outputs->content,"mimeType","text/plain");
     365    char *tmp=OGR_G_ExportToJson(res);
     366    setMapInMaps(outputs,"Result","value",tmp);
     367    setMapInMaps(outputs,"Result","mimeType","text/plain");
     368    free(tmp);
    363369  }
    364370  else{
    365     addToMap(outputs->content,"value",OGR_G_ExportToGML(res));
     371    char *tmp=OGR_G_ExportToGML(res);
     372    setMapInMaps(outputs,"Result","value",tmp);
     373    free(tmp);
    366374  }
    367375}}}
     
    434442}}}
    435443
    436 You should now understand more clearly the meannings of the ZOO Service Provider source tree ! The {{{cgi- env}}} directory will let you deploy your new Services or Services Provider in an easy way , simply by copying the whole {{{cgi-env}}} content in your {{{cgi-bin}}} directory.
     444You should now understand more clearly the meannings of the ZOO Service Provider source tree ! The {{{cgi-env}}} directory will let you deploy your new Services or Services Provider in an easy way , simply by copying the whole {{{cgi-env}}} content in your {{{cgi-bin}}} directory.
    437445
    438446Please note that you can add the following lines to your {{{Makefile}}} to be able to type make install directly and to get your new Services Provider available for use from ZOO Kernel :

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