How to use the geonode.geoserver.helpers.ogc_server_settings function in GeoNode

To help you get started, we’ve selected a few GeoNode examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github MapStory / mapstory / mapstory / importer / tests.py View on Github external
def setUp(self):

        if not os.path.exists(os.path.join(os.path.split(__file__)[0], 'test_ogr')):
            self.skipTest('Skipping test due to missing test data.')

        # These tests require geonode to be running on :80!
        self.postgis = db.connections['datastore']
        self.postgis_settings = self.postgis.settings_dict

        self.username, self.password = self.create_user('admin', 'admin', is_superuser=True)
        self.non_admin_username, self.non_admin_password = self.create_user('non_admin', 'non_admin')
        self.cat = Catalog(ogc_server_settings.internal_rest, *ogc_server_settings.credentials)
        self.workspace = 'geonode'
        self.datastore = self.create_datastore(self.postgis, self.cat)
github cga-harvard / worldmap / wm_extra / views.py View on Github external
@csrf_exempt
def proxy(request):
    PROXY_ALLOWED_HOSTS = getattr(settings, 'PROXY_ALLOWED_HOSTS', ())

    host = None

    if 'geonode.geoserver' in settings.INSTALLED_APPS:
        from geonode.geoserver.helpers import ogc_server_settings
        hostname = (ogc_server_settings.hostname,) if ogc_server_settings else ()
        PROXY_ALLOWED_HOSTS += hostname
        host = ogc_server_settings.netloc

    if 'url' not in request.GET:
        return HttpResponse("The proxy service requires a URL-encoded URL as a parameter.",
                            status=400,
                            content_type="text/plain"
                            )

    raw_url = request.GET['url']
    url = urlsplit(raw_url)
    locator = str(url.path)
    if url.query != "":
        locator += '?' + url.query
    if url.fragment != "":
        locator += '#' + url.fragment
github MapStory / mapstory / mapstory / management / commands / automatic_layer_fixes.py View on Github external
def handle(self, *args, **options):

        rest_url = ogc_server_settings.rest
        rest_user = ogc_server_settings.credentials.username
        rest_pass = ogc_server_settings.credentials.password
        dry_run = options['dry-run']
        gs = Catalog(rest_url, rest_user, rest_pass)
        layers = gs.get_layers()

        if options['layer_list'] is not None:
            layers = options['layer_list'].split(',')

        unfixable = []
        valid = []

        def add_unfixable(layer_name, reason):
            layer = {'name': layer_name,
                     'error': reason}
            unfixable.append(layer)
