<?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: Export from Portal to Shapefile and adding X &amp;amp; Y in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/export-from-portal-to-shapefile-and-adding-x-amp-y/m-p/1320035#M68448</link>
    <description>&lt;P&gt;to anyone else following this or would like my solution..&amp;nbsp; it was a LOT easier than I thought&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I just opened the workspace and ran the ADD XY using this simple command&amp;nbsp; arcpy.management.AddXY(layer_name)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;with arcpy.EnvManager(preserveGlobalIds=True):
    for x in data_content.layers:
        if x.properties.type == "Feature Layer":
            layer_name = x.properties.name.replace(" ","")
            layer_url = x.url;
            
            if x.properties.geometryType == "esriGeometryPoint": 
      		arcpy.conversion.FeatureClassToFeatureClass(layer_url, workspace_gdb, layer_name)  
                arcpy.management.AddXY(layer_name)

            else:
                
                arcpy.conversion.FeatureClassToFeatureClass(layer_url, workspace_gdb, layer_name)    
                      
            
    for x in data_content.tables:
        if x.properties.type == "Table":
            layer_name = x.properties.name.replace(" ","")
            layer_url = x.url;
            
            arcpy.conversion.TableToTable(layer_url, workspace_gdb, layer_name) &lt;/LI-CODE&gt;</description>
    <pubDate>Fri, 18 Aug 2023 12:13:57 GMT</pubDate>
    <dc:creator>KristenJones1</dc:creator>
    <dc:date>2023-08-18T12:13:57Z</dc:date>
    <item>
      <title>Export from Portal to Shapefile and adding X &amp; Y</title>
      <link>https://community.esri.com/t5/python-questions/export-from-portal-to-shapefile-and-adding-x-amp-y/m-p/1319291#M68435</link>
      <description>&lt;P&gt;I have a working Export tool that grabs a published Rest service of several layers and saves them locally on my computer, the only thing I need to add to it is on the point feature classes there is no X and Y coordinates. So I have to calculate them and add them to the exported shape file.&amp;nbsp; The following code WORKS PERFECT&amp;nbsp; (I just left out the variables and such) but I am working on the "If it is a Point FC then add the X&amp;amp;Y to that exported FC.&amp;nbsp; The CODE I have that is remarked out is what I am wanting to do logically but it is not correct.&amp;nbsp; Can someone help with the correct syntax and calls?&lt;/P&gt;&lt;LI-CODE lang="python"&gt;with arcpy.EnvManager(preserveGlobalIds=True):
    for x in data_content.layers:
        if x.properties.type == "Feature Layer":
            layer_name = x.properties.name.replace(" ","")
            layer_url = x.url;
 
#if layer_url.geometry.dtype == "Point":
   #Calulate/get the  X &amp;amp; Y values
   #XVALUE = arcpy.management.CalculateGeometryAttributes(arcpy.env.workspace, POINT_X)
   #YVALUE = arcpy.management.CalculateGeometryAttributes(arcpy.env.workspace, POINT_Y)
   #XField = arcpy.AddFieldDelimiters(arcpy.env.workspace, "X")
   #YField = arcpy.AddFieldDelimiters(arcpy.env.workspace, "Y")
   #expression = XField + " = XVALUE, YField + " = YVALUE,"
   #arcpy.conversion.FeatureClassToFeatureClass(layer_url, workspace_gdb, layer_name, expression)    
            arcpy.conversion.FeatureClassToFeatureClass(layer_url, workspace_gdb, layer_name)         
            
    for x in data_content.tables:
        if x.properties.type == "Table":
            layer_name = x.properties.name.replace(" ","")
            layer_url = x.url;                 
            arcpy.conversion.TableToTable(layer_url, workspace_gdb, layer_name)  &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Aug 2023 19:10:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-from-portal-to-shapefile-and-adding-x-amp-y/m-p/1319291#M68435</guid>
      <dc:creator>KristenJones1</dc:creator>
      <dc:date>2023-08-16T19:10:35Z</dc:date>
    </item>
    <item>
      <title>Re: Export from Portal to Shapefile and adding X &amp; Y</title>
      <link>https://community.esri.com/t5/python-questions/export-from-portal-to-shapefile-and-adding-x-amp-y/m-p/1319368#M68436</link>
      <description>&lt;P&gt;Hi, I think for the if statement you should change to something like&lt;/P&gt;&lt;PRE&gt;if x.properties.geometryType == "esriGeometryPoint":&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You could also approach this differently if this is the only thing you need to do. Here's a working snippet that uses just the ArcGIS API for Python:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis import GIS
from arcgis.features import FeatureLayer

gis = GIS()
sample_url = "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Earthquakes_Since1970/FeatureServer/0"
fl = FeatureLayer(sample_url, gis)
sdf = fl.query(as_df=True)

