[GeoNode-users] Programmatically create a map

Toni Schönbuchner toni.schoenbuchner at csgis.de
Mon Jan 28 13:22:29 PST 2019


Hey Sam,

just an untested Idea, how about passing in a map config wit your base layers?

https://github.com/GeoNode/geonode/blob/master/geonode/maps/tests.py#L51 <https://github.com/GeoNode/geonode/blob/master/geonode/maps/tests.py#L51>
and
https://github.com/GeoNode/geonode/blob/master/geonode/maps/tests.py#L184 <https://github.com/GeoNode/geonode/blob/master/geonode/maps/tests.py#L184>

cheers,

Toni

> Am 28.01.2019 um 21:00 schrieb geonode-users-request at lists.osgeo.org:
> 
> Message: 1
> Date: Mon, 28 Jan 2019 15:36:55 +0000
> From: Sam Franklin <mr.samfranklin at gmail.com <mailto:mr.samfranklin at gmail.com>>
> To: geonode-users at lists.osgeo.org <mailto:geonode-users at lists.osgeo.org>
> Subject: [GeoNode-users] Programmatically create a map
> Message-ID:
> 	<CAPYJVm3kzLgzX7XG=-4PEHk=ER5uavJMRJGih8HsfzHD9GTTdA at mail.gmail.com <mailto:CAPYJVm3kzLgzX7XG=-4PEHk=ER5uavJMRJGih8HsfzHD9GTTdA at mail.gmail.com>>
> Content-Type: text/plain; charset="utf-8"
> 
> 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).

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/geonode-users/attachments/20190128/f58a2d6c/attachment-0001.html>


More information about the geonode-users mailing list