<?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 convert a feature layer to point in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-convert-a-feature-layer-to-point/m-p/1149134#M7181</link>
    <description>&lt;P&gt;Would it be possible to do it on the notebook? I just checked and I don't need to save the point layer. I need this point layer to use&amp;nbsp;arcgis.features.analysis.plan_routes() because I want to automate some stuff on workforce.&lt;/P&gt;</description>
    <pubDate>Tue, 01 Mar 2022 15:59:26 GMT</pubDate>
    <dc:creator>MVAC</dc:creator>
    <dc:date>2022-03-01T15:59:26Z</dc:date>
    <item>
      <title>how to convert a feature layer to point</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-convert-a-feature-layer-to-point/m-p/1149107#M7178</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I'm using jupyter notebooks (localhost, not in pro or AGOL), and I want to convert a feature layer to point. I've been trying to do it using&amp;nbsp;&lt;STRONG&gt;arcpy.FeatureToPoint_management()&amp;nbsp;&lt;/STRONG&gt;but I'm having some issues:&lt;/P&gt;&lt;PRE&gt;parcels_id = 'the id'&lt;BR /&gt;&lt;BR /&gt;# get layer&lt;BR /&gt;&lt;BR /&gt;parcels = gis.content.get(parcels_id)&lt;BR /&gt;&lt;BR /&gt;# get the required layer&lt;BR /&gt;parcels_layer = parcels.layers[0]&lt;BR /&gt;&lt;BR /&gt;# variables&lt;BR /&gt;inFeatures = parcels_layer&lt;BR /&gt;outFeatureClass =  &lt;STRONG&gt;i dont know how to address this part&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;# feature to point&lt;BR /&gt;&lt;SPAN&gt;arcpy.FeatureToPoint_management(inFeatures, outFeatureClass, &lt;/SPAN&gt;&lt;SPAN class=""&gt;"INSIDE"&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;For the &lt;STRONG&gt;outFeatureClass,&amp;nbsp;&lt;/STRONG&gt; how can I do it to save it in a folder i have in my AGOL? is the &lt;STRONG&gt;inFeatures&lt;/STRONG&gt; ok?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 01 Mar 2022 15:20:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-convert-a-feature-layer-to-point/m-p/1149107#M7178</guid>
      <dc:creator>MVAC</dc:creator>
      <dc:date>2022-03-01T15:20:25Z</dc:date>
    </item>
    <item>
      <title>Re: how to convert a feature layer to point</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-convert-a-feature-layer-to-point/m-p/1149124#M7179</link>
      <description>&lt;P&gt;Hello MVAC,&lt;/P&gt;&lt;P&gt;Not sure about using the feature to point to save directly to AGOL.&amp;nbsp; I have a feature that I create from a feature class in our versioned geodatabase with definition query applied and saved to a project in ArcGIS Pro.&amp;nbsp; I then upload it using the script below.&amp;nbsp; Hope this helps.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy, os, sys
from arcgis.gis import GIS
from datetime import datetime
import ctypes
ctypes.windll.kernel32.SetConsoleTitleW('AgUseParcelsFeatureServiceUpdate')

### Start setting variables
# Set the path to the project
prjPath = r"I:\users\abishop\PY\FeatureServiceUpdates\AgUseParcels\AgUseParcels.aprx"

# Update the following variables to match:
# Feature service/SD name in arcgis.com, user/password of the owner account
sd_fs_name = "Agricultural_Use_Parcels"
portal = "https://mcpafl.maps.arcgis.com/" # ArcGIS Online account
user = "abishop_MCPAFL"
password = "********"

# Set sharing options
shrOrg = True
shrEveryone = False
shrGroups = ""

### End setting variables

# Local paths to create temporary content
relPath = os.path.dirname(prjPath)
sddraft = os.path.join(relPath, "WebUpdate.sddraft")
sd = os.path.join(relPath, "WebUpdate.sd")

# Create a new SDDraft and stage to SD
print("Creating SD file")
arcpy.env.overwriteOutput = True
prj = arcpy.mp.ArcGISProject(prjPath)
mp = prj.listMaps()[0]
arcpy.mp.CreateWebLayerSDDraft(mp, sddraft, sd_fs_name, "MY_HOSTED_SERVICES", "FEATURE_ACCESS","", True, True, allow_exporting=True)
arcpy.StageService_server(sddraft, sd)

print("Connecting to {}".format(portal))
gis = GIS(portal, user, password)

# Find the SD, update it, publish /w overwrite and set sharing and metadata
print("Search for original SD on portal…")
sdItem = gis.content.search("{} AND owner:{}".format(sd_fs_name, user), item_type="Service Definition")[0]
print("Found SD: {}, ID: {} n Uploading and overwriting…".format(sdItem.title, sdItem.id))
sdItem.update(data=sd)
print("Overwriting existing feature service…")
fs = sdItem.publish(overwrite=True)

if shrOrg or shrEveryone or shrGroups:
 print("Setting sharing options…")
fs.share(org=shrOrg, everyone=shrEveryone, groups=shrGroups)

print("Finished updating: {} – ID: {}".format(fs.title, fs.id))

