<?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 can I create a hosted feature layer from scratch using ArcGIS API for Python? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-can-i-create-a-hosted-feature-layer-from/m-p/1556422#M73150</link>
    <description>&lt;P&gt;Awesome!&lt;/P&gt;</description>
    <pubDate>Thu, 07 Nov 2024 17:57:34 GMT</pubDate>
    <dc:creator>TonyAlmeida</dc:creator>
    <dc:date>2024-11-07T17:57:34Z</dc:date>
    <item>
      <title>How can I create a hosted feature layer from scratch using ArcGIS API for Python?</title>
      <link>https://community.esri.com/t5/python-questions/how-can-i-create-a-hosted-feature-layer-from/m-p/1555142#M73137</link>
      <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;I'm trying to create a new hosted feature layer w/o using an existing CSV, Shapefile, etc. I have an example which works to create the Feature Layer Collection, e.g.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;empty_service_item = gis.content.create_service(name='awesome_python', service_type='featureService')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;but I can't seem to get the code right for adding a Feature Layer and defining it's fields. The examples I've found are either incomplete or don't work with the current API. Can someone please help me?&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Nov 2024 16:54:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-i-create-a-hosted-feature-layer-from/m-p/1555142#M73137</guid>
      <dc:creator>john_cartwright_noaa</dc:creator>
      <dc:date>2024-11-04T16:54:06Z</dc:date>
    </item>
    <item>
      <title>Re: How can I create a hosted feature layer from scratch using ArcGIS API for Python?</title>
      <link>https://community.esri.com/t5/python-questions/how-can-i-create-a-hosted-feature-layer-from/m-p/1555639#M73139</link>
      <description>&lt;P&gt;Try this.&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

# Connect to your GIS
gis = GIS("https://www.blah.com", "username", "password")

# Step 1: Create an empty feature service
service_name = "awesome_python"
empty_service_item = gis.content.create_service(name=service_name, service_type='featureService')
feature_layer_collection = FeatureLayerCollection.fromitem(empty_service_item)

# Step 2: Define the feature layer schema (fields, geometry type, spatial reference, etc.)
layer_definition = {
    "layers": [
        {
            "name": "MyFeatureLayer",
            "geometryType": "esriGeometryPoint",  # Change to Polyline, Polygon as needed
            "fields": [
                {
                    "name": "ObjectID",
                    "alias": "ObjectID",
                    "type": "esriFieldTypeOID"
                },
                {
                    "name": "Name",
                    "alias": "Name",
                    "type": "esriFieldTypeString",
                    "length": 50
                },
                {
                    "name": "Description",
                    "alias": "Description",
                    "type": "esriFieldTypeString",
                    "length": 255
                },
                {
                    "name": "Value",
                    "alias": "Value",
                    "type": "esriFieldTypeDouble"
                }
            ],
            "objectIdField": "ObjectID",
            "globalIdField": "",
            "displayField": "Name",
            "typeIdField": "",
            "spatialReference": {"wkid": 4326}  # WGS 84
        }
    ]
}

# Step 3: Add the layer to the feature service
feature_layer_collection.manager.add_to_definition(layer_definition)

print("Feature layer created successfully!")&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 05 Nov 2024 23:06:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-i-create-a-hosted-feature-layer-from/m-p/1555639#M73139</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2024-11-05T23:06:11Z</dc:date>
    </item>
    <item>
      <title>Re: How can I create a hosted feature layer from scratch using ArcGIS API for Python?</title>
      <link>https://community.esri.com/t5/python-questions/how-can-i-create-a-hosted-feature-layer-from/m-p/1556119#M73145</link>
      <description>&lt;P&gt;Thanks - just what I needed!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Nov 2024 23:29:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-i-create-a-hosted-feature-layer-from/m-p/1556119#M73145</guid>
      <dc:creator>john_cartwright_noaa</dc:creator>
      <dc:date>2024-11-06T23:29:49Z</dc:date>
    </item>
    <item>
      <title>Re: How can I create a hosted feature layer from scratch using ArcGIS API for Python?</title>
      <link>https://community.esri.com/t5/python-questions/how-can-i-create-a-hosted-feature-layer-from/m-p/1556422#M73150</link>
      <description>&lt;P&gt;Awesome!&lt;/P&gt;</description>
      <pubDate>Thu, 07 Nov 2024 17:57:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-i-create-a-hosted-feature-layer-from/m-p/1556422#M73150</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2024-11-07T17:57:34Z</dc:date>
    </item>
  </channel>
</rss>

