Upload new source data for existing layer

818
2
03-27-2017 02:28 AM
AlistairFox
Occasional Contributor

Ok my workflow is this:

  1. I have existing feature layers all symbolized and popups set nicely in my AGOL account
  2. Every month I want to refresh the data within
  3. I would like to make a copy of the layer to a new month - remove the data and upload the new data

I can use the API to publish the new data as a new layer, name it and put it in the right folder. But all my symbology is now default symbol and I want to re-use the existing symbology. 

So can I:

  1. save the symbology definition and use that to set this on the new layer as i upload it.
  2. or, somehow delete all features from the old layer and load in the new features - hence layer setting such as symbology stays
0 Kudos
2 Replies
AtmaMani
Esri Contributor

Both the options you described is possible with the Python API.

For option a - save symbology: In a feature layer, your symbology can be stored in two places 1) The web feature layer's definition 2) portal Item's data resource. Refer to the guide on FeatureLayerManager to find how to read & update definitions of a feature layer, this is useful if symbology and pop-ups is stored in the feature layer's definition. If your template has it stored in the item, access the data resource using Item.get_data().

For option b - update just the features: To perform this, refer to the guide on editing features.

Both of these use cases are popular, over the next few update cycles, we will consider writing them as samples or guide chapters.

0 Kudos
AlistairFox
Occasional Contributor

Hi Atma

that's definitely put me on the right path. I can get the json dict properties of the old and new layers. But I'm stuggling with the update_definition. 

How do I update just the drawing definition part to use the previously set symbol. As below.

I've tried saving this to a json file and loading in an applying to update_definition but get an unable to retrieve feature error. Your right, a worked example here would really help.

Also; when i go to get the properties of the layer i get a token error. how do i generate a token and pass thru. 

  "drawingInfo": {

    "labelingInfo": null,

    "transparency": 0,

    "renderer": {

      "type": "simple",

      "symbol": {

        "imageData": "iVBORw0KGgoAAAANSUhEUgAAABsAAAAaCAYAAABGiCfwAAAAAXNSR0IB2cksfwAAAAlwSFlzAAAOxAAADsQBlSsOGwAAArxJREFUSInllUtIlFEUx3/aaDI6YyM6OhIIMdBzGxS0y6BVbqKFi6igDJLQspBeM1qMlkEhCG6yVi3aROuGWlS79rYYopFstOIba+abmW8e32lx5/3QVHLTgQvnu4//755z7nevhS00y/8Niz2eEURQzaTgqyaRKM33PHWbgmk9u6Xp0gAYiYIwAhTDgMZG9LEJMWaf0BYK1ITWhOkT9wURJGUoQROsF34AQmy2HevAsupEiM10gAjbz/ajI9Lsu1sVWBWmj/kEIw0iWC8uFQTNuJqQTIAksrNNMFJYh5aADLGHTvTh69L86EEFsAKm3/QIRgIQrIPLKqqsIJIEMhA3QIz8mLlPy8KFFV3Hvs2C5nJLeUorIzNSCjQcIjblxHpVpavp5CKIGrMc1MA0AJPoZActo9/VwQHsGRMySRqOH4WngdqRRQZHxIwnWDm9hFXAemUhL1LfLXm/8Ui8ELGeyqc0ctuJbXwBMInc6OR3/xmxP39WVxVGKg4i7Ow2wFTCUY+TlrElJXCnE9tYqFArTCSZzKbXBCMNqLqm37yvSFoJTIyUEr21A9u4ArR4C9GRTAHZumWBNt8XEAgf/orD/xqiOTV3bZjmcgtJA+18kJ5dDUSudWGbWgRMfo90Y5/6hs33GaLvKkQAHP6CH+514/AHCPeWAksiS7/9QLQvAE6weSB8SC2yewG9EhDu68HxKshPbxvtXq0EVM1WvUEc/gC/zvXQOhesKtL6MgjwV6ASWFsoUKe53NI95ObF5QCnTmQF54J5MIA26qJtUh2S+vqiKMtA5SmsiCwHPDbtJjxN1V3mQOWWm1sMWfOnzgGr7XYtWw1UFVYO3IjVuvnXfM8+zcOevRvFrhMmOsx/LHybTbD/gPKL+wG6NgvrGq08VeFVxDf0eNZaVFzL1YTXBVvvJv4JbDO2pbA/1VNr5+fX+kYAAAAASUVORK5CYII=",

        "xoffset": 0,

        "width": 20,

        "contentType": "image/png",

        "type": "esriPMS",

        "height": 19,

        "yoffset": 0,

        "angle": 0,

        "url": "632a2675cb74c05e5734e3b8b2acdcf2"

      },

      "label": "",

      "description": ""

    }

  },

0 Kudos