Beispiel #1
0
Datei: io.py Projekt: sabman/riab
def get_metadata(server_url, layer_name):
    """Uses OWS services to get the metadata for a given layer
    """
    #FIXME: Make sure server_url is an actual url
    themetadata = get_layers_metadata(server_url, version='1.0.0')

    layer_metadata = None
    for x in themetadata:
        # This is taking care of differences between wcs and wfs layers
        # wfs has a preceding workspace but wcs does not.
        if ':' in x[0]:
            x_layer_name = x[0].split(':')[1]
        else:
            x_layer_name = x[0]

        if ':' in layer_name:
            plain_layer_name = layer_name.split(':')[1]
        else:
            plain_layer_name = layer_name

        if x_layer_name == plain_layer_name:
            # We expect only one element in this list, if there is more
            # than one, we will use the first one.
            layer_metadata = x[1]
            break

    msg = 'There is no metadata in server %s for layer %s' % (server_url, layer_name)
    assert layer_metadata is not None, msg

    # FIXME: We need a geotransform attribute in get_metadata
    # Let's add it here for the time being

    return layer_metadata
Beispiel #2
0
    def test_plugin_compatability(self):
        """Performance of the default plugins using internal GeoServer
        """

        plugin_list = get_plugins()
        assert len(plugin_list) > 0

        geoserver = {'url': settings.GEOSERVER_BASE_URL + 'ows',
                     'name': 'Local Geoserver',
                     'version': '1.0.0',
                     'id': 0}
        layers = get_layers_metadata(geoserver['url'],
                                     geoserver['version'])

        msg = 'There were no layers in test geoserver'
        assert len(layers) > 0, msg

        annotated_plugins = [{'name': name,
                              'doc': f.__doc__,
                              'layers': compatible_layers(f, layers)}
                             for name, f in plugin_list.items()]

        msg = 'No compatible layers returned'
        assert len(annotated_plugins) > 0, msg
Beispiel #3
0
    def test_layer_upload(self):
        """Layers can be uploaded to local GeoNode
        """

        expected_layers = []
        not_expected_layers = []
        datadir = TEST_DATA
        BAD_LAYERS = ['grid_without_projection.asc']

        for root, dirs, files in os.walk(datadir):
            for filename in files:
                basename, extension = os.path.splitext(filename)

                if extension.lower() in LAYER_TYPES:

                    # FIXME(Ole): GeoNode converts names to lower case
                    name = unicode(basename.lower())
                    if filename not in BAD_LAYERS:
                        expected_layers.append(name)
                    else:
                        not_expected_layers.append(name)

        # Upload
        layers = save_to_geonode(datadir, user=self.user, overwrite=True)

        # Check integrity
        layer_names = [l.name for l in layers]

        for layer in layers:
            msg = 'Layer %s was uploaded but not expected' % layer.name
            assert layer.name in expected_layers, msg

        for layer_name in expected_layers:
            msg = ('The following layer should have been uploaded '
                   'but was not: %s' % layer_name)
            assert layer_name in layer_names, msg

            # Check the layer is in the Django database
            Layer.objects.get(name=layer_name)

            # Check that layer is in geoserver
            found = False
            gs_username, gs_password = settings.GEOSERVER_CREDENTIALS
            page = get_web_page(os.path.join(settings.GEOSERVER_BASE_URL,
                                             'rest/layers'),
                                             username=gs_username,
                                             password=gs_password)
            for line in page:
                if line.find('rest/layers/%s.html' % layer_name) > 0:
                    found = True
            if not found:
                msg = ('Upload could not be verified, the layer %s is not '
                   'in geoserver %s, but GeoNode did not raise any errors, '
                   'this should never happen.' %
                   (layer_name, settings.GEOSERVER_BASE_URL))
                raise GeoNodeException(msg)

        server_url = settings.GEOSERVER_BASE_URL + 'ows?'

        # Verify that the GeoServer GetCapabilities record is accesible:
        metadata = get_layers_metadata(server_url, '1.0.0')
        msg = ('The metadata list should not be empty in server %s'
                % server_url)
        assert len(metadata) > 0, msg