예제 #1
0
  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)
예제 #2
0
    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')