github GeoNode / geonode / geonode / utils.py View on Github external
if (Link.objects.filter(resource=instance.resourcebase_ptr,
                                        url=wfs_url,
                                        name=name).count() < 2):
                    Link.objects.update_or_create(
                        resource=instance.resourcebase_ptr,
                        url=wfs_url,
                        name=name,
                        link_type='data',
                        defaults=dict(
                            extension=ext,
                            mime=mime,
                        )
                    )

        elif instance.storeType == 'coverageStore':
            links = wcs_links(ogc_server_settings.public_url + 'wcs?',
                              instance.alternate.encode('utf-8'),
                              bbox,
                              srid)

        for ext, name, mime, wcs_url in links:
            if (Link.objects.filter(resource=instance.resourcebase_ptr,
                                    url=wcs_url,
                                    name=name).count() < 2):
                Link.objects.update_or_create(
                    resource=instance.resourcebase_ptr,
                    url=wcs_url,
                    name=name,
                    link_type='data',
                    defaults=dict(
                        extension=ext,
                        mime=mime,
github GeoNode / geonode / geonode / contrib / dynamic / models.py View on Github external
from django.conf import settings
from django.contrib.gis.utils import LayerMapping
from django.contrib.gis.db import models
from django.contrib.gis import admin
from django.core.exceptions import ValidationError
from django import db

from geonode.layers.models import Layer
from geonode.geoserver.helpers import ogc_server_settings

from .postgis import file2pgtable

datastore_name = settings.OGC_SERVER['default']['DATASTORE']
DYNAMIC_DATASTORE = datastore_name if datastore_name != '' else 'datastore'

has_datastore = True if len(ogc_server_settings.datastore_db.keys()) > 0 else False


class ModelDescription(models.Model):
    name = models.CharField(max_length=255)
    layer = models.ForeignKey(Layer, null=True, blank=True)

    def get_django_model(self, with_admin=False):
        "Returns a functional Django model based on current data"
        # Get all associated fields into a list ready for dict()
        fields = [(f.name, f.get_django_field()) for f in self.fields.all()]

        # Use the create_model function defined above
        return create_model(self.name, dict(fields),
                            app_label='dynamic',
                            module='geonode.contrib.dynamic',
                            options={'db_table': self.name,
github GeoNode / geonode / geonode / upload / upload_validators.py View on Github external
def validate_uploaded_files(cleaned, uploaded_files, field_spatial_types):
    logger.info("uploaded_files: {}".format(uploaded_files))
    requires_datastore = () if ogc_server_settings.DATASTORE else (
        'csv',
        'kml')
    types = [t for t in files.types if t.code not in requires_datastore]
    base_ext = os.path.splitext(cleaned["base_file"].name)[-1].lower()[1:]
    if not _supported_type(base_ext, types) and base_ext.lower() != "zip":
        raise forms.ValidationError(
            "%(supported)s files are supported. You uploaded a "
            "%(uploaded)s file",
            params={
                "supported": " , ".join([t.name for t in types]),
                "uploaded": base_ext
            }
        )
    elif base_ext.lower() == "zip":
        if not zipfile.is_zipfile(cleaned["base_file"]):
            raise forms.ValidationError(_("Invalid zip file detected"))
github GeoNode / geonode / geonode / geoserver / createlayer / utils.py View on Github external
xml = (""
           "{name}"
           "{native_name}"
           "<title>{title}</title>"
           "EPSG:4326"
           "{minx}{maxx}{miny}{maxy}"
           "EPSG:4326"
           "{attributes}"
           "").format(
        name=name.encode('UTF-8', 'strict'), native_name=native_name.encode('UTF-8', 'strict'),
        title=title.encode('UTF-8', 'strict'),
        minx=BBOX[0], maxx=BBOX[1], miny=BBOX[2], maxy=BBOX[3],
        attributes=attributes_block)

    url = ('%s/workspaces/%s/datastores/%s/featuretypes'
           % (ogc_server_settings.rest, workspace.name, datastore.name))
    headers = {'Content-Type': 'application/xml'}
    _user, _password = ogc_server_settings.credentials
    req = requests.post(url, data=xml, headers=headers, auth=(_user, _password))
    if req.status_code != 201:
        logger.error('Request status code was: %s' % req.status_code)
        logger.error('Response was: %s' % req.text)
        raise GeoNodeException("Layer could not be created in GeoServer")

    return workspace, datastore
github GeoNode / geonode / geonode / contrib / dynamic / postgis.py View on Github external
#
# Opencarto is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with Opencarto.  If not, see .
#
from django import db
from django.contrib.gis.gdal import DataSource, SpatialReference, OGRGeometry
from django.utils.text import slugify

from geonode.geoserver.helpers import ogc_server_settings

has_datastore = True if len(ogc_server_settings.datastore_db.keys()) &gt; 0 else False


def get_model_field_name(field):
    """Get the field name usable without quotes.
    """
    # Remove spaces and strange characters.
    field = slugify(field)

    # Use underscores instead of dashes.
    field = field.replace('-', '_')

    # Use underscores instead of semicolons.
    field = field.replace(':', '_')

    # Do not let it be called id
    if field in ('id',):
github GeoNode / geonode / geonode / geoserver / views.py View on Github external
request,
                'layers/layer_style_manage.html',
                context={
                    "layer": layer,
                    "gs_styles": gs_styles,
                    "layer_styles": layer_styles,
                    "layer_style_names": [s[0] for s in layer_styles],
                    "default_style": default_style
                }
            )
        except (FailedRequestError, EnvironmentError):
            tb = traceback.format_exc()
            logger.debug(tb)
            msg = ('Could not connect to geoserver at "%s"'
                   'to manage style information for layer "%s"' % (
                       ogc_server_settings.LOCATION, layer.name)
                   )
            logger.debug(msg)
            # If geoserver is not online, return an error
            return render(
                request,
                'layers/layer_style_manage.html',
                context={
                    "layer": layer,
                    "error": msg
                }
            )
    elif request.method in ('POST', 'PUT', 'DELETE'):
        try:
            selected_styles = request.POST.getlist('style-select')

            default_style = request.POST['default_style']
github MapStory / mapstory / mapstory / storylayers / views.py View on Github external
def layer_append_minimal(source, target, request_cookies):
    """
    The main layer_append logic that can run outside of a request.
    """
    source = 'geonode:' + source

    def chunk_list(list, chunk_size):
        """Yield successive chunk_size chunks from list."""
        for i in xrange(0, len(list), chunk_size):
            yield list[i:i+chunk_size]

    # TODO: use the provided column to decide which features should be updated and which should be created
    # join_on_attribute = json.loads(request.POST.get(u'joinOnAttributeName', 'false'))

    get_features_request = requests.post(
        '{}/wfs?service=wfs&amp;version=2.0.0&amp;request=GetFeature&amp;typeNames={}'.format(ogc_server_settings.public_url,
                                                                                  source),
        auth=ogc_server_settings.credentials
    )

    if has_exception(get_features_request.content):
        raise AssertionError(
            'Failed to get features from source layer: {0}'.format(source))

    # the response to getfeatures will look like the following. We want everything between first  and last 
    # 
    #     
    #         
    #             
    #                 
    #                     14.101186235070415 -87.19960869178765
    #