Skip to content

Commit

Permalink
Adding the createlayer contrib application, as per GNIP GeoNode#3269
Browse files Browse the repository at this point in the history
  • Loading branch information
capooti committed Sep 7, 2017
1 parent 465c814 commit 6231be0
Show file tree
Hide file tree
Showing 17 changed files with 815 additions and 2 deletions.
51 changes: 51 additions & 0 deletions docs/tutorials/admin/admin_mgmt_commands/index.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,57 @@ Additional options::
-h, --help show this help message and exit


createvectorlayer
=================

Create an empty PostGIS vector layer in GeoNode.

Usage::

python manage.py createvectorlayer name [options]

Additional options::

manage.py createvectorlayer [-h] [--version] [-v {0,1,2,3}]
[--settings SETTINGS]
[--pythonpath PYTHONPATH] [--traceback]
[--no-color] [--user USER]
[--geometry GEOMETRY]
[--attributes ATTRIBUTES] [--title TITLE]
name

Create an empty PostGIS vector layer in GeoNode.

positional arguments:
name

optional arguments:
-h, --help show this help message and exit
--version show program's version number and exit
-v {0,1,2,3}, --verbosity {0,1,2,3}
Verbosity level; 0=minimal output, 1=normal output,
2=verbose output, 3=very verbose output
--settings SETTINGS The Python path to a settings module, e.g.
"myproject.settings.main". If this isn't provided, the
DJANGO_SETTINGS_MODULE environment variable will be
used.
--pythonpath PYTHONPATH
A directory to add to the Python path, e.g.
"/home/djangoprojects/myproject".
--traceback Raise on CommandError exceptions
--no-color Don't colorize the command output.
--user USER Name of the user account which should own the created
layer
--geometry GEOMETRY Geometry type of the layer to be created. Can be
Point, LineString or Polygon. Default is Point
--attributes ATTRIBUTES
A json representation of the attributes to create.
Example: { "field_str": "string", "field_int":
"integer", "field_date": "date", "field_float":
"float"}
--title TITLE Title for the layer to be created.


fixsitename
===========

Expand Down
22 changes: 22 additions & 0 deletions docs/tutorials/users/managing_layers/create.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.. _layers.create:

Creating empty layers
=====================

In GeoNode it is possible to create empty layers, that can be populated with features at a later stage using the mapping client editing tools.

This is possible using the *createlayer* application, which can be enabled if GeoNode is installed with PostGIS.

Once the application is enabled in GeoNode you will be able to create an empty layer by browsing to "Data > Create Layer". You will see a form like this:

.. figure:: img/layer_create.png

Fill the form as needed:

* give a layer name
* give a layer title
* assign a geometry for the layer (Points, Lines, Polygons)
* add as many attributes as needed. For each attribute provide a name and a type. Type can be string, integer, float and date
* assign permissions as needed

Now by clicking the "Create" button your new empty layer should be created.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions docs/tutorials/users/managing_layers/index.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ In this section, you will learn how to create a new layer by uploading a local d
.. toctree::
:maxdepth: 2

upload
upload
info
share
more

create
Empty file.
51 changes: 51 additions & 0 deletions geonode/contrib/createlayer/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# -*- coding: utf-8 -*-
#########################################################################
#
# Copyright (C) 2017 OSGeo
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
#
#########################################################################

from django import forms


GEOMETRY_TYPES = (
('Point', 'Points'),
('LineString', 'Lines'),
('Polygon', 'Polygons'),
)


class NewLayerForm(forms.Form):
"""
A form to create an empty layer in PostGIS.
"""
name = forms.CharField(label='Layer name', max_length=255)
title = forms.CharField(label='Layer title', max_length=255)
geometry_type = forms.ChoiceField(choices=GEOMETRY_TYPES)

permissions = forms.CharField(
widget=forms.HiddenInput(
attrs={
'name': 'permissions',
'id': 'permissions'}),
required=True)

attributes = forms.CharField(
widget=forms.HiddenInput(
attrs={
'name': 'attributes',
'id': 'attributes'}),
required=True)
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# -*- coding: utf-8 -*-
#########################################################################
#
# Copyright (C) 2017 OSGeo
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
#
#########################################################################

from django.core.management.base import BaseCommand

