Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
  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 map() here to avoid setting the type binding to a Python
        # (eg: PyInteger) type, but rather a native java type (Integer)
        tb.add(name, core.map(typ))

      self._type = tb.buildFeatureType()
        
    elif ft:
      # gt feature type specified directly
      self._type = ft
    else:
      raise Exception('No fields specified for feature type.')
Exemplo n.º 3
0
    def __init__(self, name=None, fields=[], ft=None):
        self._type = ft

        if name and fields:
            # name and fields specified directly, generate gt feature type
            # from list
            tb = SimpleFeatureTypeBuilder()
            tb.setName(NameImpl(name))
            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])
                if prj:
                    tb.crs(prj._crs)

                # we call map() here to avoid setting the type binding to a Python
                # (eg: PyInteger) type, but rather a native java type (Integer)
                tb.add(name, core.map(typ))

            self._type = tb.buildFeatureType()

        elif ft:
            # gt feature type specified directly
            self._type = ft
        else:
            raise Exception('No fields specified for feature type.')
Exemplo n.º 4
0
  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
Exemplo n.º 5
0
    def transform(self, obj, dest):
        """
    Transforms an object from this projection to a specified destination projection.

    *obj* is a :class:`Geometry <geoscript.geom.Geometry>` object to transform.

    *dest* is the destination :class:`Projection` to transform to.

     >>> proj = Projection('epsg:4326')
     >>> dest = Projection('epsg:3005')
     >>> import geom
     >>> p1 = geom.Point(-125, 50)
     >>> p2 = proj.transform(p1, dest)
     >>> p2.round()
     POINT (1071693 554290)


    *obj* may also be specified as a single coordinate ``list`` or ``tuple``. *dest* may also be specified as a string identifying the destination projection.

    >>> proj = Projection('epsg:4326')
    >>> p1 = (-125, 50)
    >>> p2 = proj.transform(p1, 'epsg:3005')
    >>> [round(x) for x in p2]
    [1071693.0, 554290.0]
    """
        fromcrs = self._crs
        tocrs = Projection(dest)._crs
        tx = crs.findMathTransform(fromcrs, tocrs)

        if isinstance(obj, (list, tuple)):
            # tuple or list
            import jarray
            transformed = jarray.zeros(len(obj), 'd')
            tx.transform(obj, 0, transformed, 0, 1)
            l = [transformed[x] for x in range(len(obj))]
            return l if isinstance(obj, list) else tuple(l)
        else:
            # geometry
            gt = GeometryTX()
            gt.mathTransform = tx

            return core.map(gt.transform(obj))
Exemplo n.º 6
0
  def transform(self, obj, dest):
    """
    Transforms an object from this projection to a specified destination projection.

    *obj* is a :class:`Geometry <geoscript.geom.Geometry>` object to transform.

    *dest* is the destination :class:`Projection` to transform to.

     >>> proj = Projection('epsg:4326')
     >>> dest = Projection('epsg:3005')
     >>> import geom
     >>> p1 = geom.Point(-125, 50)
     >>> p2 = proj.transform(p1, dest)
     >>> p2.round()
     POINT (1071693 554290)


    *obj* may also be specified as a single coordinate ``list`` or ``tuple``. *dest* may also be specified as a string identifying the destination projection.

    >>> proj = Projection('epsg:4326')
    >>> p1 = (-125, 50)
    >>> p2 = proj.transform(p1, 'epsg:3005')
    >>> [round(x) for x in p2]
    [1071693.0, 554290.0]
    """
    fromcrs = self._crs
    tocrs = Projection(dest)._crs
    tx = crs.findMathTransform(fromcrs,tocrs)

    if isinstance(obj, (list,tuple)):
      # tuple or list
      import jarray
      transformed = jarray.zeros(len(obj), 'd')
      tx.transform(obj, 0, transformed, 0, 1)
      l = [transformed[x] for x in range(len(obj))]
      return l if isinstance(obj, list) else tuple(l)
    else:
      # geometry
      gt = GeometryTX()
      gt.mathTransform = tx

      return core.map(gt.transform(obj))
