<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to programmatically create a service and add new layers? in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-programmatically-create-a-service-and-add/m-p/1301443#M8809</link>
    <description>&lt;P&gt;Thanks, I get an Error: FeatureLayerCollection is not definded.&lt;/P&gt;&lt;P&gt;Is the following correct:&lt;/P&gt;&lt;P&gt;flc = features.FeatureLayerCollection.fromitem(empty_service_item)&lt;/P&gt;&lt;P&gt;When I use this I get the following Error:&lt;/P&gt;&lt;P&gt;Service Hosted/SERVICENAME/MapServer not found&lt;/P&gt;</description>
    <pubDate>Wed, 21 Jun 2023 11:40:41 GMT</pubDate>
    <dc:creator>MarcelBeckmann</dc:creator>
    <dc:date>2023-06-21T11:40:41Z</dc:date>
    <item>
      <title>How to programmatically create a service and add new layers?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-programmatically-create-a-service-and-add/m-p/766112#M537</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I can create an empty service using gis.content.create_service&lt;BR /&gt;This empty service has&lt;BR /&gt;layers=[]&lt;BR /&gt;tables=[]&lt;BR /&gt;I can get the service item's FeatureLayerCollection and use&amp;nbsp; .manager.update_definition to update the definition of the service including service-level properties.&lt;BR /&gt;&lt;BR /&gt;But, how to create a new feature layer (or table) and add it to the service's definition?&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Nov 2019 21:56:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-programmatically-create-a-service-and-add/m-p/766112#M537</guid>
      <dc:creator>TedChapin</dc:creator>
      <dc:date>2019-11-08T21:56:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to programmatically create a service and add new layers?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-programmatically-create-a-service-and-add/m-p/1256506#M8363</link>
      <description>&lt;P&gt;Reviving this question as I am also looking for a solution to this.&lt;/P&gt;&lt;P&gt;Anyone have a solution for this or a link to a sample?&lt;/P&gt;</description>
      <pubDate>Thu, 09 Feb 2023 15:01:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-programmatically-create-a-service-and-add/m-p/1256506#M8363</guid>
      <dc:creator>Danik-B</dc:creator>
      <dc:date>2023-02-09T15:01:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to programmatically create a service and add new layers?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-programmatically-create-a-service-and-add/m-p/1301407#M8807</link>
      <description>&lt;P&gt;Here is a link where I started:&amp;nbsp;&lt;A href="https://community.esri.com/t5/geodev-germany-blog/publish-multiple-layers-in-one-feature-service-on/ba-p/888883" target="_blank"&gt;https://community.esri.com/t5/geodev-germany-blog/publish-multiple-layers-in-one-feature-service-on/ba-p/888883&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jun 2023 07:37:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-programmatically-create-a-service-and-add/m-p/1301407#M8807</guid>
      <dc:creator>MarcelBeckmann</dc:creator>
      <dc:date>2023-06-21T07:37:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to programmatically create a service and add new layers?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-programmatically-create-a-service-and-add/m-p/1301409#M8808</link>
      <description>&lt;P&gt;Example: create the empty service and add a point layer. Once created you can use methods to add/append data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.gis import GIS
from arcgis.features import FeatureLayerCollection

"""Access AGOL"""
agol = GIS("home")

"""paramters for the create_service method"""
name = "NAME_OF_FS"
has_static_data = False # want to be able to edit
max_record_count = 1000
capabilities = "Query,Extract,Create,Update,Editing,Delete",
service_type = "featureService"
tags = ["TEST", "Feature", "Service"]
snippet = "User generated feature service"

"""create the empty feature service"""
empty_service_item = agol.content.create_service(
    name = name,
    has_static_data = has_static_data,
    max_record_count = max_record_count,
    capabilities = capabilities,
    service_type = service_type,
    tags = tags,
    snippet = snippet
)

