예제 #1
0
    def create(self,
               name=None,
               fields=[('geom', geom.Geometry, 'epsg:4326')],
               schema=None):
        """
     Creates a new :class:`Layer geoscript.layer.layer.Layer` in the workspace.
   
     *name* is the optional name to assign to the new layer.

     *fields* is an optional ``list`` of ``str``/``type`` tuples which define th e schema of the new layer.

     *schema* is the optional :class:`Schema <geoscript.feature.Schema>` of the new layer.

     **Note**: When the *schema* argument is specified neither of *name* or *fields* should be specified.

     >>> from geoscript import geom
     >>> ws = Workspace()
     >>> l1 = ws.create('foo', [('geom', geom.Point)])
     >>> ws.layers()
     ['foo']

     >>> from geoscript.feature import Schema
     >>> l2 = ws.create(schema=Schema('bar', [('geom', geom.Point)]))
     >>> ws.layers()
     ['bar', 'foo']
     """

        if not name:
            name = schema.name if schema else Layer._newname()

        if schema:
            schema = feature.Schema(name, schema.fields)

        try:
            self.get(name)
            raise Exception('Layer %s already exists.' % (name))
        except KeyError:
            pass

        schema = schema or feature.Schema(name, fields)
        self._store.createSchema(schema._type)
        return self.get(name)
예제 #2
0
  def create(self, name=None, fields=[('geom', geom.Geometry,'epsg:4326')], schema=None):
     """
     Creates a new :class:`Layer geoscript.layer.layer.Layer` in the workspace.
   
     *name* is the optional name to assign to the new layer.

     *fields* is an optional ``list`` of ``str``/``type`` tuples which define th e schema of the new layer.

     *schema* is the optional :class:`Schema <geoscript.feature.Schema>` of the new layer.

     **Note**: When the *schema* argument is specified neither of *name* or *fields* should be specified.

     >>> from geoscript import geom
     >>> ws = Workspace()
     >>> l1 = ws.create('foo', [('geom', geom.Point)])
     >>> ws.layers()
     ['foo']

     >>> from geoscript.feature import Schema
     >>> l2 = ws.create(schema=Schema('bar', [('geom', geom.Point)]))
     >>> ws.layers()
     ['foo', 'bar']
     """
 
     if not name:
       name = schema.name if schema else Layer._newname()

     if schema:
       schema = feature.Schema(name, schema.fields)

     try:
       self.get(name)
       raise Exception('Layer %s already exists.' % (name))
     except KeyError:
       pass

     schema = schema or feature.Schema(name, fields)
     self._store.createSchema(schema._type) 
     return self.get(name)