Ejemplo n.º 1
0
  def addList(self, featureList):
    if self.readonly:
      raise Exception('Layer is read-only')

    fc = FeatureCollections.newCollection() 

    for o in featureList:
      if isinstance(o, feature.Feature):
        f = o
        if not f.schema:
          f.schema = self.schema
      elif isinstance(o, (dict,list)):
        f = self.schema.feature(o)
        
      fc.add(f._feature)

    trans = DefaultTransaction("ex")
    self._source.setTransaction(trans)
    try:
      self._source.addFeatures(fc)
      trans.commit()
      trans.close()
    except:
      print 'Exception', sys.exc_info()[2]
      print sys.exc_info()
      traceback.print_stack()
      print repr(traceback.extract_stack())
      print repr(traceback.format_stack())
      trans.rollback()
Ejemplo n.º 2
0
  def add(self, o):
    """
    Adds a :class:`Feature <geoscript.feature.Feature>` to the layer.

    *o* is the feature to add. It may be specified directly as a Feature object or alternatively as a ``dict`` 
    or a ``list``.

    >>> from geoscript import geom
    >>> from geoscript import feature
    >>> l = Layer() 
    >>> l.count()
    0
    >>> f = feature.Feature({'geom': geom.Point(1,2)})
    >>> l.add(f)
    >>> l.count()
    1
    >>> l = Layer()
    >>> l.add({'geom': geom.Point(1,2)})
    >>> l.add([geom.Point(1,2)])
    >>> l.count()
    2
    """
    if self.readonly:
      raise Exception('Layer is read-only')

    if isinstance(o, Layer):
      for f in o.features():
        self.add(f)
      return

    if isinstance(o, feature.Feature):
      f = o
      if not f.schema:
        f.schema = self.schema
    elif isinstance(o, (dict,list)):
      f = self.schema.feature(o)
      
    fc = FeatureCollections.newCollection() 
    fc.add(f._feature)
    self._source.addFeatures(fc)
Ejemplo n.º 3
0
    def add(self, o):
        """
    Adds a :class:`Feature <geoscript.feature.Feature>` to the layer.

    *o* is the feature to add. It may be specified directly as a Feature object or alternatively as a ``dict`` 
    or a ``list``.

    >>> from geoscript import geom
    >>> from geoscript import feature
    >>> l = Layer() 
    >>> l.count()
    0
    >>> f = feature.Feature({'geom': geom.Point(1,2)})
    >>> l.add(f)
    >>> l.count()
    1
    >>> l = Layer()
    >>> l.add({'geom': geom.Point(1,2)})
    >>> l.add([geom.Point(1,2)])
    >>> l.count()
    2
    """
        if self.readonly:
            raise Exception('Layer is read-only')

        if isinstance(o, Layer):
            for f in o.features():
                self.add(f)
            return

        if isinstance(o, feature.Feature):
            f = o
            if not f.schema:
                f.schema = self.schema
        elif isinstance(o, (dict, list)):
            f = self.schema.feature(o)

        fc = FeatureCollections.newCollection()
        fc.add(f._feature)
        self._source.addFeatures(fc)