-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic version of WorldMap GeoNode unforked version with working maps
- Loading branch information
Showing
1,108 changed files
with
182,719 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Empty file.
193 changes: 193 additions & 0 deletions
193
geonode/contrib/worldmap/gazetteer/fixtures/gazetteer_data.json
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,193 @@ | ||
[ { | ||
"fields": { | ||
"date_joined": "2010-07-20 13:31:27", | ||
"email": "[email protected]", | ||
"first_name": "", | ||
"groups": [], | ||
"is_active": true, | ||
"is_staff": true, | ||
"is_superuser": true, | ||
"last_login": "2010-07-20 17:26:12", | ||
"last_name": "", | ||
"password": "sha1$6c974$de67ee46336cb3b9bb9e90d53863c3a8d01ce944", | ||
"user_permissions": [], | ||
"username": "admin" | ||
}, | ||
"model": "auth.user", | ||
"pk": 1 | ||
}, | ||
{ | ||
"fields": { | ||
"typename": "base:CA1", | ||
"store": "CA1", | ||
"name": "CA1", | ||
"workspace": "base", | ||
"llbbox" : ["1", "3", "2", "3"], | ||
"srs": "EPSG:4326", | ||
"geographic_bounding_box": "whatever", | ||
"uuid": "254afb8e-5a5f-4c1f-b01b-40af91532298", | ||
"created_dttm": "2010-07-20 13:31:27", | ||
"last_modified": "2010-07-20 13:31:27" | ||
}, | ||
"model": "maps.layer", | ||
"pk": 1 | ||
}, | ||
{ | ||
"fields": { | ||
"typename": "base:CA2", | ||
"store": "CA2", | ||
"name": "CA2", | ||
"workspace": "base", | ||
"llbbox" : ["1", "3", "2", "3"], | ||
"srs": "EPSG:4326", | ||
"geographic_bounding_box": "whatever", | ||
"uuid": "254afb8e-5a5f-4c1f-b01b-40af91532299", | ||
"created_dttm": "2013-07-20 13:31:27", | ||
"last_modified": "2013-07-20 13:31:27" | ||
}, | ||
"model": "maps.layer", | ||
"pk": 2 | ||
}, | ||
{ | ||
"fields": { | ||
"abstract": "This is a demonstration of GeoNode, an application for assembling and publishing web based maps. After adding layers to the map, use the Save Map button above to contribute your map to the GeoNode community.", | ||
"center_x": -9428760.8701902702, | ||
"center_y": 1427430.7410345681, | ||
"owner": 1, | ||
"projection": "EPSG:900913", | ||
"title": "GeoNode Default Map", | ||
"last_modified": "2010-07-20 13:31:27", | ||
"zoom": 7, | ||
"created_dttm": "2010-07-20 13:31:27" | ||
}, | ||
"model": "maps.map", | ||
"pk": 1 | ||
}, | ||
{ | ||
"fields": { | ||
"fixed": false, | ||
"group": "background", | ||
"layer_params": "", | ||
"map": 1, | ||
"name": "base:CA1", | ||
"ows_url": "http://localhost:8001/geoserver/wms", | ||
"source_params": "", | ||
"stack_order": 0, | ||
"created_dttm": "2010-07-20 13:31:27", | ||
"last_modified": "2010-07-20 13:31:27" | ||
}, | ||
"model": "maps.maplayer", | ||
"pk": 1 | ||
}, | ||
{ | ||
"fields": { | ||
"fixed": false, | ||
"group": "background", | ||
"layer_params": "", | ||
"map": 1, | ||
"name": "base:CA2", | ||
"ows_url": "http://localhost:8001/geoserver/wms", | ||
"source_params": "", | ||
"stack_order": 0, | ||
"created_dttm": "2010-07-20 13:31:27", | ||
"last_modified": "2010-07-20 13:31:27" | ||
}, | ||
"model": "maps.maplayer", | ||
"pk": 2 | ||
}, | ||
{ | ||
"fields": { | ||
"layer_name": "CA1", | ||
"layer_attribute": "field1", | ||
"feature_type": "POINT", | ||
"feature_fid": 121, | ||
"latitude": 40, | ||
"longitude": -70, | ||
"place_name": "Paradise1", | ||
"start_date": "2010-07-20", | ||
"end_date": "2012-07-20", | ||
"julian_start": 2455398, | ||
"julian_end": 2456129, | ||
"project": "test", | ||
"feature": null | ||
}, | ||
"model": "gazetteer.GazetteerEntry", | ||
"pk": 1 | ||
}, | ||
{ | ||
"fields": { | ||
"layer_name": "CA1", | ||
"layer_attribute": "field1", | ||
"feature_type": "POINT", | ||
"feature_fid": 122, | ||
"latitude": 40, | ||
"longitude": -70, | ||
"place_name": "Paradise2", | ||
"start_date": "2011-07-20", | ||
"end_date": "2013-07-20", | ||
"julian_start": 2455763, | ||
"julian_end": 2456494, | ||
"project": "test", | ||
"feature": null | ||
}, | ||
"model": "gazetteer.GazetteerEntry", | ||
"pk": 2 | ||
}, | ||
{ | ||
"fields": { | ||
"layer_name": "CA1", | ||
"layer_attribute": "field1", | ||
"feature_type": "POINT", | ||
"feature_fid": 123, | ||
"latitude": 40, | ||
"longitude": -70, | ||
"place_name": "Paradise3", | ||
"start_date": "2013-07-20 BC", | ||
"end_date": "2011-07-20 BC", | ||
"julian_start": 986027, | ||
"julian_end": 986758, | ||
"project": "test", | ||
"feature": null | ||
}, | ||
"model": "gazetteer.GazetteerEntry", | ||
"pk": 3 | ||
}, | ||
{ | ||
"fields": { | ||
"layer_name": "CA2", | ||
"layer_attribute": "field1", | ||
"feature_type": "POINT", | ||
"feature_fid": 124, | ||
"latitude": 40, | ||
"longitude": -70, | ||
"place_name": "Paradise4", | ||
"start_date": "2012-07-20 BC", | ||
"end_date": "2010-07-20 BC", | ||
"julian_start": 986741, | ||
"julian_end": 987471, | ||
"project": "test", | ||
"feature": null | ||
}, | ||
"model": "gazetteer.GazetteerEntry", | ||
"pk": 4 | ||
}, | ||
{ | ||
"fields": { | ||
"layer_name": "CA2", | ||
"layer_attribute": "field1", | ||
"feature_type": "POINT", | ||
"feature_fid": 125, | ||
"latitude": 40, | ||
"longitude": -70, | ||
"place_name": "Paradise5", | ||
"start_date": "2010-07-21 BC", | ||
"end_date": null, | ||
"julian_start": 987472, | ||
"julian_end": null, | ||
"project": null, | ||
"feature": null | ||
}, | ||
"model": "gazetteer.GazetteerEntry", | ||
"pk": 5 | ||
} | ||
] |
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,139 @@ | ||
import exceptions | ||
import logging | ||
from datautil.date import FlexiDate | ||
from django.core.exceptions import ValidationError | ||
from django.db import models | ||
from django.forms.widgets import Input | ||
from django.utils.encoding import smart_str, force_unicode | ||
from django import forms | ||
from django.utils.translation import ugettext as _ | ||
|
||
|
||
logger = logging.getLogger("geonode.flexidates") | ||
|
||
class FlexiDateField(models.Field): | ||
empty_strings_allowed = False | ||
default_error_messages = { | ||
'invalid': _(u"'%s' value has an invalid date format. Acceptable formats include " | ||
u"YYYY-MM-DD where YYYY = year (at least 4 digits, use" | ||
u"0001 for year 1), MM = month (1-12, optional), DD = day of month (1-31, optional)." | ||
u"For BC dates insert a minus sign before year (-1000-01-01) or append with BC (1000-01-01 BC).") | ||
} | ||
description = _("Date BC/AD (without time)") | ||
|
||
def __init__(self, verbose_name=None, name=None, auto_now=False, | ||
auto_now_add=False, **kwargs): | ||
self.auto_now, self.auto_now_add = auto_now, auto_now_add | ||
if auto_now or auto_now_add: | ||
kwargs['editable'] = False | ||
kwargs['blank'] = True | ||
models.Field.__init__(self, verbose_name, name, **kwargs) | ||
|
||
def get_internal_type(self): | ||
return "flexidate" | ||
|
||
def db_type(self, connection): | ||
return 'varchar' | ||
|
||
def to_python(self, value): | ||
if value is None: | ||
return value | ||
if isinstance(value, FlexiDate): | ||
return value | ||
|
||
value = smart_str(value) | ||
if len(value) == 0: | ||
return value | ||
|
||
try: | ||
parsed = parse_flex_date(value) | ||
if parsed is not None and len(parsed.isoformat()) > 0: | ||
return parsed | ||
except ValueError: | ||
msg = self.error_messages['invalid'] % value | ||
raise exceptions.ValidationError(msg) | ||
|
||
msg = self.error_messages['invalid_date'] % value | ||
raise exceptions.ValidationError(msg) | ||
|
||
|
||
def get_db_prep_value(self, value, connection, prepared=False): | ||
import re | ||
# Casts dates into the format expected by the backend | ||
if not prepared: | ||
value = self.get_prep_value(value) | ||
if isinstance(value, FlexiDate): | ||
connection.ops.value_to_db_date(value.isoformat()) | ||
return connection.ops.value_to_db_date(value) | ||
|
||
def value_to_string(self, obj): | ||
val = self._get_val_from_obj(obj) | ||
return '' if val is None else val.isoformat() | ||
|
||
def formfield(self, **kwargs): | ||
defaults = {'form_class': FlexiDateFormField} | ||
defaults.update(kwargs) | ||
return super(FlexiDateField, self).formfield(**defaults) | ||
|
||
def parse_flex_date(dateString): | ||
from datautil.date import DateutilDateParser | ||
parser = DateutilDateParser() | ||
if dateString is not None and len(dateString) > 0: | ||
return parser.parse(dateString) | ||
return None | ||
|
||
def parse_julian_date(dateString): | ||
from jdcal import gcal2jd | ||
flex_date = parse_flex_date(dateString) | ||
julian = gcal2jd(int(flex_date.year), int(flex_date.month if flex_date.month is not '' else '1'), \ | ||
int(flex_date.day if flex_date.day is not '' else '1')) | ||
return julian[0] + julian[1] | ||
|
||
class FlexiDateInput(Input): | ||
input_type = 'text' | ||
|
||
def __init__(self, attrs=None, format=None): | ||
super(FlexiDateInput, self).__init__(attrs) | ||
|
||
|
||
def _format_value(self, value): | ||
return value | ||
|
||
def _has_changed(self, initial, data): | ||
# If our field has show_hidden_initial=True, initial will be a string | ||
# formatted by HiddenInput using formats.localize_input, which is not | ||
# necessarily the format used for this widget. Attempt to convert it. | ||
try: | ||
initial = parse_flex_date(initial).isoformat() | ||
except (TypeError, ValueError): | ||
pass | ||
return super(FlexiDateInput, self)._has_changed(self._format_value(initial), data) | ||
|
||
class FlexiDateFormField(forms.Field): | ||
widget = FlexiDateInput | ||
default_error_messages = { | ||
'invalid': _(u"Invalid date format. Try a format of YYYY-MM-DD where YYYY = year (mandatory), " | ||
u"MM = month (1-12, optional), DD = day of month (1-31, optional). For BC dates " | ||
u"insert a minus sign before year (-1000-01-01) or append with BC (1000-01-01 BC).") | ||
} | ||
|
||
def __init__(self, *args, **kwargs): | ||
super(FlexiDateFormField, self).__init__(*args, **kwargs) | ||
|
||
|
||
def to_python(self, value): | ||
# Try to coerce the value to unicode. | ||
unicode_value = force_unicode(value, strings_only=True) | ||
if isinstance(unicode_value, unicode): | ||
value = unicode_value.strip() | ||
if isinstance(value, unicode): | ||
if len(value) == 0: | ||
return None | ||
try: | ||
fd = parse_flex_date(value) | ||
if fd is None: | ||
raise ValueError | ||
return fd | ||
except ValueError: | ||
pass | ||
raise ValidationError(self.error_messages['invalid']) |
Empty file.
Empty file.
28 changes: 28 additions & 0 deletions
28
geonode/contrib/worldmap/gazetteer/management/commands/updategazetteer.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,28 @@ | ||
from django.core.management import BaseCommand | ||
from geonode.gazetteer.models import GazetteerEntry | ||
from geonode.maps.models import Layer | ||
|
||
|
||
class Command(BaseCommand): | ||
help = """ | ||
Assigns usernames to all gazetteer features that do not have an associated | ||
username yet. | ||
""" | ||
args = '[none]' | ||
|
||
def handle(self, *args, **kwargs): | ||
gaz_layers = GazetteerEntry.objects.filter( | ||
username__isnull=True).values('layer_name').distinct() | ||
print ("Found %d layers in gazetteer with unasssigned users") % len(gaz_layers) | ||
for gl in gaz_layers: | ||
lname = gl['layer_name'] | ||
try: | ||
layer = Layer.objects.get(name=lname) | ||
username = layer.owner.username | ||
print("Assigning features for %s to %s") % (layer.name, username) | ||
GazetteerEntry.objects.filter( | ||
layer_name__exact=lname).update(username=username) | ||
except Layer.DoesNotExist: | ||
print("Layer %s no longer exists, removing from gazetteer" % lname) | ||
GazetteerEntry.objects.filter(layer_name__exact=lname).delete() | ||
print("Complete") |
Oops, something went wrong.