#provide input to stop script - uncomment input below if you need to see the script final output in the command window
input('Press ENTER to exit') &lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 01 Mar 2022 15:46:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-convert-a-feature-layer-to-point/m-p/1149124#M7179</guid>
      <dc:creator>ABishop</dc:creator>
      <dc:date>2022-03-01T15:46:09Z</dc:date>
    </item>
    <item>
      <title>Re: how to convert a feature layer to point</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-convert-a-feature-layer-to-point/m-p/1149130#M7180</link>
      <description>&lt;P&gt;Moved this thread to the &lt;EM&gt;arcgis-api-for-python&lt;/EM&gt; since it isn't python specific.&lt;/P&gt;&lt;P&gt;If you want to use the FeatureToPoint tool work local and upload the result.&amp;nbsp; Especially for shapefiles, you can only upload a zip of its parts&lt;/P&gt;</description>
      <pubDate>Tue, 01 Mar 2022 15:53:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-convert-a-feature-layer-to-point/m-p/1149130#M7180</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2022-03-01T15:53:00Z</dc:date>
    </item>
    <item>
      <title>Re: how to convert a feature layer to point</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-convert-a-feature-layer-to-point/m-p/1149134#M7181</link>
      <description>&lt;P&gt;Would it be possible to do it on the notebook? I just checked and I don't need to save the point layer. I need this point layer to use&amp;nbsp;arcgis.features.analysis.plan_routes() because I want to automate some stuff on workforce.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Mar 2022 15:59:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-convert-a-feature-layer-to-point/m-p/1149134#M7181</guid>
      <dc:creator>MVAC</dc:creator>
      <dc:date>2022-03-01T15:59:26Z</dc:date>
    </item>
    <item>
      <title>Re: how to convert a feature layer to point</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-convert-a-feature-layer-to-point/m-p/1149141#M7185</link>
      <description>&lt;P&gt;You will have to wade through the help topic for it&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/python/api-reference/arcgis.features.analysis.html?highlight=plan_routes#plan-routes" target="_self"&gt;arcgis.features.analysis module — plan_routes&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Mar 2022 16:06:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-convert-a-feature-layer-to-point/m-p/1149141#M7185</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2022-03-01T16:06:36Z</dc:date>
    </item>
    <item>
      <title>Re: how to convert a feature layer to point</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-convert-a-feature-layer-to-point/m-p/1149170#M7189</link>
      <description>&lt;P&gt;Here's a purely ArcGIS Python API way of doing this. Well, plus a little pandas.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Query the layer&lt;OL&gt;&lt;LI&gt;Return as a dataframe&lt;/LI&gt;&lt;LI&gt;Return centroid instead of geometry&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;LI&gt;The centroid is just a JSON object, not a true shape, so we need to convert it.&lt;OL&gt;&lt;LI&gt;Export the centroid column to a dict&lt;/LI&gt;&lt;LI&gt;Read the dict back into its own dataframe&lt;/LI&gt;&lt;LI&gt;Convert the x/y columns to a true shape&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;LI&gt;Export the spatial dataframe to a new layer in your portal&lt;/LI&gt;&lt;/OL&gt;&lt;LI-CODE lang="python"&gt;from arcgis import GIS, GeoAccessor
import pandas as pd

# connect to portal
gis = GIS('your url', 'username')

# get parcel layer
parcels = gis.content.get('parcels itemid').layers[0]

# set our spatial reference
sr = 4326 # or whatever your spatial reference is

# query features to dataframe
df = parcels.query(
    as_df = True,
    return_centroid = True,
    return_geometry = False,
    out_sr = sr
)

# convert centroid to dict
# ordinarily I don't like long single lines, but there's no point in assigning all the intermediate outputs to their own variables
sdf = GeoAccessor.from_xy(df.join(pd.DataFrame(df.loc[:, 'centroid'].to_dict()).T), 'x', 'y', sr=sr)

# drop the centroid columns
sdf.drop(columns=['x', 'y', 'centroid', 'objectid'], inplace=True)

# export to new feature class
sdf.spatial.to_featurelayer(
    title = 'My Awesome Parcel Centroids',
    gis = gis,
    tags = ['parcels', 'centroids', 'outputs'],
    folder = 'My Outputs',
    sanitize_columns = True,
    service_name = 'parcels_centroids'
)&lt;/LI-CODE&gt;&lt;P&gt;You can just as easily export to other formats if you like.&lt;/P&gt;&lt;P&gt;Alternatively, you can use the &lt;STRONG&gt;GeoSeriesAccessor &lt;/STRONG&gt;to take a spatial polygon column and derive the &lt;STRONG&gt;true_centroid&lt;/STRONG&gt; of each, then assign the dataframe's shape attribute to &lt;EM&gt;that&lt;/EM&gt;, but I tend to find the text → dict → x/y method performs a lot faster.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Mar 2022 16:46:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-convert-a-feature-layer-to-point/m-p/1149170#M7189</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2022-03-01T16:46:35Z</dc:date>
    </item>
    <item>
      <title>Re: how to convert a feature layer to point</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-convert-a-feature-layer-to-point/m-p/1149473#M7194</link>
      <description>&lt;P&gt;Thank you very much!&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to overwrite the feature layer every time I run the code?&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2022 11:26:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/how-to-convert-a-feature-layer-to-point/m-p/1149473#M7194</guid>
      <dc:creator>MVAC</dc:creator>
      <dc:date>2022-03-02T11:26:57Z</dc:date>
    </item>
  </channel>
</rss>