from geonode.people.utils import get_valid_user
from geonode.contrib.createlayer.utils import create_layer


class Command(BaseCommand):
help = "Create an empty PostGIS vector layer in GeoNode."

def add_arguments(self, parser):
# positional arguments
parser.add_argument('name', type=str)
# named (optional arguments)
parser.add_argument('--user',
help='Name of the user account which should own the created layer')
parser.add_argument('--geometry',
default='Point',
help=('Geometry type of the layer to be created. '
'Can be Point, LineString or Polygon. Default is Point')
)
parser.add_argument('--attributes',
help=('A json representation of the attributes to create. '
'Example: '
'{ "field_str": "string", "field_int": "integer", '
'"field_date": "date", "field_float": "float"}')
)
parser.add_argument('--title',
default='No title',
help='Title for the layer to be created.'
)

def handle(self, *args, **options):
name = options.get('name')
username = options.get('user')
user = get_valid_user(username)
title = options.get('title')
geometry_type = options.get('geometry')
attributes = options.get('attributes')
create_layer(name, title, user, geometry_type, attributes)
112 changes: 112 additions & 0 deletions geonode/contrib/createlayer/templates/createlayer/layer_create.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
{% extends "geonode_base.html" %}
{% load url from future %}
{% load i18n %}
{% load bootstrap_tags %}
{% load staticfiles %}

{% block title %} {% trans "Create Layer" %} - {{ block.super }} {% endblock %}

{% block body_class %}layer create{% endblock %}


{% block head %}

{{ block.super }}
{% endblock %}

{% block body_outer %}

<div class="page-header">
<a href="{% url "layer_browse" %}" class="btn btn-primary pull-right">{% trans "Explore Layers" %}</a>
<h2 class="page-title">{% trans "Create an empty layer" %}</h2>
</div>

<div class="row">
<div class="col-md-8">

{% if error %}
<div id="errors" class="alert alert-danger">
<p>{{ error }}</p>
</div>
{% endif %}

<section>
<form id="layer-create-form" method="post" action="{% url "layer_create" %}">
{% csrf_token %}
{{ form|as_bootstrap }}

<div class="input-attrs-wrap">
<button id="add-attr-button" class="add-attr-button btn btn-primary">{% trans "Add Attribute" %}</button>
</div>

<button type="submit" id="layer-create-button" class="btn btn-danger" style="margin-top:20px">{% trans "Create" %}</button>

</form>
</section>

</div>

{% if GEONODE_SECURITY_ENABLED %}
<div class="col-md-4">
<h3>{% trans "Permissions" %}</h3>
<form id="permission_form">
{% include "_permissions.html" %}
</form>
</div>
{% endif %}
</div>
{% endblock %}


{% block extra_script %}

{{ block.super }}

{% if GEONODE_SECURITY_ENABLED %}
{% include "_permissions_form_js.html" %}
{% endif %}

<script type="text/javascript">

// code inspired by https://www.sanwebe.com/2013/03/addremove-input-fields-dynamically-with-jquery
var max_attrs = 50;

var attr_type_select = '<select class="form-control"" \
name="attr-type" style="margin-top:15px"> \
<option value="string">String</option> \
<option value="integer">Integer</option> \
<option value="float">Float</option> \
<option value="date">Date</option> \
</select>'

var x = 1;
$(".add-attr-button").click(function(e){
e.preventDefault();
if(x < max_attrs){
$(".input-attrs-wrap").append('<div class="attr-definition"><input type="text" class="form-control" style="margin-top:15px" />' + attr_type_select + '<a href="#" class="remove-attr">Remove</a></div>');
x++;
}
});

$(".input-attrs-wrap").on("click", ".remove-attr", function(e){
e.preventDefault();
$(this).parent('div').remove();
x--;
})

// copy permissions and attributes
$('#layer-create-form').submit(function(){
$('#permissions').val(JSON.stringify(permissionsString($('#permission_form'),'base')));

var attrs = {};
$('.attr-definition').each(function(i, obj) {
attr_name = obj.childNodes[0].value;
attr_type = obj.childNodes[1].value;
attrs[attr_name] = attr_type;
});
$('#attributes').val(JSON.stringify(attrs));
});

</script>

{% endblock extra_script %}
Loading

0 comments on commit 6231be0

Please sign in to comment.