AnsweredAssumed Answered

losing information when creating a shapefile

Question asked by sotriant on Jan 16, 2018
Latest reply on Jan 16, 2018 by Dan_Patterson

I m using ArcGIS 10.4.1 and NetworkAnalyst. The following code is used to read a table in a database and create a points shapefile:


import arcpy
from arcpy import env
import csv
import pyodbc
TABLE_NAME = "ad0127_2403$";
try:
   cn = pyodbc.connect('DRIVER={SQL Server};SERVER=*******;DATABASE=routing;trusted_connection=yes')
   sql = "select Row_ID, Sys_Date, Latitude, Longitude, Dop, Speed, Mobile_ID_1, is_pod from dbo."+TABLE_NAME+" where is_pod = 224 order by Sys_Date"
   cur = cn.cursor()
   cur.execute(sql)
   the_data = cur.fetchall()
   cn.commit()

 

   OPoint = arcpy.Point()
   pointGeometryList = []

   for row in the_data:
      OPoint.Y = float(row[2])
      OPoint.X = float(row[3])
      Speed = float(row[4])

      spRef = arcpy.SpatialReference("WGS 1984")
      pointGeometry = arcpy.PointGeometry(OPoint,spRef)
      pointGeometryList.append(pointGeometry)

 

   # Output the result
   # Copy features to shapefile
   arcpy.CopyFeatures_management(pointGeometryList,    r"C:\Users\*****\Desktop\ROUTES\testingRoutess\testing.shp")
   arcpy.AddXY_management(r"C:\Users\******\Desktop\ROUTES\testingRoutess\testing.shp")

 

except Exception as e:
# If an error occurred, print line number and error message
import traceback, sys
tb = sys.exc_info()[2]
print "An error occured on line %i" % tb.tb_lineno
print str(e)

 

The problem that i m facing has to do with the fact that the created shapefile's attribute table is missing crucial information.The source table has the following fields

 

the shapefile's attribute table has the following fields

 

Is there any way or python method to auto add more fields (i.e Speed) in the attribute table? Any help would be appreciated.

Outcomes