forked from GeoNode/geonode
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding the createlayer contrib application, as per GNIP GeoNode#3269
- Loading branch information
Showing
17 changed files
with
815 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
59 changes: 59 additions & 0 deletions
59
geonode/contrib/createlayer/management/commands/createvectorlayer.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
112
geonode/contrib/createlayer/templates/createlayer/layer_create.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %} |
Oops, something went wrong.