Ejemplo n.º 1
0
def check_projection(name, resource):
    # Get a short handle to the gsconfig geoserver catalog
    cat = Layer.objects.gs_catalog

    try:
        if resource.latlon_bbox is None:
            box = resource.native_bbox[:4]
            minx, maxx, miny, maxy = [float(a) for a in box]
            if -180 <= minx <= 180 and -180 <= maxx <= 180 and\
               -90  <= miny <= 90  and -90  <= maxy <= 90:
                logger.warn('GeoServer failed to detect the projection for layer '
                            '[%s]. Guessing EPSG:4326', name)
                # If GeoServer couldn't figure out the projection, we just
                # assume it's lat/lon to avoid a bad GeoServer configuration

                resource.latlon_bbox = resource.native_bbox
                resource.projection = "EPSG:4326"
                cat.save(resource)
            else:
                msg = ((_('GeoServer failed to detect the projection for layer ') + 
                       '[%s].' + 
                       _('It doesn\'t look like EPSG:4326, so backing out the layer.')) % name)
                logger.warn(msg, name)
                cascading_delete(cat, resource)
                raise GeoNodeException(msg % name)
    except:
        msg = ((_('GeoServer failed to read the layer projection for') + ' [%s] ' + 
               _('so backing out the layer.')) % name)
        cascading_delete(cat, resource)
        raise GeoNodeException(msg % name)
    def test_cascading_delete(self):
        """Verify that the gs_helpers.cascading_delete() method is working properly
        """
        gs_cat = Layer.objects.gs_catalog

        # Upload a Shapefile
        shp_file = os.path.join(TEST_DATA, "lembang_schools.shp")
        shp_layer = file_upload(shp_file)

        # Save the names of the Resource/Store/Styles
        resource_name = shp_layer.resource.name
        store = shp_layer.resource.store
        store_name = store.name
        layer = gs_cat.get_layer(resource_name)
        styles = layer.styles + [layer.default_style]

        # Delete the Layer using cascading_delete()
        cascading_delete(gs_cat, shp_layer.resource)

        # Verify that the styles were deleted
        for style in styles:
            s = gs_cat.get_style(style)
            assert s == None

        # Verify that the resource was deleted
        self.assertRaises(FailedRequestError, lambda: gs_cat.get_resource(resource_name, store=store))

        # Verify that the store was deleted
        self.assertRaises(FailedRequestError, lambda: gs_cat.get_store(store_name))

        # Clean up by deleting the layer from GeoNode's DB and GeoNetwork
        shp_layer.delete()
Ejemplo n.º 3
0
def check_projection(name, resource):
    # Get a short handle to the gsconfig geoserver catalog
    cat = Layer.objects.gs_catalog

    try:
        if resource.latlon_bbox is None:
            box = resource.native_bbox[:4]
            minx, maxx, miny, maxy = [float(a) for a in box]
            if -180 <= minx <= 180 and -180 <= maxx <= 180 and\
               -90  <= miny <= 90  and -90  <= maxy <= 90:
                logger.warn('GeoServer failed to detect the projection for layer '
                            '[%s]. Guessing EPSG:4326', name)
                # If GeoServer couldn't figure out the projection, we just
                # assume it's lat/lon to avoid a bad GeoServer configuration

                resource.latlon_bbox = resource.native_bbox
                resource.projection = "EPSG:4326"
                cat.save(resource)
            else:
                msg = ((_('GeoServer failed to detect the projection for layer ') + 
                       '[%s].' + 
                       _('It doesn\'t look like EPSG:4326, so backing out the layer.')))
                logger.warn(msg, name)
                cascading_delete(cat, resource)
                raise GeoNodeException(msg % name)
    except:
        msg = ((_('GeoServer failed to read the layer projection for') + ' [%s] ' + 
               _('so backing out the layer.')))
        cascading_delete(cat, resource)
        raise GeoNodeException(msg % name)
Ejemplo n.º 4
0
    if gs_resource.latlon_bbox is None:
        box = gs_resource.native_bbox[:4]
        minx, maxx, miny, maxy = [float(a) for a in box]
        if -180 <= minx <= 180 and -180 <= maxx <= 180 and \
           -90  <= miny <= 90  and -90  <= maxy <= 90:
            logger.warn('GeoServer failed to detect the projection for layer [%s]. Guessing EPSG:4326', name)
            # If GeoServer couldn't figure out the projection, we just
            # assume it's lat/lon to avoid a bad GeoServer configuration

            gs_resource.latlon_bbox = gs_resource.native_bbox
            gs_resource.projection = "EPSG:4326"
            cat.save(gs_resource)
        else:
            msg = "GeoServer failed to detect the projection for layer [%s]. It doesn't look like EPSG:4326, so backing out the layer."
            logger.warn(msg, name)
            cascading_delete(cat, gs_resource)
            raise GeoNodeException(msg % name)

    # Step 7. Create the style and assign it to the created resource
    # FIXME: Put this in gsconfig.py
    logger.info('>>> Step 7. Creating style for [%s]' % name)
    publishing = cat.get_layer(name)

    if 'sld' in files:
        f = open(files['sld'], 'r')
        sld = f.read()
        f.close()
    else:
        sld = get_sld_for(publishing)

    if sld is not None:
Ejemplo n.º 5
0
        if -180 <= minx <= 180 and -180 <= maxx <= 180 and \
           -90  <= miny <= 90  and -90  <= maxy <= 90:
            logger.warn('GeoServer failed to detect the projection for layer '
                        '[%s]. Guessing EPSG:4326', name)
            # If GeoServer couldn't figure out the projection, we just
            # assume it's lat/lon to avoid a bad GeoServer configuration

            gs_resource.latlon_bbox = gs_resource.native_bbox
            gs_resource.projection = "EPSG:4326"
            cat.save(gs_resource)
        else:
            msg = ('GeoServer failed to detect the projection for layer '
                   '[%s]. It doesn\'t look like EPSG:4326, so backing out '
                   'the layer.')
            logger.warn(msg, name)
            cascading_delete(cat, gs_resource)
            raise GeoNodeException(msg % name)

    # Step 7. Create the style and assign it to the created resource
    # FIXME: Put this in gsconfig.py
    logger.info('>>> Step 7. Creating style for [%s]' % name)
    publishing = cat.get_layer(name)

    if 'sld' in files:
        f = open(files['sld'], 'r')
        sld = f.read()
        f.close()
    else:
        sld = get_sld_for(publishing)

    if sld is not None: