Ignore:
Timestamp:
Dec 28, 2012, 1:16:09 AM (12 years ago)
Author:
djay
Message:

Add fields to outputed features.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/zoo-project/zoo-services/ogr/base-vect-ops-py/cgi-env/ogr_sp.py

    r360 r382  
    55import os
    66import sys
     7import zoo
    78
    89def 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)
    1717        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 []
    2128
    2229def buildFeatureFromGeomtry(conf,geom,driverName,ext):
     
    4148    try:
    4249        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"]))
    4455        else:
    4556            return buildFeatureFromGeomtry(conf,geom,"GML","xml")
     
    7687    i=0
    7788    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 )
    7899        lyr.CreateFeature(geom[i])
    79100        geom[i].Destroy()
     
    90111
    91112def BufferPy(conf,inputs,outputs):
    92     print >> sys.stderr, inputs
    93     print >> sys.stderr, outputs
     113    print >> sys.stderr, "Starting service ..."
    94114    try:
    95115        bdist=float(inputs["BufferDistance"]["value"])
     
    97117        bdist=1
    98118    print >> sys.stderr, bdist
    99    
    100119    geometry=extractInputs(conf,inputs["InputPolygon"])
    101120    i=0
     
    112131    outputResult(conf,outputs["Result"],rgeometries)
    113132    i=0
    114     return 3
     133    return zoo.SERVICE_SUCCEEDED
    115134
    116135def BoundaryPy(conf,inputs,outputs):
     
    127146        i+=1
    128147    outputResult(conf,outputs["Result"],rgeometries)
    129     return 3
     148    return zoo.SERVICE_SUCCEEDED
    130149
    131150def CentroidPy(conf,inputs,outputs):
     
    144163        i+=1
    145164    outputResult(conf,outputs["Result"],rgeometries)
    146     return 3
     165    return zoo.SUCCEEDED
    147166
    148167def ConvexHullPy(conf,inputs,outputs):
     
    158177        i+=1
    159178    outputResult(conf,outputs["Result"],rgeometries)
    160     return 3
     179    return zoo.SUCCEEDED
    161180
    162181
     
    198217
    199218    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=[]
    204225    i=0
    205226    while i < len(geometry1):
     
    211232            resg=geometry1[i].GetGeometryRef().Intersection(resg)
    212233            tmp.SetGeometryDirectly(resg)
    213             if not(resg.IsEmpty()):
     234            if resg is not None and not(resg.IsEmpty()) and fids.count(tmp.GetFID())==0:
    214235                rgeometries+=[tmp]
     236                fids+=[tmp.GetFID()]
     237            else:
     238                tmp.Destroy()
    215239            j+=1
    216240        geometry1[i].Destroy()
Note: See TracChangeset for help on using the changeset viewer.

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