source: trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/ogr_sp.py @ 9

Last change on this file since 9 was 9, checked in by djay, 12 years ago

Update of both ZOO Kernel and ZOO Services (ogr base-vect-ops ServicesProvider?).
All the ZCFG files have been corrected to remove all references to wrong metadata (Test = Demo) to avoid validation issues.
Main Memory leaks has been removed from this version.
Addition of the Simplify Service in the C ogr base-vect-ops ServicesProvider? and addition of the Python version (without Simplify).
Update of the configure.ac and Makefile.in to follow dicussions on the mailing list and ensure to use our cgic206 and not another one, path to our cgic library is now directly in the Makefile.in file.
Accept the "-" character to name inputs, to solve issue on GRASS 7 integration.
Addition of the extension keyword for ZCFG file to be able to store resulting outputs in a file name using the extension suffix.
This version after a testing period shall be considerate as 1.0.1 version of the ZOO Project.

File size: 3.1 KB
Line 
1import osgeo.ogr
2import libxml2
3
4def createGeometryFromWFS(my_wfs_response):
5    doc=libxml2.parseMemory(my_wfs_response,len(my_wfs_response))
6    ctxt = doc.xpathNewContext()
7    res=ctxt.xpathEval("/*/*/*/*/*[local-name()='Polygon' or local-name()='MultiPolygon']")
8    for node in res:
9        geometry_as_string=node.serialize()
10        geometry=osgeo.ogr.CreateGeometryFromGML(geometry_as_string)
11        return geometry
12    return geometry
13
14def extractInputs(obj):
15    if obj["mimeType"]=="application/json":
16        return osgeo.ogr.CreateGeometryFromJson(obj["value"])
17    else:
18        try:
19                return createGeometryFromWFS(obj["value"])
20        except:
21                return osgeo.ogr.CreateGeometryFromJson(obj["value"])
22    return null
23   
24def outputResult(obj,geom):
25    if obj["mimeType"]=="application/json":
26        obj["value"]=geom.ExportToJson()
27        obj["mimeType"]="text/plain"
28    else:
29        obj["value"]=geom.ExportToGML()
30
31def BoundaryPy(conf,inputs,outputs):
32    geometry=extractInputs(inputs["InputPolygon"])
33    rgeom=geometry.GetBoundary()
34    if outputs["Result"]["mimeType"]=="application/json":
35        outputs["Result"]["value"]=rgeom.ExportToJson()
36        outputs["Result"]["mimeType"]="text/plain"
37    else:
38        outputs["Result"]["value"]=rgeom.ExportToGML()
39    return 3
40
41def CentroidPy(conf,inputs,outputs):
42    geometry=extractInputs(inputs["InputPolygon"])
43    if geometry.GetGeometryType()!=3:
44        geometry=geometry.ConvexHull()
45    rgeom=geometry.Centroid()
46    outputResult(outputs["Result"],rgeom)
47    return 3
48
49def ConvexHullPy(conf,inputs,outputs):
50    geometry=extractInputs(inputs["InputPolygon"])
51    rgeom=geometry.ConvexHull()
52    outputResult(outputs["Result"],rgeom)
53    return 3
54
55def BufferPy(conf,inputs,outputs):
56    geometry=createGeometryFromWFS(inputs["InputPolygon"]["value"])
57    try:
58        bdist=int(inputs["BufferDistance"]["value"])
59    except:
60        bdist=10
61    rgeom=geometry.Buffer(bdist)
62    if outputs["Result"]["mimeType"]=="application/json":
63        outputs["Result"]["value"]=rgeom.ExportToJson()
64        outputs["Result"]["mimeType"]="text/plain"
65    else:
66        outputs["Result"]["value"]=rgeom.ExportToGML()
67    return 3
68
69def UnionPy(conf,inputs,outputs):
70    geometry1=extractInputs(inputs["InputEntity1"])
71    geometry2=extractInputs(inputs["InputEntity2"])
72    rgeom=geometry1.Union(geometry2)
73    outputResult(outputs["Result"],rgeom)
74    return 3
75
76def IntersectionPy(conf,inputs,outputs):
77    geometry1=extractInputs(inputs["InputEntity1"])
78    geometry2=extractInputs(inputs["InputEntity2"])
79    rgeom=geometry1.Intersection(geometry2)
80    outputResult(outputs["Result"],rgeom)
81    return 3
82
83def DifferencePy(conf,inputs,outputs):
84    geometry1=extractInputs(inputs["InputEntity1"])
85    geometry2=extractInputs(inputs["InputEntity2"])
86    rgeom=geometry1.Difference(geometry2)
87    outputResult(outputs["Result"],rgeom)
88    return 3
89
90def SymDifferencePy(conf,inputs,outputs):
91    geometry1=extractInputs(inputs["InputEntity1"])
92    geometry2=extractInputs(inputs["InputEntity2"])
93    rgeom=geometry1.SymmetricDifference(geometry2)
94    outputResult(outputs["Result"],rgeom)
95    return 3
Note: See TracBrowser for help on using the repository browser.

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