= 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 ==
{{{
#!python
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
}}}
== XML POST Request on page 22 ==
{{{
#!xml
Boundary
InputPolygon
Playground area
Result
Area serviced by playground.
Area within which most users of this playground will live.
}}}
== XML POST Request on page 23 ==
{{{
#!xml
Boundary
InputPolygon
{ "type": "MultiPolygon", "coordinates": [ [ [ [ -105.998360, 31.393818 ], [ -106.212753, 31.478128 ], [ -106.383041, 31.733763 ], [ -106.538971, 31.786198 ], [-106.614441, 31.817728 ], [ -105.769730, 31.170780 ], [ -105.998360, 31.393818 ] ] ], [ [ [-94.913429, 29.257572 ], [ -94.767380, 29.342451 ], [ -94.748405, 29.319490 ], [-95.105415, 29.096958 ], [ -94.913429, 29.257572 ] ] ] ] }
Result
Area serviced by playground.
Area within which most users of this
playground will live.
}}}
== Second code block on page 26 ==
{{{
#!python
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 ==
{{{
#!python
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 ==
{{{
#!python
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 ==
{{{
Single geometry processing
}}}
== Part 4.4 Page 35 code section ==
{{{
function multiProcessing(aProcess) {
if (select.features.length == 0 || hover.features.length == 0)
return alert("No feature created!");
var url = '/zoo/';
var xlink = control.protocol.url +"?SERVICE=WFS&REQUEST=GetFeature&VERSION=1.0.0";
xlink += '&typename='+control.protocol.featurePrefix;
xlink += ':'+control.protocol.featureType;
xlink += '&SRS='+control.protocol.srsName;
xlink += '&FeatureID='+select.features[0].fid;
var GeoJSON = new OpenLayers.Format.GeoJSON();
try {
var params = '';
params += ' '+aProcess+'';
params += ' ';
params += ' ';
params += ' InputEntity1';
params += ' ';
params += ' ';
params += ' ';
params += ' InputEntity2';
params += ' ';
params += ' '+GeoJSON.write(hover.features[0].geometry)+' ';
params += ' ';
params += ' ';
params += ' ';
params += ' ';
params += ' ';
params += ' Result';
params += ' ';
params += ' ';
params += ' ';
} catch(e) {
alert(e);
return false;
}
var request = new OpenLayers.Request.XMLHttpRequest();
request.open('POST',url,true);
request.setRequestHeader('Content-Type','text/xml');
request.onreadystatechange = function() {
if(request.readyState == OpenLayers.Request.XMLHttpRequest.DONE) {
var GeoJSON = new OpenLayers.Format.GeoJSON();
var features = GeoJSON.read(request.responseText);
multi.removeFeatures(multi.features);
multi.addFeatures(features);
}
}
request.send(params);
}
}}}