"""the feature layer defintion template. Note: print a feature layers properties to screen to see more definitions, see previous video Access Feature Layer and View Properties."""
fl_definition = {
    "type" : "Feature Layer",
    "name" : "Example using Point Layer",
    "description": "User created point layer",
    "geometryType": "esriGeometryPoint",
    "extent": {
        "xmin": -180.0,
        "ymin": -90.0,
        "xmax": 180.0,
        "ymax": 90.0,
        "spatialReference": {
            "wkid": 4326,
            "latestWkid": 4326
        }
    },
    "fields" : [
        {
          "name": "FID",
          "type": "esriFieldTypeOID",
          "actualType": "int",
          "alias": "FID",
          "sqlType": "sqlTypeInteger",
          "nullable": False,
          "editable": False,
        },
        {
          "name": "string_field",
          "type": "esriFieldTypeString",
          "actualType": "nvarchar",
          "alias": "String Field",
          "sqlType": "sqlTypeNVarchar",
          "length": 25,
          "nullable": True,
          "editable": True
        },
        {
          "name": "integer_field",
          "type": "esriFieldTypeSmallInteger",
          "actualType": "int",
          "alias": "Integer Field",
          "sqlType": "sqlTypeInteger",
          "nullable": True,
          "editable": True
        },
        {
          "name": "decimal_field",
          "type": "esriFieldTypeDouble",
          "actualType": "float",
          "alias": "Decimal Field",
          "sqlType": "sqlTypeFloat",
          "nullable": True,
          "editable": True
        },
        {
          "name": "date_field",
          "type": "esriFieldTypeDate",
          "alias": "Date Field",
          "sqlType": "sqlTypeOther",
          "nullable": True,
          "editable": True
        }
    ],
    "indexes": [
    {
      "name": "PK_IDX",
      "fields": "FID",
      "isAscending": True,
      "isUnique": True,
      "description": "clustered, unique, primary key"
    }
    ],
    "drawingInfo": {
        "renderer": {
            "symbol": {
                "angle": 0,
                "contentType": "image/png",
                "height": 16,
                "imageData": "iVBORw0KGgoAAAANSUhEUgAAABYAAAAWCAYAAADEtGw7AAAACXBIWXMAAA7EAAAOxAGVKw4bAAABFElEQVQ4je3T223CMBgG0JPLEqQSSzRjAGuwBmuwBl0jLIFEliDBfUjchIpAqqrqC5by4suJ7e937o9a/oL/D655T9gFdgXH8diZdcK+oVxSz4YjmrG6sqopI35mnXHIkFCdJvC7cERzXNFQ1ZSBIuOQI+2mLgIVillwYHftdivr+1qq0C9I+x+23dzt7KsoONaUTbcb2bBDhlNo2bzxMRse4y1Vervzp+hDGAJFmBhLJqrhKRzTjxPaAZQbAv1eig/hMRqDakYL4rU8wqfKbR8DGweVUMdA0/4L7FHOghvKpAMWrdugYrWkXf/xwmb2VSypT92DqALbcfqxWgL7C5sfPemIu/OiIu7O8WfBv20v+Kt9AtubZ8n+mgQEAAAAAElFTkSuQmCC",
                "type": "esriPMS",
                "url": "a12829dd513a6935fd8b99065e2121bd",
                "width": 16,
                "xoffset": 0,
                "yoffset": 0
            },
            "type": "simple"
        }
    }
}

## access as FeatureLayerCollection
flc = FeatureLayerCollection.fromitem(empty_service_item)

"""update the JSON definition fof the feature service to iclude the layer"""
flc.manager.add_to_definition({"layers": [fl_definition]})&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jun 2023 12:49:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-programmatically-create-a-service-and-add/m-p/1301409#M8808</guid>
      <dc:creator>Clubdebambos</dc:creator>
      <dc:date>2023-06-21T12:49:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to programmatically create a service and add new layers?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-programmatically-create-a-service-and-add/m-p/1301443#M8809</link>
      <description>&lt;P&gt;Thanks, I get an Error: FeatureLayerCollection is not definded.&lt;/P&gt;&lt;P&gt;Is the following correct:&lt;/P&gt;&lt;P&gt;flc = features.FeatureLayerCollection.fromitem(empty_service_item)&lt;/P&gt;&lt;P&gt;When I use this I get the following Error:&lt;/P&gt;&lt;P&gt;Service Hosted/SERVICENAME/MapServer not found&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jun 2023 11:40:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-programmatically-create-a-service-and-add/m-p/1301443#M8809</guid>
      <dc:creator>MarcelBeckmann</dc:creator>
      <dc:date>2023-06-21T11:40:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to programmatically create a service and add new layers?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-programmatically-create-a-service-and-add/m-p/1301471#M8810</link>
      <description>&lt;P&gt;I forgot the&amp;nbsp;from arcgis.features import FeatureLayerCollection at the top of the script. I have added.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jun 2023 12:49:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-programmatically-create-a-service-and-add/m-p/1301471#M8810</guid>
      <dc:creator>Clubdebambos</dc:creator>
      <dc:date>2023-06-21T12:49:38Z</dc:date>
    </item>
  </channel>
</rss>

