def __init__(self, file, schema=None): f = util.toFile(file) name = path.splitext(path.basename(file))[0] from geoscript.workspace import Directory Layer.__init__(self, name, Directory(f.canonicalFile.parent), schema=schema)
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)
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)
def get(self, name): """ Returns a :class:`Layer geoscript.layer.layer.Layer` in the workspace. This method raised ``KeyError`` if the layer does not exist. *name* is the name of a layer to return. >>> ws = Workspace() >>> try: ... ws.get('foo') ... raise Exception('Should not get here') ... except KeyError: ... pass >>> x = ws.create('foo') >>> l = ws.get('foo') >>> str(l.name) 'foo' """ if name in self.layers(): fs = self._store.getFeatureSource(name) return Layer(workspace=self, fs=fs) raise KeyError('No such layer "%s"' % name)
def __init__(self, file): f = util.toFile(file) name = path.splitext(path.basename(file))[0] from geoscript.workspace import Directory Layer.__init__(self, name, Directory(f.canonicalFile.parent))
f = open(config_file_name, 'r') config = json.load(f) # Create the workspaces in_ws = Directory(shp_dir) output_dir = out_file if not os.path.isdir(output_dir): os.mkdir(output_dir) out_ws = Directory(output_dir) mem_ws = Memory() # Show the layers are about to merge print in_ws.layers() # Init the output layer epsg4326 = Projection('epsg:4326') schema = Schema(out_file, [ ('geom', getattr(geoscript.geom, config['geomtype']), epsg4326), ('type', str), ('name', str), ('agency', str) ]) out_layer = Layer(schema=schema) try: out_layer = merge_shapefiles(config, out_layer) # Write it to the shape file out_ws.add(out_layer) except Exception, e: sys.stderr.write("Error saving. Try deleting output files and re-run?\n") sys.stderr.write("Error was: %s\n" % e) sys.exit(1) print "Output is in %s" % os.path.join(output_dir, out_file + '.shp')