2
import arcpy
import sys
import os

#arcpy.env.workspace = "C:\\Test\\addresspoint"
#arcpy.env.overwriteOutput = True

input_database = "C:\\Test\\addresspoint\\connection\\Test.sde"
out_layer_name = "addPointtbv"

Query = """ SELECT S_ID, S_Key, Address, City, State, ZipCode, Latitude, Longitude FROM [ST].[dbo].[ST] """
Unique_Identifier_Field_s_ = ["S_ID", "S_Key"]
Shape_Type = "POINT"
SRID = "3857"
Coordinate_System = """PROJCS['WGS_1984_Web_Mercator_Auxiliary_Sphere',GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],
UNIT['Degree',0.0174532925199433]],PROJECTION['Mercator_Auxiliary_Sphere'],PARAMETER['False_Easting',0.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',0.0],
PARAMETER['Standard_Parallel_1',0.0],PARAMETER['Auxiliary_Sphere_Type',0.0],UNIT['Meter',1.0]];-20037700 -30241100 10000;-100000 10000;-100000 10000;0.001;0.001;0.001;IsHighPrecision"""

# Process: Make Query Layer (Make Query Layer) 
add_pnt = arcpy.MakeQueryLayer_management(input_database, out_layer_name, Query, Unique_Identifier_Field_s_,Shape_Type, SRID, Coordinate_System)                                              
print(out_layer_name + " query layer is created")

X_Field="Latitude"
Y_Field="Longitude"  
Spatial_Reference = Coordinate_System

# Process: Make XY Event Layer (Make XY Event Layer) 
in_layer = out_layer_name
out_layer = "xyeventlayer"

arcpy.MakeXYEventLayer_management(in_layer, X_Field, Y_Field, out_layer, Spatial_Reference)
print(out_layer + " is saved")

Error:

arcgisscripting.ExecuteError: ERROR 000223: Cannot extract event table properties

Failed to execute (MakeXYEventLayer).

It does work in ArcGIS Pro based python 3.6.9 (64 bit) anaconda, It is not working at all in 2.7.5 and 2.7.16 which desktop based installation and it is 32 bit.

4

According to documentation, spatial reference argument should be a SpatialReference object. It also accepts some string type of spatial reference. But it may not accept wkt string of spatial reference like in your script.

Therefore, try to create SpatialReference object.

# other lines

coordinate_system_string = """PROJCS['WGS_1984_Web_Mercator_Auxiliary_Sphere',GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],
UNIT['Degree',0.0174532925199433]],PROJECTION['Mercator_Auxiliary_Sphere'],PARAMETER['False_Easting',0.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',0.0],
PARAMETER['Standard_Parallel_1',0.0],PARAMETER['Auxiliary_Sphere_Type',0.0],UNIT['Meter',1.0]];-20037700 -30241100 10000;-100000 10000;-100000 10000;0.001;0.001;0.001;IsHighPrecision"""

coordinate_system = arcpy.SpatialReference()
coordinate_system.loadFromString(coordinate_system_string)

add_pnt = arcpy.MakeQueryLayer_management(....., SRID, coordinate_system)

# other lines

arcpy.MakeXYEventLayer_management(....., coordinate_system)
|improve this answer|||||
  • I got this error in spatial_reference object: NameError("The attribute 'latitudeOfOrigin' is not supported on this instance of SpatialReference.",)NameError("The attribute 'metersPerUnit' is not supported on this instance of SpatialReference.",) – LoveGIS Feb 26 at 21:54
  • Sahbaz after try above i got this error, sorry I am new to this platform so I do mistakes. – LoveGIS Feb 26 at 22:07
  • Which line gives that error? – Kadir Şahbaz Feb 26 at 22:21
  • error at this point arcpy.MakeXYEventLayer_management(in_layer, X_Field, Y_Field, out_layer, coordinate_system) this works fine add_pnt = arcpy.MakeQueryLayer_management(....,SRID, coordinate_system) – LoveGIS Feb 26 at 23:06
  • 1
    Web mercator auxiliary Sphere is EPSG:3857 which is what your WKT appears to be describing, you'd get less likelihood of errors if you used Spatial_Reference = arcpy.SpatialReference(3857) instead of WKT coordinate_system_string. – Michael Stimson Feb 27 at 0:53
2

Finally after struggling with code and debugging more than 100 times and talk to ESRI support I am able to resolve this issue, which is a bug listed in Esri BUG-000126550. This bug is not in XY event layer it is in Make query layer. So instead of using

arcpy.MakeQueryLayer_management(......) 

I have to use

arcpy.CreateDatabaseView_management (input_database, view_name, view_definition)

import arcpy
import sys
import os

#arcpy.env.workspace = "C:\\Test\\addresspoint"
#arcpy.env.overwriteOutput = True

input_database = "C:\\Test\\addresspoint\\connection\\Test.sde"
view_name = "db_view"

view_definition = """ SELECT S_ID, S_Key, Address, City, State, ZipCode, Latitude, Longitude FROM [ST].[dbo].[ST] """

SRID = "3857"
# Process: Create Database View
arcpy.CreateDatabaseView_management (input_database, view_name, view_definition)                                    
print(view_name + " db view is created")

X_Field="Latitude"
Y_Field="Longitude"  
# Process: Make XY Event Layer (Make XY Event Layer) 
in_layer = view_name
out_layer = "xyeventlayer"

arcpy.MakeXYEventLayer_management(in_layer, X_Field, Y_Field, out_layer, 3857)
print(out_layer + " is saved")
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.