Changeset 9 for trunk/zoo-services/ogr
- Timestamp:
- Sep 14, 2010, 2:04:55 PM (14 years ago)
- Location:
- trunk/zoo-services/ogr
- Files:
-
- 11 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-services/ogr/base-vect-ops/Makefile
r1 r9 1 CFLAGS=-I../../ zoo-kernel/ -I./ `xml2-config --cflags` `python-config --cflags` `gdal-config --cflags` -DLINUX_FREE_ISSUE #-DDEBUG1 CFLAGS=-I../../../zoo-kernel/ -I./ `xml2-config --cflags` `python-config --cflags` `gdal-config --cflags` -DLINUX_FREE_ISSUE #-DDEBUG 2 2 CC=gcc 3 3 4 4 cgi-env/service.zo: service.c 5 g++ ${CFLAGS} -shared -fpic -o cgi-env/ogr_service.zo ./service.c `gdal-config --libs`5 g++ ${CFLAGS} -shared -fpic -o cgi-env/ogr_service.zo ./service.c ../../../zoo-kernel/service_internal.o `gdal-config --libs` 6 6 7 7 clean: -
trunk/zoo-services/ogr/base-vect-ops/cgi-env/Boundary.zcfg
r1 r9 8 8 serviceType = C 9 9 <MetaData> 10 Test= Demo10 title = Demo 11 11 </MetaData> 12 12 <DataInputs> 13 13 [InputPolygon] 14 Title = Polygon to be buffered14 Title = Polygon to compute boundary 15 15 Abstract = URI to a set of GML that describes the polygon. 16 16 minOccurs = 1 17 17 maxOccurs = 1 18 18 <MetaData lang="en"> 19 Test= Mon test19 title = Mon test 20 20 </MetaData> 21 21 <ComplexData> 22 22 <Default> 23 mimeType = text/ js23 mimeType = text/xml 24 24 encoding = UTF-8 25 schema = http://fooa/gml/3.1.0/polygon.xsd 25 26 </Default> 26 27 <Supported> … … 30 31 </Supported> 31 32 </ComplexData> 32 [BufferDistance]33 Title = Buffer Distance34 Abstract = Distance to be used to calculate buffer.35 minOccurs = 036 maxOccurs = 137 <LiteralData>38 DataType = float39 <Default>40 uom = meters41 </Default>42 <Supported>43 uom = feet44 </Supported>45 </LiteralData>46 33 </DataInputs> 47 34 <DataOutputs> 48 [ Boundary]35 [Result] 49 36 Title = The geometry created 50 37 Abstract = The geometry containing the boundary of the geometry on which the method is invoked. 51 38 <MetaData lang="en"> 52 Test1= Mon test39 title = Mon test 53 40 </MetaData> 54 41 <ComplexData> 55 42 <Default> 56 mimeType = text/xml43 mimeType = application/json 57 44 encoding = UTF-8 58 schema = http://fooa/gml/3.1.0/polygon.xsd45 extension = js 59 46 asReference = true 60 47 </Default> 61 48 <Supported> 62 49 mimeType = text/xml 50 encoding = UTF-8 51 schema = http://fooa/gml/3.1.0/polygon.xsd 52 extension = xml 53 </Supported> 54 <Supported> 55 mimeType = text/xml 63 56 encoding = base64 64 57 schema = http://fooa/gml/3.1.0/polygon.xsd 65 </Supported> 66 <Supported> 67 mimeType = text/js 68 encoding = UTF-8 58 extension = xml 69 59 </Supported> 70 60 </ComplexData> -
trunk/zoo-services/ogr/base-vect-ops/cgi-env/Buffer.zcfg
r1 r9 9 9 serviceType = C 10 10 <MetaData lang="en"> 11 Test= Demo11 title = Demo 12 12 </MetaData> 13 13 <DataInputs> … … 18 18 maxOccurs = 1 19 19 <MetaData lang="en"> 20 Test= Mon test20 title = Mon test 21 21 </MetaData> 22 22 <ComplexData> … … 49 49 </DataInputs> 50 50 <DataOutputs> 51 [ BufferedPolygon]51 [Result] 52 52 Title = Buffered Polygon 53 53 Abstract = GML stream describing the buffered polygon feature. 54 54 <MetaData lang="en"> 55 Test1= Mon test55 title = Mon test 56 56 </MetaData> 57 57 <ComplexData> 58 58 <Default> 59 mimeType = text/xml59 mimeType = application/json 60 60 encoding = UTF-8 61 schema = http://fooa/gml/3.1.0/polygon.xsd61 extension = js 62 62 asReference = true 63 63 </Default> … … 66 66 encoding = base64 67 67 schema = http://fooa/gml/3.1.0/polygon.xsd 68 extension = xml 68 69 </Supported> 69 70 <Supported> 70 mimeType = application/json71 mimeType = text/xml 71 72 encoding = UTF-8 73 schema = http://fooa/gml/3.1.0/polygon.xsd 74 extension = xml 72 75 </Supported> 73 76 </ComplexData> -
trunk/zoo-services/ogr/base-vect-ops/cgi-env/Centroid.zcfg
r1 r9 1 1 [Centroid] 2 2 Title = Get the centroid of a polygon. 3 Abstract = C reate a buffer around a single polygon. Accepts the polygon as GML and provides GML output for the buffered feature.3 Abstract = Compute the geometry centroid. 4 4 Profile = urn:ogc:wps:1.0.0:centroid 5 5 processVersion = 2 … … 9 9 serviceType = C 10 10 <MetaData lang="en"> 11 Test= Demo11 title = Demo 12 12 </MetaData> 13 13 <DataInputs> 14 14 [InputPolygon] 15 Title = Polygon to be buffered16 Abstract = URI to a set of GML that describes the polygon.15 Title = Polygon to get the centroid 16 Abstract = The centroid which is not necessarily within the geometry. 17 17 minOccurs = 1 18 18 maxOccurs = 1 19 19 <MetaData lang="en"> 20 Test= Mon test20 title = Mon test 21 21 </MetaData> 22 22 <ComplexData> … … 34 34 </DataInputs> 35 35 <DataOutputs> 36 [ Centroid]36 [Result] 37 37 Title = The Centroid 38 38 Abstract = JSON String / GML Entity of the centroid 39 39 <MetaData lang="en"> 40 Test1= Mon test40 title = Mon test 41 41 </MetaData> 42 42 <ComplexData> 43 43 <Default> 44 mimeType = text/js44 mimeType = application/json 45 45 encoding = UTF-8 46 extension = js 47 asReference = true 46 48 </Default> 47 <Supported>48 mimeType = text/xml49 encoding = base6450 schema = http://fooa/gml/3.1.0/point.xsd51 </Supported>52 49 <Supported> 53 50 mimeType = text/xml 54 51 encoding = UTF-8 55 52 schema = http://fooa/gml/3.1.0/point.xsd 56 asReference = true53 extension = xml 57 54 </Supported> 58 55 </ComplexData> -
trunk/zoo-services/ogr/base-vect-ops/cgi-env/ConvexHull.zcfg
r1 r9 8 8 serviceType = C 9 9 <MetaData lang="en"> 10 Test= Demo10 title = Demo 11 11 </MetaData> 12 12 <DataInputs> 13 13 [InputPolygon] 14 Title = Polygon to compute are14 Title = Polygon to compute convexhull 15 15 Abstract = URI to a set of GML that describes the polygon. 16 16 minOccurs = 1 17 17 maxOccurs = 1 18 18 <MetaData lang="en"> 19 Test1= Mon test19 title = Mon test 20 20 </MetaData> 21 21 <ComplexData> … … 37 37 Abstract = The convex hull of the geometry 38 38 <MetaData lang="en"> 39 Test1= Mon test39 title = Mon test 40 40 </MetaData> 41 41 <ComplexData> 42 42 <Default> 43 mimeType = application/json 44 encoding = UTF-8 45 extension = js 46 asReference = true 47 </Default> 48 <Supported> 43 49 mimeType = text/xml 44 50 encoding = UTF-8 45 51 schema = http://fooa/gml/3.1.0/polygon.xsd 46 </Default> 47 <Supported> 48 mimeType = text/xml 49 encoding = base64 50 schema = http://fooa/gml/3.1.0/polygon.xsd 52 extension = xml 51 53 </Supported> 52 54 </ComplexData> -
trunk/zoo-services/ogr/base-vect-ops/cgi-env/Difference.zcfg
r1 r9 9 9 serviceType = C 10 10 <MetaData> 11 Test= Demo11 title = Demo 12 12 </MetaData> 13 13 <DataInputs> … … 18 18 maxOccurs = 1 19 19 <MetaData lang="en"> 20 Test= Mon test20 title = Mon test 21 21 </MetaData> 22 22 <ComplexData> … … 38 38 maxOccurs = 1 39 39 <MetaData lang="en"> 40 Test= Mon test40 title = Mon test 41 41 </MetaData> 42 42 <ComplexData> … … 54 54 </DataInputs> 55 55 <DataOutputs> 56 [ Distance]57 Title = The di stance between two geometries58 Abstract = The shortest distance between the two geometries.56 [Result] 57 Title = The difference between two geometries 58 Abstract = The difference between the two geometries. 59 59 <MetaData lang="en"> 60 Test1= Mon test60 title = Mon test 61 61 </MetaData> 62 62 <ComplexData> … … 64 64 mimeType = application/json 65 65 encoding = UTF-8 66 extension = js 66 67 </Default> 67 68 <Supported> … … 69 70 schema = http://fooa/gml/3.1.0/polygon.xsd 70 71 encoding = UTF-8 72 extension = xml 71 73 </Supported> 72 74 </ComplexData> -
trunk/zoo-services/ogr/base-vect-ops/cgi-env/Distance.zcfg
r1 r9 9 9 serviceType = C 10 10 <MetaData> 11 Test= Demo11 title = Demo 12 12 </MetaData> 13 13 <DataInputs> … … 18 18 maxOccurs = 1 19 19 <MetaData lang="en"> 20 Test= Mon test20 title = Mon test 21 21 </MetaData> 22 22 <ComplexData> … … 38 38 maxOccurs = 1 39 39 <MetaData lang="en"> 40 Test= Mon test40 title = Mon test 41 41 </MetaData> 42 42 <ComplexData> … … 58 58 Abstract = The shortest distance between the two geometries. 59 59 <MetaData lang="en"> 60 Test1= Mon test60 title = Mon test 61 61 </MetaData> 62 62 <LiteralData> -
trunk/zoo-services/ogr/base-vect-ops/cgi-env/GetArea.zcfg
r1 r9 8 8 serviceType = C 9 9 <MetaData lang="en"> 10 Test= Demo10 title = Demo 11 11 </MetaData> 12 12 <DataInputs> … … 17 17 maxOccurs = 1 18 18 <MetaData lang="en"> 19 Test1= Mon test19 title = Mon test 20 20 </MetaData> 21 21 <ComplexData> … … 37 37 Abstract = The Computed Area Value 38 38 <MetaData lang="en"> 39 Test1= Mon test39 title = Mon test 40 40 </MetaData> 41 41 <LiteralData> -
trunk/zoo-services/ogr/base-vect-ops/cgi-env/Intersection.zcfg
r1 r9 9 9 serviceType = C 10 10 <MetaData> 11 Test= Demo11 title = Demo 12 12 </MetaData> 13 13 <DataInputs> … … 18 18 maxOccurs = 1 19 19 <MetaData lang="en"> 20 Test= Mon test20 title = Mon test 21 21 </MetaData> 22 22 <ComplexData> … … 38 38 maxOccurs = 1 39 39 <MetaData lang="en"> 40 Test= Mon test40 title = Mon test 41 41 </MetaData> 42 42 <ComplexData> … … 54 54 </DataInputs> 55 55 <DataOutputs> 56 [ Distance]57 Title = The distance between twogeometries58 Abstract = The shortest distance between the two geometries.56 [Result] 57 Title = Intersection of geometries 58 Abstract = A new geometry representing the intersection or NULL if there is no intersection or an error occurs. 59 59 <MetaData lang="en"> 60 Test1= Mon test60 title = Mon test 61 61 </MetaData> 62 62 <ComplexData> … … 64 64 mimeType = application/json 65 65 encoding = UTF-8 66 extension = js 66 67 </Default> 67 68 <Supported> … … 69 70 schema = http://fooa/gml/3.1.0/polygon.xsd 70 71 encoding = UTF-8 72 extension = xml 71 73 </Supported> 72 74 </ComplexData> -
trunk/zoo-services/ogr/base-vect-ops/cgi-env/SymDifference.zcfg
r1 r9 9 9 serviceType = C 10 10 <MetaData> 11 Test= Demo11 title = Demo 12 12 </MetaData> 13 13 <DataInputs> … … 18 18 maxOccurs = 1 19 19 <MetaData lang="en"> 20 Test= Mon test20 title = Mon test 21 21 </MetaData> 22 22 <ComplexData> … … 38 38 maxOccurs = 1 39 39 <MetaData lang="en"> 40 Test= Mon test40 title = Mon test 41 41 </MetaData> 42 42 <ComplexData> … … 54 54 </DataInputs> 55 55 <DataOutputs> 56 [ Distance]57 Title = The distance between two geometries58 Abstract = The s hortest distance between the two geometries.56 [Result] 57 Title = The resulting geometry 58 Abstract = The symmetric difference of two geometries 59 59 <MetaData lang="en"> 60 Test1= Mon test60 title = Mon test 61 61 </MetaData> 62 62 <ComplexData> … … 64 64 mimeType = application/json 65 65 encoding = UTF-8 66 extension = js 66 67 </Default> 67 68 <Supported> … … 69 70 schema = http://fooa/gml/3.1.0/polygon.xsd 70 71 encoding = UTF-8 72 extension = xml 71 73 </Supported> 72 74 </ComplexData> -
trunk/zoo-services/ogr/base-vect-ops/cgi-env/Union.zcfg
r1 r9 9 9 serviceType = C 10 10 <MetaData> 11 Test= Demo11 title = Demo 12 12 </MetaData> 13 13 <DataInputs> … … 18 18 maxOccurs = 1 19 19 <MetaData lang="en"> 20 Test= Mon test20 title = Mon test 21 21 </MetaData> 22 22 <ComplexData> … … 38 38 maxOccurs = 1 39 39 <MetaData lang="en"> 40 Test= Mon test40 title = Mon test 41 41 </MetaData> 42 42 <ComplexData> … … 54 54 </DataInputs> 55 55 <DataOutputs> 56 [ Distance]57 Title = The distance betweentwo geometries58 Abstract = The shortest distance betweenthe two geometries.56 [Result] 57 Title = The union of two geometries 58 Abstract = The geometry representing the union of the two geometries. 59 59 <MetaData lang="en"> 60 Test1= Mon test60 title = Mon test 61 61 </MetaData> 62 62 <ComplexData> … … 64 64 mimeType = application/json 65 65 encoding = UTF-8 66 extension = js 66 67 </Default> 67 68 <Supported> … … 69 70 schema = http://fooa/gml/3.1.0/polygon.xsd 70 71 encoding = UTF-8 72 extension = xml 71 73 </Supported> 72 74 </ComplexData> -
trunk/zoo-services/ogr/base-vect-ops/service.c
r1 r9 23 23 */ 24 24 25 #include "cpl_ minixml.h"25 #include "cpl_conv.h" 26 26 #include "ogr_api.h" 27 #include "ogr_geometry.h" 28 #include "geos_c.h" 27 29 #include "service.h" 28 30 … … 39 41 #include <openssl/buffer.h> 40 42 41 xmlNodeSet* extractFromDoc(xmlDocPtr,char*);42 43 void printExceptionReportResponse(maps*,map*); 43 44 char *base64(const unsigned char *input, int length); … … 71 72 } 72 73 xmlDocDumpFormatMemory(ndoc, &xmlbuff, &buffersize, 1); 73 char *tmp=strdup(strstr((char*)xmlbuff,"?>")+2); 74 char *tmp=(char*)calloc((xmlStrlen(xmlStrstr(xmlbuff,BAD_CAST "?>"))-1),sizeof(char)); 75 sprintf(tmp,"%s",xmlStrstr(xmlbuff,BAD_CAST "?>")+2); 76 //strdup(strstr((char*)xmlbuff,"?>")+2); 74 77 xmlXPathFreeObject(xpathObj); 75 xmlXPathFreeContext(xpathCtx); 78 xmlXPathFreeContext(xpathCtx); 76 79 xmlFree(xmlbuff); 77 80 xmlFreeDoc(doc); 81 xmlFreeDoc(ndoc); 78 82 xmlCleanupParser(); 79 83 #ifdef DEBUG … … 81 85 #endif 82 86 OGRGeometryH res=OGR_G_CreateFromGML(tmp); 87 free(tmp); 83 88 if(res==NULL){ 84 85 86 87 89 map* tmp=createMap("text","Unable to call OGR_G_CreatFromGML"); 90 addToMap(tmp,"code","NoApplicableCode"); 91 printExceptionReportResponse(conf,tmp); 92 exit(0); 88 93 } 89 94 else 90 return OGR_G_CreateFromGML(tmp); 95 return res;//OGR_G_CreateFromGML(tmp); 96 } 97 98 int Simplify(maps*& conf,maps*& inputs,maps*& outputs){ 99 maps* cursor=inputs; 100 OGRGeometryH geometry,res; 101 double tolerance; 102 map* tmp0=getMapFromMaps(cursor,"Tolerance","value"); 103 if(tmp0==NULL){ 104 tolerance=atof("2.0"); 105 } 106 else 107 tolerance=atof(tmp0->value); 108 fprintf(stderr,"Tolerance for Simplify %f",tolerance); 109 map* tmp=getMapFromMaps(inputs,"InputPolygon","value"); 110 if(!tmp) 111 return SERVICE_FAILED; 112 map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeTime"); 113 if(tmp1!=NULL){ 114 if(strncmp(tmp1->value,"text/js",7)==0 || 115 strncmp(tmp1->value,"application/json",7)==0) 116 geometry=OGR_G_CreateGeometryFromJson(tmp->value); 117 else 118 geometry=createGeometryFromGML(conf,tmp->value); 119 } 120 else 121 geometry=createGeometryFromGML(conf,tmp->value); 122 GEOSGeometry* ggeometry=((OGRGeometry *) geometry)->exportToGEOS(); 123 GEOSGeometry* gres=GEOSTopologyPreserveSimplify(ggeometry,tolerance); 124 res=OGRGeometryFactory::createFromGEOS(gres); 125 if(tmp1!=NULL){ 126 if(strncmp(tmp1->value,"text/js",7)==0 || 127 strncmp(tmp1->value,"application/json",16)==0){ 128 outputs->content=createMap("value",OGR_G_ExportToJson(tmp->value)); 129 addMapToMap(&outputs->content,createMap("mimeType","text/plain")); 130 addMapToMap(&outputs->content,createMap("encoding","UTF-8")); 131 } 132 else{ 133 outputs->content=createMap("value",OGR_G_ExportToGML(res)); 134 addMapToMap(&outputs->content,createMap("mimeType","text/xml")); 135 addMapToMap(&outputs->content,createMap("encoding","UTF-8")); 136 addMapToMap(&outputs->content,createMap("schema","http://fooa/gml/3.1.0/polygon.xsd")); 137 } 138 }else{ 139 outputs->content=createMap("value",OGR_G_ExportToJson(res)); 140 addMapToMap(&outputs->content,createMap("mimeType","text/plain")); 141 addMapToMap(&outputs->content,createMap("encoding","UTF-8")); 142 } 143 outputs->next=NULL; 144 //GEOSFree(ggeometry); 145 //GEOSFree(gres); 146 OGR_G_DestroyGeometry(res); 147 OGR_G_DestroyGeometry(geometry); 148 return SERVICE_SUCCEEDED; 149 } 150 151 152 int applyOne(maps*& conf,maps*& inputs,maps*& outputs,OGRGeometryH (*myFunc)(OGRGeometryH)){ 153 #ifdef DEBUG 154 fprintf(stderr,"\nService internal print\n"); 155 #endif 156 maps* cursor=inputs; 157 OGRGeometryH geometry,res; 158 #ifdef DEBUG 159 dumpMaps(cursor); 160 #endif 161 map* tmp=getMapFromMaps(inputs,"InputPolygon","value"); 162 if(!tmp) 163 return SERVICE_FAILED; 164 fprintf(stderr,"Service internal print \n"); 165 dumpMaps(inputs); 166 fprintf(stderr,"/Service internal print \n"); 167 map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType"); 168 fprintf(stderr,"Service internal print \n"); 169 dumpMap(tmp1); 170 fprintf(stderr,"/Service internal print \n"); 171 if(tmp1!=NULL){ 172 if(strncmp(tmp1->value,"text/js",7)==0 || 173 strncmp(tmp1->value,"application/json",7)==0) 174 geometry=OGR_G_CreateGeometryFromJson(tmp->value); 175 else 176 geometry=createGeometryFromGML(conf,tmp->value); 177 } 178 else 179 geometry=createGeometryFromGML(conf,tmp->value); 180 res=(*myFunc)(geometry); 181 fprintf(stderr,"Service internal print \n"); 182 dumpMaps(outputs); 183 fprintf(stderr,"/Service internal print \n"); 184 map *tmp_2=getMapFromMaps(outputs,"Result","mimeType"); 185 fprintf(stderr,"Service internal print \n"); 186 dumpMap(tmp_2); 187 fprintf(stderr,"/Service internal print \n"); 188 if(tmp_2!=NULL){ 189 if(strncmp(tmp_2->value,"text/js",7)==0 || 190 strncmp(tmp_2->value,"application/json",16)==0){ 191 char *tres=OGR_G_ExportToJson(res); 192 addToMap(outputs->content,"value",tres); 193 free(tres); 194 addToMap(outputs->content,"mimeType","text/plain"); 195 addToMap(outputs->content,"encoding","UTF-8"); 196 } 197 else{ 198 char *tres=OGR_G_ExportToGML(res); 199 addToMap(outputs->content,"value",tres); 200 free(tres); 201 } 202 }else{ 203 char *tres=OGR_G_ExportToJson(res); 204 addToMap(outputs->content,"value",tres); 205 free(tres); 206 addToMap(outputs->content,"mimeType","text/plain"); 207 addToMap(outputs->content,"encoding","UTF-8"); 208 } 209 outputs->next=NULL; 210 #ifdef DEBUG 211 dumpMaps(outputs); 212 fprintf(stderr,"\nService internal print\n===\n"); 213 #endif 214 OGR_G_DestroyGeometry(res); 215 OGR_G_DestroyGeometry(geometry); 216 //CPLFree(res); 217 //CPLFree(geometry); 218 fprintf(stderr,"Service internal print \n"); 219 dumpMaps(outputs); 220 fprintf(stderr,"/Service internal print \n"); 221 return SERVICE_SUCCEEDED; 222 } 223 224 #ifdef WIN32 225 __declspec(dllexport) 226 #endif 227 int Buffer(maps*& conf,maps*& inputs,maps*& outputs){ 228 OGRGeometryH geometry,res; 229 map* tmp=getMapFromMaps(inputs,"InputPolygon","value"); 230 if(tmp==NULL) 231 return SERVICE_FAILED; 232 map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType"); 233 if(strncmp(tmp1->value,"application/json",16)==0) 234 geometry=OGR_G_CreateGeometryFromJson(tmp->value); 235 else 236 geometry=createGeometryFromGML(conf,tmp->value); 237 int bufferDistance=1; 238 tmp=getMapFromMaps(inputs,"BufferDistance","value"); 239 if(tmp!=NULL) 240 bufferDistance=atoi(tmp->value); 241 res=OGR_G_Buffer(geometry,bufferDistance,30); 242 tmp1=getMapFromMaps(outputs,"Result","mimeType"); 243 if(strncmp(tmp1->value,"application/json",16)==0){ 244 addToMap(outputs->content,"value",OGR_G_ExportToJson(res)); 245 addToMap(outputs->content,"mimeType","text/plain"); 246 } 247 else{ 248 addToMap(outputs->content,"value",OGR_G_ExportToGML(res)); 249 } 250 outputs->next=NULL; 251 OGR_G_DestroyGeometry(geometry); 252 OGR_G_DestroyGeometry(res); 253 return SERVICE_SUCCEEDED; 254 } 255 256 /* int Buffer(maps*& conf,maps*& inputs,maps*& outputs){ 257 #ifdef DEBUG 258 fprintf(stderr,"\nService internal print\n"); 259 #endif 260 maps* cursor=inputs; 261 OGRGeometryH geometry,res; 262 int bufferDistance; 263 if(cursor!=NULL){ 264 #ifdef DEBUG 265 fprintf(stderr,"\nService internal print\n"); 266 dumpMaps(cursor); 267 fprintf(stderr,"\nService internal print\n"); 268 dumpMaps(inputs); 269 fprintf(stderr,"\nService internal print\n"); 270 #endif 271 map* tmp=getMapFromMaps(inputs,"InputPolygon","value"); 272 map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType"); 273 if(tmp1!=NULL){ 274 if(strncmp(tmp1->value,"application/json",16)==0 || 275 strncmp(tmp1->value,"text/js",7)==0) 276 geometry=OGR_G_CreateGeometryFromJson(tmp->value); 277 else 278 geometry=createGeometryFromGML(conf,tmp->value); 279 } 280 else 281 geometry=createGeometryFromGML(conf,tmp->value); 282 } 283 if(cursor!=NULL){ 284 map* tmp=getMapFromMaps(cursor,"BufferDistance","value"); 285 if(tmp==NULL){ 286 bufferDistance=10; 287 } 288 else 289 bufferDistance=atoi(tmp->value); 290 #ifdef DEBUG 291 fprintf(stderr,"\nService internal print (BufferDistance value: %i)\n",bufferDistance); 292 #endif 293 } 294 #ifdef DEBUG 295 dumpMaps(outputs); 296 #endif 297 map* tmp=getMapFromMaps(outputs,"Result","mimeType"); 298 res=OGR_G_Buffer(geometry,bufferDistance,30); 299 #ifdef DEBUG 300 dumpMap(tmp); 301 #endif 302 if(tmp!=NULL){ 303 #ifdef DEBUG 304 dumpMap(tmp); 305 #endif 306 if(strncmp(tmp->value,"application/json",16)==0){ 307 addToMap(outputs->content,"value",OGR_G_ExportToJson(res)); 308 addToMap(outputs->content,"mimeType","text/plain"); 309 addToMap(outputs->content,"encoding","UTF-8"); 310 } 311 else if(strcmp(tmp->value,"text/xml")==0){ 312 xmlInitParser(); 313 xmlDocPtr doc = xmlParseMemory(tmp->value,strlen(tmp->value)); 314 xmlChar *xmlbuff; 315 int buffersize; 316 char *buff=OGR_G_ExportToGML(res); 317 addToMap(outputs->content,"value",buff); 318 map* tmp1=getMapFromMaps(outputs,"Result","encoding"); 319 if(tmp1!=NULL) 320 addToMap(outputs->content,"encoding",tmp1->value); 321 else 322 addToMap(outputs->content,"encoding","UTF-8"); 323 xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1); 324 xmlFree(xmlbuff); 325 xmlFreeDoc(doc); 326 xmlCleanupParser(); 327 } 328 else{ 329 addToMap(outputs->content,"value",OGR_G_ExportToJson(res)); 330 addToMap(outputs->content,"mimeType","text/plain"); 331 addToMap(outputs->content,"encoding","UTF-8"); 332 outputs->next=NULL; 333 } 334 outputs->next=NULL; 335 } 336 else{ 337 addToMap(outputs->content,"value",OGR_G_ExportToJson(res)); 338 addToMap(outputs->content,"mimeType","text/plain"); 339 addToMap(outputs->content,"encoding","UTF-8"); 340 outputs->next=NULL; 341 } 342 outputs->next=NULL; 343 #ifdef DEBUG 344 dumpMaps(outputs); 345 fprintf(stderr,"\nService internal print\n===\n"); 346 #endif 347 OGR_G_DestroyGeometry(geometry); 348 OGR_G_DestroyGeometry(res); 349 return SERVICE_SUCCEEDED; 350 } 351 */ 352 353 #ifdef WIN32 354 __declspec(dllexport) 355 #endif 356 int Boundary(maps*& conf,maps*& inputs,maps*& outputs){ 357 return applyOne(conf,inputs,outputs,&OGR_G_GetBoundary); 358 } 359 360 #ifdef WIN32 361 __declspec(dllexport) 362 #endif 363 int ConvexHull(maps*& conf,maps*& inputs,maps*& outputs){ 364 return applyOne(conf,inputs,outputs,&OGR_G_ConvexHull); 365 } 366 367 368 OGRGeometryH MY_OGR_G_Centroid(OGRGeometryH hTarget){ 369 OGRGeometryH res; 370 res=OGR_G_CreateGeometryFromJson("{\"type\": \"Point\", \"coordinates\": [0,0] }"); 371 OGRwkbGeometryType gtype=OGR_G_GetGeometryType(hTarget); 372 if(gtype!=wkbPolygon){ 373 hTarget=OGR_G_ConvexHull(hTarget); 374 } 375 int c=OGR_G_Centroid(hTarget,res); 376 return res; 377 } 378 379 #ifdef WIN32 380 __declspec(dllexport) 381 #endif 382 int Centroid(maps*& conf,maps*& inputs,maps*& outputs){ 383 return applyOne(conf,inputs,outputs,&MY_OGR_G_Centroid); 91 384 } 92 385 … … 130 423 } 131 424 res=(*myFunc)(geometry1,geometry2); 132 outputs=(maps*)malloc(sizeof(maps*)); 133 outputs->name="Result"; 134 char tmpres[100]; 135 sprintf(tmpres,"%d",res); 136 outputs->content=createMap("value",OGR_G_ExportToJson(res)); 137 addMapToMap(&outputs->content,createMap("mimeType","text/plain")); 138 addMapToMap(&outputs->content,createMap("encoding","UTF-8")); 425 addToMap(outputs->content,"value",OGR_G_ExportToJson(res)); 426 addToMap(outputs->content,"mimeType","text/plain"); 427 addToMap(outputs->content,"encoding","UTF-8"); 139 428 outputs->next=NULL; 429 OGR_G_DestroyGeometry(geometry1); 430 OGR_G_DestroyGeometry(geometry2); 431 OGR_G_DestroyGeometry(res); 140 432 return SERVICE_SUCCEEDED; 141 433 } 142 434 143 435 #ifdef WIN32 144 436 __declspec(dllexport) … … 162 454 } 163 455 164 int applyOne(maps*& conf,maps*& inputs,maps*& outputs,OGRGeometryH (*myFunc)(OGRGeometryH)){165 #ifdef DEBUG166 fprintf(stderr,"\nService internal print\n");167 #endif168 maps* cursor=inputs;169 OGRGeometryH geometry,res;170 int bufferDistance;171 #ifdef DEBUG172 dumpMaps(cursor);173 #endif174 map* tmp=getMapFromMaps(inputs,"InputPolygon","value");175 if(!tmp)176 return SERVICE_FAILED;177 map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeTime");178 if(tmp1!=NULL){179 if(strncmp(tmp1->value,"text/js",7)==0)180 geometry=OGR_G_CreateGeometryFromJson(tmp->value);181 else182 geometry=createGeometryFromGML(conf,tmp->value);183 }184 else185 geometry=createGeometryFromGML(conf,tmp->value);186 res=(*myFunc)(geometry);187 /**188 * Here we should check what is the requested output.189 * Let's use JSON per default.190 */191 //outputs=(maps*)malloc(sizeof(maps*));192 outputs->name="Result";193 if(tmp1!=NULL){194 if(strncmp(tmp1->value,"text/js",7)==0){195 outputs->content=createMap("value",OGR_G_ExportToJson(tmp->value));196 addMapToMap(&outputs->content,createMap("mimeType","text/plain"));197 addMapToMap(&outputs->content,createMap("encoding","UTF-8"));198 }199 else{200 outputs->content=createMap("value",OGR_G_ExportToGML(res));201 addMapToMap(&outputs->content,createMap("mimeType","text/xml"));202 addMapToMap(&outputs->content,createMap("encoding","UTF-8"));203 addMapToMap(&outputs->content,createMap("schema","http://fooa/gml/3.1.0/polygon.xsd"));204 }205 }else{206 outputs->content=createMap("value",OGR_G_ExportToJson(res));207 addMapToMap(&outputs->content,createMap("mimeType","text/plain"));208 addMapToMap(&outputs->content,createMap("encoding","UTF-8"));209 }210 outputs->next=NULL;211 #ifdef DEBUG212 dumpMaps(outputs);213 fprintf(stderr,"\nService internal print\n===\n");214 #endif215 return SERVICE_SUCCEEDED;216 }217 218 #ifdef WIN32219 __declspec(dllexport)220 #endif221 int ConvexHull(maps*& conf,maps*& inputs,maps*& outputs){222 return applyOne(conf,inputs,outputs,&OGR_G_ConvexHull);223 }224 225 #ifdef WIN32226 __declspec(dllexport)227 #endif228 int Boundary(maps*& conf,maps*& inputs,maps*& outputs){229 #ifdef DEBUG230 fprintf(stderr,"\nService internal print\nStarting\n");231 #endif232 maps* cursor=inputs;233 OGRGeometryH geometry,res;234 int bufferDistance;235 xmlInitParser();236 237 if(cursor!=NULL){238 map* tmp=getMapFromMaps(inputs,"InputPolygon","value");239 map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType");240 if(tmp1!=NULL){241 if(strncmp(tmp1->value,"text/js",7)==0)242 geometry=OGR_G_CreateGeometryFromJson(tmp->value);243 else244 geometry=createGeometryFromGML(conf,tmp->value);245 }246 else247 geometry=createGeometryFromGML(conf,tmp->value);248 }249 res=OGR_G_GetBoundary(geometry);250 outputs=(maps*)malloc(sizeof(maps*));251 outputs->name="Boundary";252 outputs->content=createMap("value",OGR_G_ExportToJson(res));253 addMapToMap(&outputs->content,createMap("mimeType","text/plain"));254 addMapToMap(&outputs->content,createMap("encoding","UTF-8"));255 /*256 outputs->content=createMap("value",OGR_G_ExportToGML(res));257 addMapToMap(&outputs->content,createMap("mimeType","text/xml"));258 addMapToMap(&outputs->content,createMap("encoding","UTF-8"));259 addMapToMap(&outputs->content,createMap("schema","http://fooa/gml/3.1.0/polygon.xsd"));260 */261 outputs->next=NULL;262 #ifdef DEBUG263 fprintf(stderr,"\nService internal print\n===\n");264 #endif265 xmlCleanupParser();266 return SERVICE_SUCCEEDED;267 }268 269 #ifdef WIN32270 __declspec(dllexport)271 #endif272 int Centroid(maps*& conf,maps*& inputs,maps*& outputs){273 #ifdef DEBUG274 fprintf(stderr,"\nService internal print\n");275 #endif276 maps* cursor=inputs;277 OGRGeometryH geometry,res=NULL;278 int bufferDistance;279 if(cursor!=NULL){280 #ifdef DEBUG281 fprintf(stderr,"\nService internal print\n");282 dumpMaps(cursor);283 fprintf(stderr,"\nService internal print\n");284 dumpMaps(inputs);285 fprintf(stderr,"\nService internal print\n");286 #endif287 map* tmp=getMapFromMaps(inputs,"InputPolygon","value");288 map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType");289 if(tmp1!=NULL){290 if(strncmp(tmp1->value,"application/json",16)==0)291 geometry=OGR_G_CreateGeometryFromJson(tmp->value);292 else293 geometry=createGeometryFromGML(conf,tmp->value);294 }295 else296 geometry=createGeometryFromGML(conf,tmp->value);297 }else{298 /**299 * Print WPSExceptionError message here !!300 */301 }302 #ifdef DEBUG303 dumpMaps(outputs);304 #endif305 res=OGR_G_CreateGeometryFromJson("{\"type\": \"Point\", \"coordinates\": [0,0] }");306 OGRwkbGeometryType gtype=OGR_G_GetGeometryType(geometry);307 if(gtype!=wkbPolygon){308 fprintf(stderr,"\n\nGeometry Type is not Polygon, let us use the ConvexHull !\n\n");309 geometry=OGR_G_ConvexHull(OGR_G_Clone(geometry));310 }else{311 fprintf(stderr,"\n\nGeometry Type is Polygon, thanks !\n\n");312 }313 int c=OGR_G_Centroid(geometry,res);314 #ifdef DEBUG315 fprintf(stderr,"\n\nC VALUE : %d\n\n",c);316 #endif317 map* tmp=getMapFromMaps(outputs,"Result","mimeType");318 #ifdef DEBUG319 dumpMaps(outputs);320 #endif321 if(tmp!=NULL){322 #ifdef DEBUG323 dumpMap(tmp);324 #endif325 if(strncmp(mtoupper(tmp->value),mtoupper("application/json"),16)==0){326 outputs->content=createMap("value",OGR_G_ExportToJson(res));327 addMapToMap(&outputs->content,createMap("mimeType","text/plain"));328 addMapToMap(&outputs->content,createMap("encoding","UTF-8"));329 }330 else if(strncmp(mtoupper(tmp->value),mtoupper("text/xml"),8)==0){331 /*xmlInitParser();332 xmlDocPtr doc = xmlParseMemory(tmp->value,strlen(tmp->value));333 xmlChar *xmlbuff;334 int buffersize;*/335 outputs->content=createMap("value",OGR_G_ExportToGML(res));336 addMapToMap(&outputs->content,createMap("mimeType","text/xml"));337 map* tmp1=getMapFromMaps(outputs,"Result","encoding");338 if(tmp1!=NULL)339 addMapToMap(&outputs->content,createMap("encoding",tmp1->value));340 else341 addMapToMap(&outputs->content,createMap("encoding","UTF-8"));342 /*xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1);343 outputs->content=createMap("value",OGR_G_ExportToGML(res));344 xmlFree(xmlbuff);345 xmlFreeDoc(doc);346 xmlCleanupParser();347 */348 }349 else{350 outputs=(maps*)malloc(sizeof(maps*));351 outputs->name="Result";352 outputs->content=createMap("value",OGR_G_ExportToJson(res));353 addMapToMap(&outputs->content,createMap("mimeType","text/plain"));354 addMapToMap(&outputs->content,createMap("encoding","UTF-8"));355 outputs->next=NULL;356 }357 outputs->next=NULL;358 }359 else{360 outputs=(maps*)malloc(sizeof(maps*));361 outputs->name="Result";362 outputs->content=createMap("value",OGR_G_ExportToJson(res));363 addMapToMap(&outputs->content,createMap("mimeType","text/plain"));364 addMapToMap(&outputs->content,createMap("encoding","UTF-8"));365 outputs->next=NULL;366 }367 outputs->next=NULL;368 #ifdef DEBUG369 dumpMaps(outputs);370 fprintf(stderr,"\nService internal print\n===\n");371 #endif372 return SERVICE_SUCCEEDED;373 }374 375 #ifdef WIN32376 __declspec(dllexport)377 #endif378 int Buffer(maps*& conf,maps*& inputs,maps*& outputs){379 #ifdef DEBUG380 fprintf(stderr,"\nService internal print\n");381 #endif382 maps* cursor=inputs;383 OGRGeometryH geometry,res;384 int bufferDistance;385 if(cursor!=NULL){386 #ifdef DEBUG387 fprintf(stderr,"\nService internal print\n");388 dumpMaps(cursor);389 fprintf(stderr,"\nService internal print\n");390 dumpMaps(inputs);391 fprintf(stderr,"\nService internal print\n");392 #endif393 map* tmp=getMapFromMaps(inputs,"InputPolygon","value");394 map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType");395 if(tmp1!=NULL){396 if(strncmp(tmp1->value,"application/json",16)==0)397 geometry=OGR_G_CreateGeometryFromJson(tmp->value);398 else399 geometry=createGeometryFromGML(conf,tmp->value);400 }401 else402 geometry=createGeometryFromGML(conf,tmp->value);403 }404 if(cursor!=NULL){405 map* tmp=getMapFromMaps(cursor,"BufferDistance","value");406 if(tmp==NULL){407 bufferDistance=10;408 }409 else410 bufferDistance=atoi(tmp->value);411 #ifdef DEBUG412 fprintf(stderr,"\nService internal print (BufferDistance value: %i)\n",bufferDistance);413 #endif414 }415 #ifdef DEBUG416 dumpMaps(outputs);417 #endif418 map* tmp=getMapFromMaps(outputs,"BufferedPolygon","mimeType");419 res=OGR_G_Buffer(geometry,bufferDistance,30);420 #ifdef DEBUG421 dumpMap(tmp);422 #endif423 if(tmp!=NULL){424 #ifdef DEBUG425 dumpMap(tmp);426 #endif427 if(strncmp(mtoupper(tmp->value),mtoupper("application/json"),16)==0){428 outputs->content=createMap("value",OGR_G_ExportToJson(res));429 addMapToMap(&outputs->content,createMap("mimeType","text/plain"));430 addMapToMap(&outputs->content,createMap("encoding","UTF-8"));431 }432 else if(strcmp(mtoupper(tmp->value),mtoupper("text/xml"))==0){433 xmlInitParser();434 xmlDocPtr doc = xmlParseMemory(tmp->value,strlen(tmp->value));435 xmlChar *xmlbuff;436 int buffersize;437 outputs->content=createMap("value",OGR_G_ExportToGML(res));438 addMapToMap(&outputs->content,createMap("mimeType","text/xml"));439 map* tmp1=getMapFromMaps(outputs,"BufferedPolygon","encoding");440 if(tmp1!=NULL)441 addMapToMap(&outputs->content,createMap("encoding",tmp1->value));442 else443 addMapToMap(&outputs->content,createMap("encoding","UTF-8"));444 xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1);445 outputs->content=createMap("value",OGR_G_ExportToGML(res));446 xmlFree(xmlbuff);447 xmlFreeDoc(doc);448 xmlCleanupParser();449 }450 else{451 outputs=(maps*)malloc(sizeof(maps*));452 outputs->name="BufferedPolygon";453 outputs->content=createMap("value",OGR_G_ExportToJson(res));454 addMapToMap(&outputs->content,createMap("mimeType","text/plain"));455 addMapToMap(&outputs->content,createMap("encoding","UTF-8"));456 outputs->next=NULL;457 }458 outputs->next=NULL;459 }460 else{461 outputs=(maps*)malloc(sizeof(maps*));462 outputs->name="BufferedPolygon";463 outputs->content=createMap("value",OGR_G_ExportToJson(res));464 addMapToMap(&outputs->content,createMap("mimeType","text/plain"));465 addMapToMap(&outputs->content,createMap("encoding","UTF-8"));466 outputs->next=NULL;467 }468 outputs->next=NULL;469 #ifdef DEBUG470 dumpMaps(outputs);471 fprintf(stderr,"\nService internal print\n===\n");472 #endif473 return SERVICE_SUCCEEDED;474 }475 476 456 #ifdef WIN32 477 457 __declspec(dllexport) 478 458 #endif 479 459 int Union(maps*& conf,maps*& inputs,maps*& outputs){ 480 #ifdef DEBUG 481 fprintf(stderr,"\nService internal print1\n"); 482 fflush(stderr); 483 #endif 484 maps* cursor=inputs; 485 OGRGeometryH geometry1,geometry2; 486 OGRGeometryH res; 487 { 488 map* tmp=getMapFromMaps(inputs,"InputEntity1","value"); 489 map* tmp1=getMapFromMaps(inputs,"InputEntity1","mimeType"); 490 if(tmp1!=NULL){ 491 if(strncmp(tmp1->value,"application/json",16)==0) 492 geometry1=OGR_G_CreateGeometryFromJson(tmp->value); 493 else 494 geometry1=createGeometryFromGML(conf,tmp->value); 495 } 496 else 497 geometry1=createGeometryFromGML(conf,tmp->value); 498 } 499 { 500 map* tmp=getMapFromMaps(inputs,"InputEntity2","value"); 501 map* tmp1=getMapFromMaps(inputs,"InputEntity2","mimeType"); 502 #ifdef DEBUG 503 fprintf(stderr,"MY MAP\n"); 504 dumpMap(tmp1); 505 fprintf(stderr,"MY MAP\n"); 506 #endif 507 if(tmp1!=NULL){ 508 if(strncmp(tmp1->value,"application/json",16)==0) 509 geometry2=OGR_G_CreateGeometryFromJson(tmp->value); 510 else 511 geometry2=createGeometryFromGML(conf,tmp->value); 512 } 513 else 514 geometry2=createGeometryFromGML(conf,tmp->value); 515 } 516 res=OGR_G_Union(geometry1,geometry2); 517 outputs=(maps*)malloc(sizeof(maps*)); 518 outputs->name="Result"; 519 char tmpres[100]; 520 sprintf(tmpres,"%d",res); 521 outputs->content=createMap("value",OGR_G_ExportToJson(res)); 522 addMapToMap(&outputs->content,createMap("mimeType","text/plain")); 523 addMapToMap(&outputs->content,createMap("encoding","UTF-8")); 524 outputs->next=NULL; 525 return SERVICE_SUCCEEDED; 460 return applyTwo(conf,inputs,outputs,&OGR_G_Union); 526 461 } 527 462 … … 589 524 } 590 525 526 #ifdef WIN32 527 __declspec(dllexport) 528 #endif 591 529 int GetArea(maps*& conf,maps*& inputs,maps*& outputs){ 592 530 fprintf(stderr,"GETAREA \n");
Note: See TracChangeset
for help on using the changeset viewer.