if fl.properties.geometryType == "esriGeometryPoint":
    sdf["x"] = sdf.SHAPE.apply(lambda x: x.x)
    sdf["y"] = sdf.SHAPE.apply(lambda x: x.y)

sdf.spatial.to_featureclass(location=r"c:\temp\eq.shp")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Aug 2023 21:35:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-from-portal-to-shapefile-and-adding-x-amp-y/m-p/1319368#M68436</guid>
      <dc:creator>EarlMedina</dc:creator>
      <dc:date>2023-08-16T21:35:18Z</dc:date>
    </item>
    <item>
      <title>Re: Export from Portal to Shapefile and adding X &amp; Y</title>
      <link>https://community.esri.com/t5/python-questions/export-from-portal-to-shapefile-and-adding-x-amp-y/m-p/1319630#M68438</link>
      <description>&lt;P&gt;Thanks but I can't seem to "plug in your code to work.&amp;nbsp; The esriGeometryPoint works but not the adding X &amp;amp; Y coordinates. Here is my exact working code with the lines REMED out that I am trying to edit.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;import arcpy, getpass, logging, matplotlib, json
import datetime
from arcgis.gis import GIS
from arcgis.features import FeatureLayer
import pandas as pd
from pandas import json_normalize
now = datetime.datetime.now()

# Create a unique name
namedate = now.strftime("%Y%m%d%H%M%S")

# Print the name
print(namedate)

name = "DEV"
gdb_name = namedate + "-" + name
portal_url = 'https://gisdev.testing.com/portal' 
rest_id = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
user = 'test'
pwd = 'test' 
Company_Code = 'X'
folder_input = 'C:\test\\' 

gis = GIS(portal_url, user, pwd)

data_content = gis.content.get(rest_id)
workspace_gdb = arcpy.CreateFileGDB_management(folder_input, f"{gdb_name}.gdb")

arcpy.env.workspace = fr"{workspace_gdb}"

with arcpy.EnvManager(preserveGlobalIds=True):
    for x in data_content.layers:
        if x.properties.type == "Feature Layer":
            layer_name = x.properties.name.replace(" ","")
            layer_url = x.url;
            
            if x.properties.geometryType == "esriGeometryPoint":
                    # BOMBS sdf = x.properties.query(as_df=True)
                    # BOMBS sdf["x"] = sdf.SHAPE.apply(lambda x: x.x)
                    # BOMBS sdf["y"] = sdf.SHAPE.apply(lambda x: x.y)
                    arcpy.conversion.FeatureClassToFeatureClass(layer_url, workspace_gdb, layer_name)  
            Else       
                    arcpy.conversion.FeatureClassToFeatureClass(layer_url, workspace_gdb, layer_name)

    for x in data_content.tables:
        if x.properties.type == "Table":
            layer_name = x.properties.name.replace(" ","")
            layer_url = x.url;
            arcpy.conversion.TableToTable(layer_url, workspace_gdb, layer_name) &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Aug 2023 15:04:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-from-portal-to-shapefile-and-adding-x-amp-y/m-p/1319630#M68438</guid>
      <dc:creator>KristenJones1</dc:creator>
      <dc:date>2023-08-17T15:04:54Z</dc:date>
    </item>
    <item>
      <title>Re: Export from Portal to Shapefile and adding X &amp; Y</title>
      <link>https://community.esri.com/t5/python-questions/export-from-portal-to-shapefile-and-adding-x-amp-y/m-p/1320035#M68448</link>
      <description>&lt;P&gt;to anyone else following this or would like my solution..&amp;nbsp; it was a LOT easier than I thought&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I just opened the workspace and ran the ADD XY using this simple command&amp;nbsp; arcpy.management.AddXY(layer_name)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;with arcpy.EnvManager(preserveGlobalIds=True):
    for x in data_content.layers:
        if x.properties.type == "Feature Layer":
            layer_name = x.properties.name.replace(" ","")
            layer_url = x.url;
            
            if x.properties.geometryType == "esriGeometryPoint": 
      		arcpy.conversion.FeatureClassToFeatureClass(layer_url, workspace_gdb, layer_name)  
                arcpy.management.AddXY(layer_name)

            else:
                
                arcpy.conversion.FeatureClassToFeatureClass(layer_url, workspace_gdb, layer_name)    
                      
            
    for x in data_content.tables:
        if x.properties.type == "Table":
            layer_name = x.properties.name.replace(" ","")
            layer_url = x.url;
            
            arcpy.conversion.TableToTable(layer_url, workspace_gdb, layer_name) &lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 18 Aug 2023 12:13:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/export-from-portal-to-shapefile-and-adding-x-amp-y/m-p/1320035#M68448</guid>
      <dc:creator>KristenJones1</dc:creator>
      <dc:date>2023-08-18T12:13:57Z</dc:date>
    </item>
  </channel>
</rss>

