ZooWorkshop2010/Files

Version 1 (modified by djay, 14 years ago)

--

ZOO Workshop 2010 Files

As some files cause many trouble when we use copy and paste, we've put the examples in this page.

ogr_ws_service_provider.py File

import osgeo.ogr
import libxml2

def createGeometryFromWFS(my_wfs_response):
        doc=libxml2.parseMemory(my_wfs_response,len(my_wfs_response))
        ctxt = doc.xpathNewContext()
        res=ctxt.xpathEval("/*/*/*/*/*[local-name()='Polygon' or local- name()='MultiPolygon']")
        for node in res:
                geometry_as_string=node.serialize()
                geometry=osgeo.ogr.CreateGeometryFromGML(geometry_as_string)
                return geometry
        return geometry

def Boundary(conf,inputs,outputs):
        if inputs["InputPolygon"]["mimeType"]=="application/json":
                geometry=osgeo.ogr.CreateGeometryFromJson(inputs["InputPolygon"]["value"])
        else:
                geometry=createGeometryFromWFS(inputs["InputPolygon"]["value"])
        rgeom=geometry.GetBoundary()
        if outputs["Result"]["mimeType"]=="application/json":
                outputs["Result"]["value"]=rgeom.ExportToJson()
                outputs["Result"]["mimeType"]="text/plain"
        else:
                outputs["Result"]["value"]=rgeom.ExportToGML()
        geometry.Destroy()
        rgeom.Destroy()
        return 3

Second code block on page 26

def extractInputs(obj):
        if obj["mimeType"]=="application/json":
                return osgeo.ogr.CreateGeometryFromJson(obj["value"])
        else:
                return createGeometryFromWFS(obj["value"])
        return null

def outputResult(obj,geom):
        if obj["mimeType"]=="application/json":
                obj["value"]=geom.ExportToJson()
                obj["mimeType"]="text/plain"
        else:
                obj["value"]=geom.ExportToGML()

Third code block on page 26

def Boundary(conf,inputs,outputs):
        geometry=extractInputs(inputs["InputPolygon"])
        rgeom=geometry.GetBoundary()
        outputResult(outputs["Result"],rgeom)
        geometry.Destroy()
        rgeom.Destroy()
        return 3 

Code block on page 27

def ConvexHull(conf,inputs,outputs):
        geometry=extractInputs(inputs["InputPolygon"])
        rgeom=geometry.ConvexHull()
        outputResult(outputs["Result"],rgeom)
        geometry.Destroy()
        rgeom.Destroy()
        return 3 

def Centroid(conf,inputs,outputs):
        geometry=extractInputs(inputs["InputPolygon"])
        if geometry.GetGeometryType()!=3:
                geometry=geometry.ConvexHull()
        rgeom=geometry.Centroid()
        outputResult(outputs["Result"],rgeom)
        geometry.Destroy()
        rgeom.Destroy()
        return 3 

zoo-ogr.html File

<h3>Single geometry processing</h3>
<ul>
  <li>
   <input type="button" onclick="simpleProcessing(this.value);" value="Buffer"/>
   Distance:
   <input id="bufferDist" value="1"/>
  </li>
  <li>
   <input type="button" onclick="simpleProcessing(this.value);" value="ConvexHull"/>
  </li>
  <li>
   <input type="button" onclick="simpleProcessing(this.value);" value="Boundary"/>
  </li>
  <li>
   <input type="button" onclick="simpleProcessing(this.value);" value="Centroid"/>
  </li>
</ul>

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