I have a SQL table that I am trying to insert my features into from a feature server. I have a shape column in the destination table:
But my features don't have just a plain old shape field like this:
I see that there is a geometry object that has my X, Y values that I am storing in my destination table. Is there some function that I need to call using those x, y values that will create a shape object(?) that I can then insert into my destination table?
Thanks,
Darrin
I am trying to understand your workflow a bit better. You are connecting to AGOL and retrieving records from a feature service, correct? Your screenshot is showing the attributes of one of those records, correct? You want to take the attributes and insert them as a new record into a table in a local DBMS, correct?
If the answer to my third question is, "yes," what is the DBMS and does it host a geodatabase? If it hosts a geodatabase, is the table you want to insert records into registered with the geodatabase?
You are connecting to AGOL and retrieving records from a feature service, correct? Yes
Your screenshot is showing the attributes of one of those records, correct? Yes. The first screen shot is a picture of the design view showing the fields in my destination table. The second screen shot is a picture of the debugging information in visual studio code. It is showing the information from a single feature that is returned from a query.
You want to take the attributes and insert them as a new record into a table in a local DBMS, correct? Yes.
what is the DBMS and does it host a geodatabase? Microsoft SQL Server. Yes.
is the table you want to insert records into registered with the geodatabase? Yes.
Since you are loading the data into a registered geodatabase table or feature class, I would stick with using ArcGIS tools to load the data instead of trying to insert it using SQL from outside of ArcGIS.
Starting with ArcGIS API for Python 1.5, the SpatialDataFrame has been deprecated in favor of the spatially-enabled DataFrame. Given that, I would take the feature set returned by your query, get the data frame, and export the data frame into a local table or feature class (use an in-memory workspace if you like).
AGOrecords.df.to_featureclass("in_memory", "AGOrecords")
From there, you can use InsertCursor—Data Access module | ArcGIS Desktop or Append—Data Management toolbox | ArcGIS Desktop to put the records into your destination table.
Regarding your comment about "Shape" and "geometry" spatial field names. "Shape" is the default and standard name for the field storing geometries in a feature class while "geometry" is the canonical name of the property containing geometry in the Esri JSON Feature object—Common Data Types | ArcGIS for Developers . They are different names for the same thing, but you won't have to worry about all of that if you use ArcGIS tools from start to finish because the tools are aware and handle the geometry conversions correctly.
I'm sorry but you lost me. I'm currently using pyodbc to connect to our local database. I've tried looking but I don't get how I use this InsertCursor to add to my local database. I'm familiar with using a connection string to connect to my DB. Is this .gdb what I would set up to connect to it now?
You answered above that the destination table is registered in an enterprise geodatabase. If that is the case, then my suggestion above is to not use outside/third-party libraries like pyodbc to insert records into the table, use ArcPy code.
What level of experience do you have with ArcGIS Desktop and GIS data formats? Regarding connecting to an enterprise geodatabase to use either an ArcPy DA cursor or Append tool: Connecting to an enterprise geodatabase or database from the Catalog tree—Help | ArcGIS Desktop and Create Database Connection—Help | ArcGIS Desktop