Exemplo n.º 7
0
  def get(self, name):
    """
    Returns the :class:`Field` of a specific name or ``None`` if no such attribute exists in the schema.
 
    *name* is the name of the field as a ``str``.

    >>> s = Schema('widgets', [('name', str), ('price', float)])
    >>> s.get('price')
    price: float
    """

    ad = self._type.getDescriptor(name)
    if ad:
      att = Field(ad.localName, core.map(ad.type.binding))
      if isinstance(ad, GeometryDescriptor) and ad.coordinateReferenceSystem:
        att.proj = proj.Projection(ad.coordinateReferenceSystem)

      return att

    raise KeyError('No such field "%s"' % name)
Exemplo n.º 8
0
    def get(self, name):
        """
    Returns the :class:`Field` of a specific name or ``None`` if no such attribute exists in the schema.
 
    *name* is the name of the field as a ``str``.

    >>> s = Schema('widgets', [('name', str), ('price', float)])
    >>> s.field('price')
    price: float
    """

        ad = self._type.getDescriptor(name)
        if ad:
            att = Field(ad.localName, core.map(ad.type.binding))
            if isinstance(ad,
                          GeometryDescriptor) and ad.coordinateReferenceSystem:
                att.proj = proj.Projection(ad.coordinateReferenceSystem)

            return att

        raise KeyError('No such field "%s"' % name)
Exemplo n.º 9
0
    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())
Exemplo n.º 10
0
  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())
Exemplo n.º 11
0
def _params(m):
  d = {}
  for k,v in dict(m).iteritems():
     d[k] = (v.name, core.map(v.type), v.description)
  return d 
Exemplo n.º 12
0
 def wrapped(inserted, req, context):
     return f(core.map(inserted), req, context)
Exemplo n.º 13
0
 def wrapped(deleted, req, context):
     return f(core.map(deleted), req, context)
Exemplo n.º 14
0
 def wrapped(updated, props, req, context):
     return f(core.map(updated),
              dict(props) if props is not None else {}, req, context)
Exemplo n.º 15
0
def _params(m):
  d = {}
  for k,v in dict(m).iteritems():
     d[k] = (v.name, core.map(v.type), v.description)
  return d 
Exemplo n.º 16
0
 def values(self):
   return [core.map(val) for val in self._feature.getAttributes()]
Exemplo n.º 17
0
 def wrapped(updated, props, req, context):
   return f(core.map(updated), dict(props), req, context)
Exemplo n.º 18
0
 def getgeom(self):
     return core.map(self._feature.defaultGeometry)
Exemplo n.º 19
0
 def values(self):
     return [core.map(val) for val in self._feature.getAttributes()]
Exemplo n.º 20
0
    def getattributes(self):
        atts = {}
        for fld in self.schema.fields:
            atts[fld.name] = core.map(self._feature.getAttribute(fld.name))

        return atts
Exemplo n.º 21
0
 def wrapped(updated, props, req, context):
     return f(core.map(updated), dict(props), req, context)
Exemplo n.º 22
0
 def wrapped(deleted, req, context):
   return f(core.map(deleted), req, context)
Exemplo n.º 23
0
  def getattributes(self):
    atts = {}
    for fld in self.schema.fields:
      atts[fld.name] = core.map(self._feature.getAttribute(fld.name))

    return atts
Exemplo n.º 24
0
 def wrapped(inserted, req, context):
   return f(core.map(inserted), req, context)
Exemplo n.º 25
0
 def getgeom(self):
   return core.map(self._feature.defaultGeometry)
Exemplo n.º 26
0
 def wrapped(updated, props, req, context):
   return f(core.map(updated),  dict(props) if props is not None else {}, req, context)