Dan_Patterson

Import arcpy.... what happens

Blog Post created by Dan_Patterson Champion on Dec 12, 2018

Arcpy

 

You need to create a Point object

 

import arcpy

pnt = arcpy.Point(300000, 5025000)

print(pnt)

300000 5025000 NaN NaN

 

Simple... But what does that... import arcpy ...line do?

Let's see

 

(1) ---- Direct import

 ----------------------------------------------------------------------
| dir(arcpy) ...
|    <module 'arcpy' from 'C:\\ArcGISPro\\Resources\\ArcPy\\arcpy\\__init__.py'>
-------
  (001)    ASCII3DToFeatureClass_3d   ASCIIToRaster_conversion AcceptConnections                                       
  (004)    AddAngleDirectedLayout_un  . . . SNIP . . .

  (1174)    stats                     stpm                     sys                                                     
  (1177)    td                        time                     toolbox                                                 
  (1180)    topographic               un                       utils                                                   
  (1183)    warnings                  winreg                   wmx   

 

That's correct... about 1200 names added to python's namespace.

 

(2) ---- Alternatives?

 

arcgisscripting

# ---- arcgisscripting is located in the folder
# C:\{your_install_path}\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgisscripting
# In there there is an arcgisscripting.pyd file

import arcgisscripting as ags

dir(ags)
['ClearCredentials', 'ExecuteAbort', 'ExecuteError', 'ExecuteWarning', 'Extent',
'ImportCredentials', 'NumPyArrayToRaster', 'Raster', 'RasterToNumPyArray',
'SignInToPortal', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__',
'__name__', '__package__', '__path__', '__spec__', '_addTimeInterval', '_analyzeForSD',
'_arcgisscripting', '_attachLocator', '_chart', '_convertWebMapToMapDocument',
'_createGISServerConnectionFile', '_createGeocodeSDDraft', '_createMapSDDraft',
'_createimageservicesddraft', '_getImageEXIFProperties', '_getRasterKeyMetadata', '_getUTMFromLocation', '_hasLocalFunctionRasterImplementation', '_hgp', '_ia',
'_listDateTimeStringFormats', '_listStyleItems', '_listTimeZones', '_mapping',
'_reserved', '_setRasterKeyMetadata', '_sharing', '_ss', '_wrapLocalFunctionRaster',
'_wrapToolRaster', 'create', 'da', 'getmytoolboxespath', 'getsystemtoolboxespath',
'getsystemtoolboxespaths', 'na', 'un']

# ---- how about the *data access* stuff??

dir(ags.da)
['ContingentFieldValue', 'ContingentValue', 'DatabaseSequence', 'Describe', 'Domain',
'Editor', 'ExtendTable', 'FeatureClassToNumPyArray', 'InsertCursor',
'ListContingentValues', 'ListDatabaseSequences', 'ListDomains',
'ListFieldConflictFilters', 'ListReplicas', 'ListSubtypes', 'ListVersions',
'NumPyArrayToFeatureClass', 'NumPyArrayToTable', 'Replica', 'SearchCursor',
'TableToNumPyArray', 'UpdateCursor', 'Version', 'Walk', '__doc__', '__loader__',
'__name__', '__package__', '__spec__', '_internal_eq', '_internal_sd', '_internal_vb']

 

arcobjects

from arcpy.arcobjects import Point

 

dirr(Point)
----------------------------------------------------------------------
| dir(Point) ...
|    <class 'arcpy.arcobjects.arcobjects.Point'>
-------
  (001)    ID                M                 X                 Y                
  (005)    Z                 __class__         __cmp__           __delattr__      
  (009)    __dict__          __dir__           __doc__           __eq__           
  (013)    __format__        __ge__            __getattribute__  __gt__           
  (017)    __hash__          __init__          __init_subclass__ __le__           
  (021)    __lt__            __module__        __ne__            __new__          
  (025)    __reduce__        __reduce_ex__     __repr__          __setattr__      
  (029)    __sizeof__        __str__           __subclasshook__  __weakref__      
  (033)    _arc_object       _go               clone             contains         
  (037)    crosses           disjoint          equals                             
  (041)    overlaps          touches           within  

(3) ---- The data access module

Get less fluff when working with tables, and featureclasses.  Compare to the arcgisscripting  import... any differences?
dirr(arcpy.da, cols=3)
----------------------------------------------------------------------
| dir(arcpy.da) ...
|    <module 'arcpy.da' from 'C:\\ArcGISPro\\Resources\\ArcPy\\arcpy\\da.py'>
-------
  (001)    Describe                 Domain                   Editor                  
  (004)    ExtendTable              FeatureClassToNumPyArray InsertCursor            
  (007)    ListDomains              ListFieldConflictFilters ListReplicas            
  (010)    ListSubtypes             ListVersions             NumPyArrayToFeatureClass
  (013)    NumPyArrayToTable        Replica                  SearchCursor            
  (016)    TableToNumPyArray        UpdateCursor             Version                 
  (019)    Walk                     __all__                  __builtins__            
  (022)    __cached__               __doc__                  __file__                
  (025)    __loader__               __name__                 __package__             
  (028)    __spec__                 _internal_eq                                     
  (031)    _internal_sd             _internal_vb   

