def run(self, **args): """ Executes the process with set of named inputs. The input argument names are specified by the :attr:`inputs` property. The output arguments names are specified by the :attr:`outputs` property. >>> p = Process.lookup('gs:Reproject') >>> from geoscript import geom, proj >>> l = Layer() >>> l.add([geom.Point(-125, 50)]) >>> r = p.run(features=l, targetCRS=proj.Projection('epsg:3005')) >>> [f.geom.round() for f in r['result']] [POINT (1071693 554290)] """ # map the inputs to java m = {} for k,v in args.iteritems(): # special case for layer if isinstance(v, Layer): v = v.cursor() m[k] = core.unmap(v) # run the process result = self._process.execute(m, None) # reverse map the outputs back r = {} for k, v in dict(result).iteritems(): r[k] = core.map(v) return r
def __init__(self, name=None, fields=[], ft=None, uri='http://geoscript.org/feature'): self._type = ft if name and fields: # name and fields specified directly, generate gt feature type # from list tb = SimpleFeatureTypeBuilder() tb.setName(NameImpl(name)) tb.setNamespaceURI(uri) for fld in fields: if isinstance(fld, Field): name, typ, prj = fld.name, fld.typ, fld.proj else: name, typ = fld[0], fld[1] prj = None if issubclass(typ, geom.Geometry): # look for srs/crs info if len(fld) > 2: prj = proj.Projection(fld[2]) prj = prj if prj else proj.Projection('EPSG:4326') if prj: tb.crs(prj._crs) # we call unmap() here to avoid setting the type binding to a Python # (eg: PyInteger) type, but rather a native java type (Integer) tb.add(name, core.unmap(typ)) self._type = tb.buildFeatureType() elif ft: # gt feature type specified directly self._type = ft else: raise Exception('No fields specified for feature type.')
def wrapped(*args, **kwargs): # map arguments on way in args = (core.map(a) for a in args) for k in kwargs: kwargs[k] = core.map(kwargs[k]) # unmap on way out # JD: this is a hack but we specify FeatureCollection as a hint to # the mapping to deal with the FeatureCollection/FeatureSource to # Layer mapping issue. In cases where we are not dealing with a layer # like with raster data it should simply be ignored result = f(*args, **kwargs) if isinstance(result, types.GeneratorType): return PyFeatureCollection(result) return core.unmap(result, FeatureCollection)
def run(self, **args): """ Executes the process with set of named inputs. The input argument names are specified by the :attr:`inputs` property. The output arguments names are specified by the :attr:`outputs` property. >>> p = Process.lookup('gs:Reproject') >>> from geoscript import geom, proj >>> l = Layer() >>> l.add([geom.Point(-125, 50)]) >>> r = p.run(features=l, targetCRS=proj.Projection('epsg:3005')) >>> [f.geom.round() for f in r['result'].features()] [POINT (1071693 554290)] """ # map the inputs to java m = dict((k, core.unmap(v, self._params[k].type)) for (k, v) in args.iteritems()) # run the process result = self._process.execute(m, None) # reverse map the outputs back return dict((k, core.map(v)) for (k, v) in dict(result).iteritems())
def run(self, **args): """ Executes the process with set of named inputs. The input argument names are specified by the :attr:`inputs` property. The output arguments names are specified by the :attr:`outputs` property. >>> p = Process.lookup('vec:Reproject') >>> from geoscript import geom, proj >>> l = Layer() >>> l.add([geom.Point(-125, 50)]) >>> r = p.run(features=l, targetCRS=proj.Projection('epsg:3005')) >>> [f.geom.round() for f in r['result'].features()] [POINT (1071693 554290)] """ # map the inputs to java m = dict((k, core.unmap(v, self._params[k].type)) for (k,v) in args.iteritems()) # run the process result = self._process.execute(m, None) # reverse map the outputs back return dict((k, core.map(v)) for (k,v) in dict(result).iteritems())
def _unmap(v, t): return tuple([core.unmap(x, t) for x in v])