More

ArcGIS 10.2 arcpy - how to import/install win32com?

ArcGIS 10.2 arcpy - how to import/install win32com?


win32com used to be included with arcpy 9.x but no longer. I used to use it to manipulate excel occasionally.

I downloaded and let win32com install itself and then tried to follow some online instructions for moving the win32com api to its own win32com directory in ArcGISx6410.2Lib, but that seemed to have no effect.

Does anyone know how to do this?


I just got it working, but I had to move all of the contents (pyd's) of Libwin32 and Libwin32lib out to the site-packages level. Now it can find them, but it's sort of an ad hoc solution.


Import arcpy--ImportError :cannot import name 'gp' from 'arcpy.geoprocessing'

I am confronted with the problem that the title said, when I "import arcpy" using python (in Anaconda`s environment) for working.

In fact, I already have met an "import arcpy" problem, and I've added "D:Program Files (x86)ArcGISDesktop10.2arcpy" and "D:Program Files (x86)ArcGISDesktop10.2arcpyarcpy" into the environment variable "PYTHONPATH" .Then the problem described in the title came to me.

I have tried a variety of methods, also done as the link, but still can not solve the problem! Do I have to reinstall Anaconda or one of them?


PyScripter for ArcGIS 10.2

This tutorial is for my GEOG 490 students. I hope others find use in it too.

PyScripter is another Python GUI (Graphical User Interface) similar to the ones we've been using in class (IDLE and PythonWin). PyScripter has several advantages over these other programs, mainly the ability to auto-complete ArcPy, which really speeds things up.

Installing PyScripter

It's important to start out with a clean install of Python. I tried to install PyScripter with multiple versions of Python on my office computer and the result was a frustrating hour trying (and failing) to get PyScripter to talk to ArcPy. If you need multiple versions of Python, I wish you luck. Please let me know if there's a secret I missed.

If you have only installed ArcGIS 10.2 (Python 2.7.3 comes as part of that installation) you can skip the first step.

  1. Uninstall all versions of Python from your computer. You will then need to repair your ArcGIS 10.2 installation to reinstall the ArcGIS-flavored Python.
  2. Download PyScripter (http://code.google.com/p/pyscripter/) http://sourceforge.net/projects/pyscripter/
    1. Either version (32-bit or 64-bit) should work on most machines. If you're unsure which version you need, go with the x86 version.
    2. There is a stand alone version of PyScripter that you can install on a flash drive or external hard drive. To get that version talking to ArcPy visit Map Guy Mike's tutorial
    1. Navigate to c:python27Libsite-packages
    2. Find the Desktop10.2.pth file-you'll need to view/edit this file with Notepad
    3. This file should contain the right information, feel free to skip this step and come back to it if ArcPy doesn't work.
    4. There should be three line in the file:
    5. If you need to, add these lines, save and close the file. If these lines are in there, you are good to go.

    PyScripter Setup

    Only one small thing to do here. Go to the Tools menu, then Options > IDE Options. Under special packages add arcpy to the end of the list.

    Test it out

    In the bottom Interpreter (command line) window try import arcpy hit enter (maybe twice) and see if it works.

    A Quick Tour

    The upper window in PyScripter is the Editor window-this is where you will write your stand alone code. The auto-complete works in here as long as you have your module import statements at the top (which you should anyway).
    ** As a bonus, you don't have to save your scripts before you run them. BUT, be sure that you do save them at some point.

    The bottom window is the Interpreter (command line) window. This is like the main IDLE window, where you can test individual code bits and where some messages will appear.

    Along the bottom are some tabs for advanced code editing and debugging. One of my favorites is the Variables tab. This is where you can see what variables are in memory and what their values are. This will be important as we start to build larger scripts and need to start debugging them.


    Optimised version of projecting coordinates on the fly

    Last week I posted about creating a csv file containing coordinates projected on the fly. Seeing as I had to update the files as the projection information changed, I decided I might as well optimise my code. I managed to halve the amount of code and not write anything temporary to disk as the final output I want is non-spatial anyway.

    I'm Cindy, and this is my blog about geoinformatics (GIS/databases/geographical science), programming and lifelong learning.


    Usage

    This tool only updates the existing coordinate system information—it does not modify any geometry. If you want to transform the geometry to another coordinate system, use the Project tool.

    The most common use for this tool is to assign a known coordinate system to a dataset with an unknown coordinate system (that is, the coordinate system is "Unknown" in the dataset properties). Another use is to assign the correct coordinate system for a dataset that has an incorrect coordinate system defined (for example, the coordinates are in UTM meters but the coordinate system is defined as geographic).

    When a dataset with a known coordinate system is input to this tool, the tool will issue a warning but will execute successfully.

    All feature classes in a geodatabase feature dataset will be in the same coordinate system. The coordinate system for a geodatabase dataset should be determined when it is created. Once it contains feature classes, its coordinate system cannot be changed.


    Usage

    This tool only updates the existing coordinate system information—it does not modify any geometry. If you want to transform the geometry to another coordinate system, use the Project tool.

    The most common use for this tool is to assign a known coordinate system to a dataset with an unknown coordinate system (that is, the coordinate system is "Unknown" in the dataset properties). Another use is to assign the correct coordinate system for a dataset that has an incorrect coordinate system defined (for example, the coordinates are in UTM meters but the coordinate system is defined as geographic).

    When a dataset with a known coordinate system is input to this tool, the tool will issue a warning but will execute successfully.

    All feature classes in a geodatabase feature dataset will be in the same coordinate system. The coordinate system for a geodatabase dataset should be determined when it is created. Once it contains feature classes, its coordinate system cannot be changed.


    Syntax

    The output raster dataset to be created.

    When storing the raster dataset in a file format, you need to specify the file extension:

    • .bil —Esri BIL
    • .bip —Esri BIP
    • .bmp —BMP
    • .bsq —Esri BSQ
    • .dat —ENVI DAT
    • .gif —GIF
    • .img —ERDAS IMAGINE
    • .jpg —JPEG
    • .jp2 —JPEG 2000
    • .png —PNG
    • .tif —TIFF
    • no extension for Esri Grid

    When storing a raster dataset in a geodatabase, no file extension should be added to the name of the raster dataset.

    When storing your raster dataset to a JPEG file, a JPEG 2000 file, a TIFF file, or a geodatabase, you can specify a compression type and compression quality.

    The coordinate system to which the input raster will be projected. The default value is set based on the Output Coordinate System environment setting.

    • A file with the ".prj" extension (the prj files which ship with ArcGIS can be found in "C:Program FilesArcGISCoordinate Systems").
    • An existing feature class, feature dataset, raster catalog (basically anything with a coordinate system).
    • The string representation of a coordinate system. These lengthy strings can be generated by adding a coordinate system variable to ModelBuilder, setting the variable's value as desired, then exporting the model to a Python script.

    The resampling algorithm to be used. The default is NEAREST.

    • NEAREST — Nearest neighbor assignment
    • BILINEAR — Bilinear interpolation
    • CUBIC — Cubic convolution
    • MAJORITY — Majority resampling

    The NEAREST and MAJORITY options are used for categorical data, such as a land-use classification. The NEAREST option is the default since it is the quickest and also because it will not change the cell values. Do not use NEAREST or MAJORITY for continuous data, such as elevation surfaces.

    The BILINEAR option and the CUBIC option are most appropriate for continuous data. It is not recommended that BILINEAR or CUBIC be used with categorical data because the cell values may be altered.

    The cell size for the new raster dataset.

    The default cell size is the cell size of the selected raster dataset.

    The transformation method used between two geographic systems or datums.

    The geographic transformation is optional when the input and output coordinate systems have the same datum. If the input and output datum are different, a geographic transformation needs to be specified.

    For information on each supported geographic (datum) transformations, see the geographic_transformations.pdf located in <install location>ArcGISDesktop 10.1 Documentation.

    The x and y coordinates (in the output space) used for pixel alignment.

    The registration point works similar to the concept of snap raster. Instead of snapping the output to an existing raster cell alignment, the registration point allows you to specify the origin point for anchoring the output cells. All output cells will be an interval of the cell size away from this point. This point does not have to be a corner coordinate or fall within the raster dataset.

    The Snap Raster environment setting will take priority over the Registration Point parameter. Therefore, if you want to set the registration point, make sure that Snap Raster is not set.


    Python in ArcGIS

    Python was introduced to ArcGIS with version 9.0. A full ArcGIS installation includes Python, its standard libraries, and the NumPy package. Starting with ArcGIS 9.2, a compatible version of PythonWin is included in the ArcGIS distribution, but must be installed separately.

    ESRI recommends using the version of Python (and additional packages) shipped together with the specific version of ArcGIS. [5]

    Python is used as the primary ArcGIS scripting language to perform geoprocessing tasks. It is capable of accessing all the ArcToolbox tools as well as the methods on the Geoprocessor Programming Model.

    Python support in different versions of ArcGIS

    The geoprocessor python object is accessed differently depending on the version of ArcGIS:

    ArcGIS 9.0/9.1

    These versions of ArcGIS use Python 2.1 with the PythonWin [6] package to access a Geoprocessor using a COM interface:

    The GpDispatch COM interface is available in later versions of ArcGIS, though it is only available to Python if PythonWin is installed. [7] GpDispatch provides access to geoprocessing using any language that supports COM.

    ArcGIS 9.2

    This version of ArcGIS uses Python 2.4 and brought a major change to how the Geoprocessor was created. The win32com.client is no longer needed, replaced by the Python-native (non-COM) arcgisscripting module. This both provides better performance and allows platform independence Python geoprocessing scripts using the arcgisscripting module are supported on non-Windows versions of ArcGIS Server.

    ArcGIS 9.3/9.3.1

    These versions of ArcGIS use Python 2.5.1 and can be used with both the 9.3 version of arcgisscripting or the original 9.2 version of arcgisscripting .

    You can determine the version of the geoprocessor from its ScriptVersion property:

    ArcGIS 10

    This version of ArcGIS adds the new arcpy module. ArcPy is a site-package that builds on (and is a successor to) the arcgisscripting module. Its goal is to create the corner-stone for a useful and productive way to perform data analysis, data conversion, data management, and map automation with Python.

    The older versions of the geoprocessor (GpDispatch and the arcgisscripting module) are still supported to allow for forward compatibility of Python scripts.

    Python Map Algebra in 10.0

    If a Spatial Analyst license is available, ArcPy can be used to create Map Algebra expressions to perform complex raster processing tasks. [8] For example:


    ArcGIS 10.2 arcpy - how to import/install win32com? - Geographic Information Systems

    LVM GEO Python Core (GISPython)

    LVM GEO Python Core (GISPython) is an open source automation and scripting core developed by the LVM GEO team. Based on this core any developer can build simple and structured Python programming scripts with a rich functionality. The programming core allows management of all system's maintenance processes within a unified environment.

    There are many automated maintenance operations necessary for every large geospatial information system (GIS). These operations are required for database and server maintenance, data validations and calculations, map preparing and caching, or data exchange with other systems. Within ERSI platform maintenance scripting is done by Python programming language and ArcPy library. The LVM GEO team has worked with ArcPy library for many years and has developed the LVM GEO Python Core complementing and enriching the Platform maintenance possibilities of the ESRI library that are not provided in the ArcPy standard:

    • monitoring of automated scripts (for example Zabbix)
    • script audit storage
    • generation of automated e-mails (script progress status reports as well as automated data validation warning e-mails, etc.)
    • data transfer using FTP and SFTP, data compressing and uncompressing
    • SQL, PowerShell, Windows Shell file initiation and progress monitoring within an unified environment with ArcPy geoprocessing tools

    The Core also includes tools that simplify usage of ArcPy and Python functions, significantly easing the development process:

    • scripting of ArcGIS server administration
    • scripting of file operations
    • scripting of service caching
    • unified script initiation from ArcGIS environment, Python Shell and from other tools
    • etc.

    The LVM GEO Python Core is already being used by several companies in Latvia, including JSC Latvia's State Forests for more than 200 automated processes every day. LVM GEO offers courses about LVM GEO Python to support development of an automation platform for companies and organizations.

    GISPython package contains following modules:

    • ArcGIS 10.x /recommended with newest patches and service packs/ (GISPython is currently running on production systems based on ArcGIS 10.2.1, ArcGIS 10.3.1 and has been tested on ArcGIS 10.4)
    • Python 2.7 (included in ArcGIS installation) (arcpy and numpy modules included)
    • Additional python modules:
        (manual installation)
    • NTLM: pip install python-ntlm (included in package setup process)
    • paramiko: pip install paramiko (included in package setup process)
    • patool: pip install patool (included in package setup process)
    • simpleJson: pip install simplejson (included in package setup process)
    • GISPython is available on the Python Package Index, so you can get it via pip: pip install GISPython . Before installing it is recomended to upgrade pip to latest version using pip install --upgrade pip . To upgrade GISPython use pip install gispython --upgrade .

      Configuration & basic usage

      Before using GISPython modules in custom geoprocessing scripts, you need to set up your scripting environment with SetupDefaultEnvironment module which also includes template for user scripts.

      SetupDefaultEnvironment module also includes basic parameters (variable paramsFileSource) for parameter file (e.g. SysGISParams.py) which is important, because GISPython relies of several parameters to be present to function successfully:

      • OutDir - directory for storing script output log files OutDir = r'C:GISLogOutlog'
      • OutDirArh - directory for storing script output log file archive (all non active files) OutDirArh = r'C:GISLogOutlogArchive'
      • ErrorLogDir - directory for storing script error log files ErrorLogDir = r'C:GISLogErrorLog' (Important! This directory can be monitored for non empty files. If this directory has a file that is non empty - this indicates that a script has failed)
      • ErrorLogDirArh - directory for storing script error log files ErrorLogDirArh = r'C:GISLogErrorLogArchive'
      • TmpFolder - Temp folder TmpFolder = r'C:GIS mp'
      • encodingPrimary - encoding of Windows shell encodingPrimary = 'cp775'
      • encodingSecondary - encoding of Windows unicode language used encodingSecondary = 'cp1257'
      • SetLogHistory - enable or disable Geoprocessing history logging SetLogHistory = False

      It is recommended to define additional script parameters in SysGISParams.py file, to keep the main code clean. Our approach is to define all the parameters that define current system environment be kept in this one file. In case of moving environment (e.g. test system and production system) this one file has the specific connections and can be easily modified without changing the scripts.

      Set up the variables at the beggining of the main function, to shorten the main code:


      Parameters

      One or more 3D models or folders containing such files in the supported formats, which are 3D Studio Max ( *.3ds ), VRML and GeoVRML ( *.wrl ), OpenFlight ( *.flt ), COLLADA ( *.dae ), and Wavefront OBJ models (*.obj).

      The multipatch that will be created from the input files.

      Indicates whether to produce one feature per file or one feature for every root node in the file. This option only applies to VRML models.

      • Unchecked—The generated output will contain one file for each feature. This is the default.
      • Checked—The generated output will contain one feature for each root node in the file.

      The coordinate system of the input data. For the majority of formats, this is unknown. Only the GeoVRML format stores its coordinate system, and its default will be obtained from the first file in the list unless a spatial reference is specified here.

      Identifies the axis that defines the vertical orientation of the input files.

      The file extension of the files to import from an input folder. This parameter is required when at least one folder is specified as an input.

      • All Supported Files — All supported files. This is the default.
      • 3D Studio Max (*.3ds) — 3D Studio Max
      • VRML or GeoVRML (*.wrl) —VRML or GeoVRML
      • OpenFlight (*.flt) —OpenFlight
      • Collada (*.dae) —Collada
      • Wavefront OBJ format (*.obj) —Wavefront OBJ model

      The point features whose coordinates define the real-world position of the input files. Each input file will be matched to its corresponding point based on the file names stored in the Symbol Field . The Coordinate System parameter should be defined to match the spatial reference of the points.

      The field in the point features containing the name of the 3D file associated with each point.

      One or more 3D models or folders containing such files in the supported formats, which are 3D Studio Max ( *.3ds ), VRML and GeoVRML ( *.wrl ), OpenFlight ( *.flt ), COLLADA ( *.dae ), and Wavefront OBJ models (*.obj).

      The multipatch that will be created from the input files.

      Indicates whether to produce one feature per file or one feature for every root node in the file. This option only applies to VRML models.

      • ONE_ROOT_ONE_FEATURE — The generated output will contain one feature for each root node in the file.
      • ONE_FILE_ONE_FEATURE — The generated output will contain one file for each feature. This is the default.

      The coordinate system of the input data. For the majority of formats, this is unknown. Only the GeoVRML format stores its coordinate system, and its default will be obtained from the first file in the list unless a spatial reference is specified here.

      Identifies the axis that defines the vertical orientation of the input files.

      The file extension of the files to import from an input folder. This parameter is required when at least one folder is specified as an input.

      • * — All supported files. This is the default.
      • 3DS — 3D Studio Max
      • WRL — VRML or GeoVRML
      • FLT — OpenFlight
      • DAE — Collada
      • OBJ — Wavefront OBJ model

      The point features whose coordinates define the real-world position of the input files. Each input file will be matched to its corresponding point based on the file names stored in the Symbol Field . The Coordinate System parameter should be defined to match the spatial reference of the points.

      The field in the point features containing the name of the 3D file associated with each point.

      Code sample

      The following sample demonstrates the use of this tool in the Python window.

      The following sample demonstrates the use of this tool in a stand-alone Python script.


      Upgrade the geodatabase

      You can use the Upgrade Geodatabase tool in ArcGIS for Desktop or a Python script run on the ArcGIS client computer to upgrade your geodatabase.

      Use the Upgrade Geodatabase tool

      You can open the Upgrade Geodatabase from the Database Properties dialog box by clicking the Upgrade Geodatabase button on the General tab, or open the tool directly. If you open the tool from Database Properties , the Input geodatabase text box is prepopulated with the geodatabase connection information.

      Esri recommends that you leave both the Pre-requisites check and Upgrade geodatabase options checked. That way, the tool checks to see if the prerequisites to upgrade have been met before continuing with the geodatabase upgrade.

      The prerequisite check detects other active connections to the geodatabase, determines whether the connecting user has sufficient privileges to upgrade the geodatabase, ensures that the database can support XML columns, makes sure all datasets can be opened, and ascertains that the database and libraries are at the same release. If any prerequisites are not met, the tool terminates. You must correct any problems before you run the upgrade procedure again.

      The results of this check are reported on the geoprocessing tool dialog box. If the check (or upgrade) fails, results are also written to the GDBUpgrade.log file, which can be found in c:Users<user name>AppDataLocalESRI<ArcGIS product> .

      If all checks are passed, the tool proceeds with the upgrade. The status for the prerequisites check and the upgrade are shown on the geoprocessing tool progress dialog box. If the upgrade fails, information is written to the GDBUpgrade.log file. Additional information is written to the sdesetup.log file, which can be found in the system TEMP directory.

      Run a script

      To upgrade the geodatabase, copy one of these example scripts into a text editor. Alter any variable values to match the information at your site.

        If you have an existing database connection file that uses a direct connection and connects as the sde user, copy the script that applies to your operating system, paste it into a text editor, alter it to use information specific to your site, save and close the file, then run it:


      Watch the video: ArcPy: Working with Feature Data