[GeoNode-users] Programmatically create a map
Sam Franklin
mr.samfranklin at gmail.com
Mon Jan 28 07:36:55 PST 2019
Hi List
I would like to programmatically create a map that consists of my base
layers (all configured in settings.py) and an existing layer that I've
added to geonode.
So, I have a workaround solution to do this using the manage.py
dumpdata/loaddata commands. I've created my content manually, then dumped
out the model configuration to JSON. Then cleaned my environment, i.e.
deleted all the content, and then run ./manage.py loaddata config.json.
This works, but it is not particularly robust as there are hardcoded
primary key values for maps and layers in the JSON config.
I think it might be preferable to use the geonode python package. I saw
that there's a method 'create_from_layer_list' in /maps/models.py. I think
this is what I want, so I wrote a short custom management command to import
the maps model and call this method:
>>>>
from django.core.management.base import BaseCommand, CommandError
from django.contrib.auth import get_user_model
from geonode.maps.models import Map
from geonode.layers.models import Layer
class Command(BaseCommand):
def handle(self, *args, **kwargs):
m = Map()
layer_name = Layer.objects.all().first().alternate
admin_user = get_user_model().objects.get(username='admin')
m.create_from_layer_list(admin_user, [layer_name], "test_map",
"this is a map")
>>>>
This custom command created a map object but is missing any of my base
layers, so the map doesn't render any content.
Within the management command, I need to add the base layers as well, but
am not sure of what to try next to solve this.
Is the "create_from_layer_list" method the best way to go, or is there a
better way to programmatically generate a map based on a list of layers
(other than my dumpdata/loaddata approach).
Thanks in advance for any advice.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/geonode-users/attachments/20190128/53a19c76/attachment.html>
More information about the geonode-users
mailing list