(4) ---- Arcobjects geometry

dirr(geo)
----------------------------------------------------------------------
| dir(arcpy.arcobjects.geometries) ...
|    <module 'arcpy.arcobjects.geometries' from 'C:\\ArcGISPro\\Resources\\ArcPy\\arcpy\\arcobjects\\geometries.py'>
-------
  (001)    Annotation    AsShape       Dimension     Geometry     
  (005)    Multipatch    Multipoint    PointGeometry Polygon      
  (009)    Polyline      __all__       __builtins__  __cached__   
  (013)    __doc__       __file__      __loader__    __name__     
  (017)    __package__   __spec__      basestring                 
  (021)    gp            operator      xrange    
but it import gp as well.

(5) ---- Arcobjects

import arcpy.arcobjects as arco
dirr(arco, cols=3)
----------------------------------------------------------------------
| dir(arcpy.arcobjects.arcobjects) ...
|    <module 'arcpy.arcobjects.arcobjects' from 'C:\\ArcGISPro\\Resources\\ArcPy\\arcpy\\arcobjects\\arcobjects.py'>
-------
  (001)    ArcSDESQLExecute               Array                          Cursor                        
  (004)    Extent                         FeatureSet                     Field                         
  (007)    FieldInfo                      FieldMap                       FieldMappings                 
  (010)    Filter                         GeoProcessor                   Geometry                      
  (013)    Index                          NetCDFFileProperties           Parameter                     
  (016)    Point                          RandomNumberGenerator          RecordSet                     
  (019)    Result                         Row                            Schema                        
  (022)    SpatialReference               Value                          ValueTable                    
  (025)    _BaseArcObject                 __builtins__                   __cached__                    
  (028)    __doc__                        __file__                       __loader__                    
  (031)    __name__                       __package__                    __spec__                      
  (034)    convertArcObjectToPythonObject mixins                         passthrough_attr 

(6) ---- environments perhaps?

from arcpy.geoprocessing import env
dirr(env, cols=3)
----------------------------------------------------------------------
| dir(<class 'arcpy.geoprocessing._base.GPEnvironments.<locals>.GPEnvironment'>) ...
|    np version
-------
  (001)    MDomain                        MResolution                    MTolerance                    
  (004)    S100FeatureCatalogueFile       XYDomain                       XYResolution                  
  (007)    XYTolerance                    ZDomain                        ZResolution                   
  (010)    ZTolerance                     __class__                      __delattr__                   
  (013)    __delitem__                    __dict__                       __dir__                       
  (016)    __doc__                        __eq__                         __format__                    
  (019)    __ge__                         __getattribute__               __getitem__                   
  (022)    __gt__                         __hash__                       __init__                      
  (025)    __init_subclass__              __iter__                       __le__                        
  (028)    __lt__                         __module__                     __ne__                        
  (031)    __new__                        __reduce__                     __reduce_ex__                 
  (034)    __repr__                       __setattr__                    __setitem__                   
  (037)    __sizeof__                     __str__                        __subclasshook__              
  (040)    __weakref__                    _environments                  _gp                           
  (043)    _refresh                       addOutputsToMap                autoCancelling                
  (046)    autoCommit                     baDataSource                   buildStatsAndRATForTempRaster 
  (049)    cartographicCoordinateSystem   cartographicPartitions         cellSize                      
  (052)    coincidentPoints               compression                    configKeyword                 
  (055)    extent                         geographicTransformations      isCancelled                   
  (058)    items                          iteritems                      keys                          
  (061)    maintainAttachments            maintainSpatialIndex           mask                          
  (064)    nodata                         outputCoordinateSystem         outputMFlag                   
  (067)    outputZFlag                    outputZValue                   overwriteOutput               
  (070)    packageWorkspace               parallelProcessingFactor       preserveGlobalIds             
  (073)    processingServer               processingServerPassword       processingServerUser          
  (076)    pyramid                        qualifiedFieldNames            randomGenerator               
  (079)    rasterStatistics               referenceScale                 resamplingMethod              
  (082)    scratchFolder                  scratchGDB                     scratchWorkspace              
  (085)    scriptWorkspace                snapRaster                     terrainMemoryUsage            
  (088)    tileSize                       tinSaveVersion                 transferDomains               
  (091)    transferGDBAttributeProperties values                         workspace   

(7) ---- Know your imports.

More to come

Outcomes