- Timestamp:
- Apr 23, 2014, 3:05:01 AM (11 years ago)
- Location:
- trunk/zoo-project/zoo-services/ogr/base-vect-ops-py/cgi-env
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-project/zoo-services/ogr/base-vect-ops-py/cgi-env/CentroidPy.zcfg
r106 r465 1 [CentroidPy] 2 Title = Get the centroid of a polygon. 3 Abstract = Compute the geometry centroid. 4 Profile = urn:ogc:wps:1.0.0:centroid 5 processVersion = 2 1 [Clean] 2 Title = Extract the feature that have a valid geometry field. 3 Abstract = Extract the feature that have a valid geometry field. 4 processVersion = 1 6 5 storeSupported = true 7 6 statusSupported = true 8 7 serviceProvider = ogr_sp 9 8 serviceType = Python 10 <MetaData>11 title = Demo12 </MetaData>13 9 <DataInputs> 14 [Input Polygon]10 [InputData] 15 11 Title = Polygon to get the centroid 16 12 Abstract = The centroid which is not necessarily within the geometry. 17 13 minOccurs = 1 18 14 maxOccurs = 1 19 <MetaData>20 title = Mon test21 </MetaData>22 15 <ComplexData> 23 16 <Default> … … 37 30 Title = The Centroid 38 31 Abstract = JSON String / GML Entity of the centroid 39 <MetaData>40 title = Mon test41 </MetaData>42 32 <ComplexData> 43 33 <Default> -
trunk/zoo-project/zoo-services/ogr/base-vect-ops-py/cgi-env/ogr_sp.py
r447 r465 52 52 print >> sys.stderr,e 53 53 return [] 54 54 55 55 def buildFeatureFromGeomtry(conf,geom,driverName,ext): 56 56 drv = osgeo.ogr.GetDriverByName( driverName ) … … 69 69 def createGeometryFromWFS(conf,my_wfs_response): 70 70 try: 71 geom=osgeo.ogr.CreateGeometryFromGML(my_wfs_response.replace('<?xml version="1.0" encoding="utf-8"?>\n','')) 72 except: 71 geom=osgeo.ogr.CreateGeometryFromGML(my_wfs_response.replace('<?xml version="1.0" encoding="utf-8"?>\n','').replace('<?xml version=\'1.0\' encoding="utf-8"?>\n','')) 72 except Exception,e: 73 print >> sys.stderr,"**" 74 print >> sys.stderr,e 73 75 geom=None 74 76 try: 77 print >> sys.stderr,geom is None 75 78 if geom is None: 76 79 if not(conf["lenv"].has_key("cnt")): … … 98 101 99 102 def outputResult(conf,obj,geom): 100 driverName = "GML" 101 extension = [ ".xml" , ".xsd" ] 103 if obj["mimeType"].count("text/xml")>0: 104 driverName = "GML" 105 extension = [ ".xml" , ".xsd" ] 106 format_list = { "2.": 'GML2', "3.1.1": 'GML3', "3.1": 'GML3Deegree', "3.2": 'GML3.2' } 107 opts=['FORMAT=%s,GML3_LONGSRS=YES',format_list["3.2"]] 108 for i in format_list: 109 if obj["mimeType"].count(i)>0: 110 opts=['FORMAT=%s,GML3_LONGSRS=YES',format_list[i]] 102 111 if obj["mimeType"]=="application/json": 103 112 driverName = "GeoJSON" 104 113 extension = [ ".js" ] 114 opts=None 105 115 if obj.keys().count("schema")>0 and \ 106 116 obj["schema"]=="http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd": 107 117 driverName = "KML" 108 118 extension = [ ".kml" ] 119 opts=None 109 120 drv = osgeo.ogr.GetDriverByName( driverName ) 110 # Create virtual file 111 ds = drv.CreateDataSource( "/vsimem/store"+conf["lenv"]["sid"]+extension[0] ) 121 print >> sys.stderr,drv 122 # Create virtual file 123 ds = drv.CreateDataSource( "/vsimem/store"+conf["lenv"]["sid"]+extension[0],options = opts) 124 print >> sys.stderr,ds 112 125 lyr = ds.CreateLayer( "Result", None, osgeo.ogr.wkbUnknown ) 113 i=0 126 print >> sys.stderr,lyr 127 i=0 128 print >> sys.stderr,driverName 129 print >> sys.stderr,extension 114 130 while i < len(geom): 115 131 if i==0 and driverName!="GeoJSON": … … 123 139 oFieldDefn.SetPrecision( poSrcFieldDefn.GetPrecision() ) 124 140 lyr.CreateField( oFieldDefn ) 125 lyr.CreateFeature(geom[i]) 141 try: 142 lyr.CreateFeature(geom[i]) 143 except: 144 pass 126 145 geom[i].Destroy() 127 146 i+=1 … … 157 176 outputResult(conf,outputs["Result"],rgeometries) 158 177 i=0 178 return zoo.SERVICE_SUCCEEDED 179 180 def Clean(conf,inputs,outputs): 181 from shapely.wkb import loads 182 print >> sys.stderr, "Starting service ..." 183 features=extractInputs(conf,inputs["InputData"]) 184 i=0 185 rgeometries=[] 186 while i < len(features): 187 tmp=features[i].Clone() 188 resg=features[i].GetGeometryRef() 189 if resg is not None: 190 geom = loads(resg.ExportToWkb()) 191 if geom.is_valid: 192 tmp.SetGeometryDirectly(resg) 193 rgeometries+=[tmp] 194 print >> sys.stderr,"valid !" 195 else: 196 print >> sys.stderr,"invalid !" 197 print >> sys.stderr,geom.wkt[0:50] 198 features[i].Destroy() 199 resg.thisown=False 200 tmp.thisown=False 201 i+=1 202 outputResult(conf,outputs["Result"],rgeometries) 203 i=0 204 print >> sys.stderr,"Return" 205 return zoo.SERVICE_SUCCEEDED 206 207 def TransformService(conf,inputs,outputs): 208 from osgeo import osr 209 geometry=extractInputs(conf,inputs["InputData"]) 210 sourceRef = osr.SpatialReference() 211 tmp=inputs["SourceCRS"]["value"].split(":") 212 sourceRef.ImportFromEPSG(int(tmp[len(tmp)-1])) 213 targetRef = osr.SpatialReference() 214 tmp=inputs["TargetCRS"]["value"].split(":") 215 targetRef.ImportFromEPSG(int(tmp[len(tmp)-1])) 216 transform = osr.CoordinateTransformation(sourceRef, targetRef) 217 i=0 218 rgeometries=[] 219 while i < len(geometry): 220 tmp=geometry[i].Clone() 221 resg=geometry[i].GetGeometryRef() 222 resg.Transform(transform) 223 tmp.SetGeometryDirectly(resg.Clone()) 224 rgeometries+=[tmp] 225 geometry[i].Destroy() 226 i+=1 227 outputResult(conf,outputs["TransformedData"],rgeometries) 159 228 return zoo.SERVICE_SUCCEEDED 160 229
Note: See TracChangeset
for help on using the changeset viewer.