Changes between Version 25 and Version 26 of ZooWorkshop/FOSS4GJapan/CreatingOGRBasedWebServices
- Timestamp:
- Oct 16, 2010, 12:00:23 AM (14 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ZooWorkshop/FOSS4GJapan/CreatingOGRBasedWebServices
v25 v26 161 161 ==== C Version ==== 162 162 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.hfile :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 : 166 166 167 167 {{{ … … 174 174 }}} 175 175 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 elementin the list. Here is the datatype definition you can find in the {{{zoo-kernel/service.h}}} file :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 {{{map}}} in the list. Here is the datatype definition you can find in the {{{zoo-kernel/service.h}}} file : 177 177 178 178 {{{ … … 185 185 }}} 186 186 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.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. 188 188 189 189 This function takes three parameters listed bellow : … … 193 193 * {{{key}}} : a specific key in the map named name 194 194 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 :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 : 196 196 197 197 {{{ … … 223 223 }}} 224 224 225 Please note that the {{{addToMap}}} function is able to create or update an existing map. Indeed, if a mapcalled « value » allready exists, then its value will be updated automatically.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. 226 226 227 227 This 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. 228 228 229 Here is an example of a maps used in Python language (this is a summarized version of the main configaration maps) :229 Here is an example of a {{{maps}}} used in Python language (this is a summarized version of the main configaration {{{maps}}}) : 230 230 231 231 {{{ … … 323 323 tmp1=getMapFromMaps(outputs,"Result","mimeType"); 324 324 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); 327 329 } 328 330 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); 330 334 } 331 335 outputs->next=NULL; … … 347 351 }}} 348 352 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 createGeometryFromGMLlocal 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_CreateGeometryFromJsonit 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).353 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. 354 355 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). 352 356 353 357 Once 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. … … 359 363 tmp1=getMapFromMaps(outputs,"Result","mimeType"); 360 364 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); 363 369 } 364 370 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); 366 374 } 367 375 }}} … … 434 442 }}} 435 443 436 You should now understand more clearly the meannings of the ZOO Service Provider source tree ! The {{{cgi- 444 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. 437 445 438 446 Please 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 :