Changeset 382 for trunk/zoo-project/zoo-services
- Timestamp:
- Dec 28, 2012, 1:16:09 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-project/zoo-services/ogr/base-vect-ops-py/cgi-env/ogr_sp.py
r360 r382 5 5 import os 6 6 import sys 7 import zoo 7 8 8 9 def readFileFromBuffer(data,ext): 9 geometry=[] 10 osgeo.gdal.FileFromMemBuffer('/vsimem//temp1'+ext,data) 11 ds = osgeo.ogr.Open('/vsimem//temp1'+ext) 12 lyr = ds.GetLayer(0) 13 feat = lyr.GetNextFeature() 14 while feat is not None: 15 geometry+=[feat.Clone()] 16 feat.Destroy() 10 try: 11 geometry=[] 12 print >> sys.stderr,'/vsimem//temp1'+ext 13 #print >> sys.stderr,data 14 osgeo.gdal.FileFromMemBuffer('/vsimem//temp1'+ext,data) 15 ds = osgeo.ogr.Open('/vsimem//temp1'+ext) 16 lyr = ds.GetLayer(0) 17 17 feat = lyr.GetNextFeature() 18 ds.Destroy() 19 osgeo.gdal.Unlink('/vsimem//temp1'+ext) 20 return geometry 18 while feat is not None: 19 geometry+=[feat.Clone()] 20 feat.Destroy() 21 feat = lyr.GetNextFeature() 22 ds.Destroy() 23 osgeo.gdal.Unlink('/vsimem//temp1'+ext) 24 return geometry 25 except Exception,e: 26 print >> sys.stderr,e 27 return [] 21 28 22 29 def buildFeatureFromGeomtry(conf,geom,driverName,ext): … … 41 48 try: 42 49 if geom is None: 43 return readFileFromBuffer(my_wfs_response,"") 50 if not(conf["lenv"].has_key("cnt")): 51 conf["lenv"]["cnt"]=0 52 else: 53 conf["lenv"]["cnt"]+=1 54 return readFileFromBuffer(my_wfs_response,str(conf["lenv"]["cnt"])) 44 55 else: 45 56 return buildFeatureFromGeomtry(conf,geom,"GML","xml") … … 76 87 i=0 77 88 while i < len(geom): 89 if i==0 and driverName!="GeoJSON": 90 poDstFDefn=geom[i].GetDefnRef() 91 if poDstFDefn is not None: 92 nDstFieldCount = poDstFDefn.GetFieldCount() 93 for iField in range(nDstFieldCount): 94 poSrcFieldDefn = poDstFDefn.GetFieldDefn(iField) 95 oFieldDefn = osgeo.ogr.FieldDefn(poSrcFieldDefn.GetNameRef(),poSrcFieldDefn.GetType()) 96 oFieldDefn.SetWidth( poSrcFieldDefn.GetWidth() ) 97 oFieldDefn.SetPrecision( poSrcFieldDefn.GetPrecision() ) 98 lyr.CreateField( oFieldDefn ) 78 99 lyr.CreateFeature(geom[i]) 79 100 geom[i].Destroy() … … 90 111 91 112 def BufferPy(conf,inputs,outputs): 92 print >> sys.stderr, inputs 93 print >> sys.stderr, outputs 113 print >> sys.stderr, "Starting service ..." 94 114 try: 95 115 bdist=float(inputs["BufferDistance"]["value"]) … … 97 117 bdist=1 98 118 print >> sys.stderr, bdist 99 100 119 geometry=extractInputs(conf,inputs["InputPolygon"]) 101 120 i=0 … … 112 131 outputResult(conf,outputs["Result"],rgeometries) 113 132 i=0 114 return 3133 return zoo.SERVICE_SUCCEEDED 115 134 116 135 def BoundaryPy(conf,inputs,outputs): … … 127 146 i+=1 128 147 outputResult(conf,outputs["Result"],rgeometries) 129 return 3148 return zoo.SERVICE_SUCCEEDED 130 149 131 150 def CentroidPy(conf,inputs,outputs): … … 144 163 i+=1 145 164 outputResult(conf,outputs["Result"],rgeometries) 146 return 3165 return zoo.SUCCEEDED 147 166 148 167 def ConvexHullPy(conf,inputs,outputs): … … 158 177 i+=1 159 178 outputResult(conf,outputs["Result"],rgeometries) 160 return 3179 return zoo.SUCCEEDED 161 180 162 181 … … 198 217 199 218 geometry1=extractInputs(conf,inputs["InputEntity1"]) 200 print >> sys.stderr,inputs["InputEntity2"] 201 geometry2=extractInputs(conf,inputs["InputEntity2"]) 202 203 rgeometries=[] 219 geometry2=extractInputs(conf,inputs["InputEntity2"]) 220 221 print >> sys.stderr,str(len(geometry1))+" "+str(len(geometry2)) 222 223 rgeometries=[] 224 fids=[] 204 225 i=0 205 226 while i < len(geometry1): … … 211 232 resg=geometry1[i].GetGeometryRef().Intersection(resg) 212 233 tmp.SetGeometryDirectly(resg) 213 if not(resg.IsEmpty()):234 if resg is not None and not(resg.IsEmpty()) and fids.count(tmp.GetFID())==0: 214 235 rgeometries+=[tmp] 236 fids+=[tmp.GetFID()] 237 else: 238 tmp.Destroy() 215 239 j+=1 216 240 geometry1[i].Destroy()
Note: See TracChangeset
for help on using the changeset viewer.