Tag Info

Hot answers tagged

55

I believe that the user should clearly define their objectives before deciding which set of tools to use. ModelBuilder and Python scripting excel at different tasks. A few thoughts: ModelBuilder has no mapping capabilities, whereas arcpy.mapping does. Python can be used to optimize workflows, such as with the multiprocessing package or with parallel ...


23

Usually Python debuggers/IDEs assume the Python script is running in the same process as itself so debugging a script running in ArcMap.exe is right out -- you need to get enough of the GP scripting environment bootstrapped in a Python script as you can to debug with. A method that's worked very well for me over the past few years is to write a simple ...


22

It seems the most common problem with these types of "flow maps" is that when many lines are included, they collide to such a great extent that it makes it difficult to discern any non-obvious pattern (when reciprocal flows are considered it happens to an even greater extent). Also the long lines tend to dominate the graphic, although it is quite possible ...


22

Keep in mind that Arcpy is essentially a wrapper around ArcObjects. But if you're just trying to call some Python scripts that you don't want to have to rewrite you can spawn a process that calls the python executable with your args. var startInfo = new ProcessStartInfo() { CreateNoWindow = false, UseShellExecute = false, FileName = ...


22

Welcome to GIS.SE! I would probably just put it in GitHub until you really know what you want to share. Even ESRI started jumping on this bandwagon after GeoIQ acquisition.


21

General python optimization techniques can save you substantial amounts of time. One really good technique for getting a lowdown of where the hold ups are in your script is using the built-in cProfile module: from cProfile import run run("code") # replace code with your code or function Testing using a small data sample will allow you to pinpoint which ...


21

You will find a number of other similar questions on this site that ask the same basic question and have very good references. The most similar (and detailed) is: What are the Python tools/modules/add-ins crucial in GIS? Others include: Python Script examples for geoprocessing shapefiles without using arcpy Pure Python Library for Geometry Operations ...


21

GDAL is the tool to use. In fact that entire call is one line for gdal_rasterize: gdal_rasterize -l mask -i -burn -9999 mask.shp elevation.tif if you knew the no data value of the dem For some python control: lyr = 'mask' shp = 'mask.shp' dem = 'elevation.tif' ndv = -9999 p = os.Popen('gdal_rasterize -l %s -i -burn %d %s %s' % (lyr,ndv,shp,dem) where ...


20

I am using an example with 1 million randomly generated points inside of a filegeodatabase. Attached here. Here is some code to get us started: import time import arcpy arcpy.env.workspace = "C:\CountTest.gdb" time.sleep(5) # Let the cpu/ram calm before proceeding! """Method 1""" StartTime = time.clock() with arcpy.da.SearchCursor("RandomPoints", ...


18

You can do this using a cursor to grab the data from your table and write to a comma-delimited text file. EDIT: I'm adding a more concise block of code to accomplish the task using the csv module of Python New Answer using arcpy.da cursor: import arcpy,csv table =r'c:\path\to\table' outfile = r'c:\path\to\output\ascii\text\file' #--first lets make a ...


17

If you are working solely within the confines of ArcGIS, there are a few considerations I would consider when attempting to determine the approach to take. What are you trying to accomplish, What are your current skill sets, Will you be sharing your work with others to use, learn from, or manipulate, and Who is your intended audience. Given those ...


17

It doesn't work because you haven't called the Xlrd modules to read the Excel spreadsheet. Implement it something like this: import xlrd workbook = xlrd.open_workbook('my_workbook.xls') worksheet = workbook.sheet_by_name('Sheet1') This will allow you to read an XLS file with Python. However, ArcPy will read XLS without Xlrd. You can consider the Excel ...


15

A good starting point would be the Geospatial Data Abstraction Library. It is actually made up oftwo libraries -- GDAL for manipulating geospatial raster data and OGR for manipulating geospatial vector data but people usually just call it GDAL. There's a geoprocessing with Python using open source GIS course at the Utah State University. You might want to ...


15

You need to loop through your inputs. Multivalue is semicolon delimited. Split on that and loop through them. (AddMessages to show how the fcs are presented) import arcpy ins = arcpy.GetParameterAsText(0) arcpy.AddMessage(ins) for fc in ins.split(';'): arcpy.AddMessage(fc) arcpy.Clip_analysis(fc, clipfeats, out) Though I'm not entirely sure of ...


15

If you need to create a second cursor for parcels.shp, do so outside of the loop for your first cursor. As it stands, your script is creating a new cursor object for each row in malls.shp which is what's costing you all that processing time. ... rows = arcpy.UpdateCursor('malls.shp',"","",'ParcelID') polyrows = arcpy.SearchCursor('parcels.shp') for row in ...


14

The Polyline class has a new method called "positionAlongLine" in ArcGIS 10.1. This will return a PointGeometry object with exactly one point at a specified distance from the starting end of the line, or a fraction of the distance between the start and end. To find the midpoint, you would just need to do positionAlongLine(0.5,True). To find the midpoints for ...


14

In a lot of my academic research I work with LiDAR data doing surface analysis for geomorphology. I quickly found that performing a lot of operations using arcpy was very slow, especially on large datasets. As a result I began using: pyshp to manipulate shapefiles and update attribute tables numpy to manage ASCII rasters and perform kernel-based analysis ...


14

Model Builder is a great and easy to learn visual programming language and a good entrance to GIS-programming in general. But in some things python can do more. One example is the integration of non-ESRI GIS libraries. Nearly all of the Open Source GIS can be adressed via python as well (e.g. GRASS, Sextante, QGIS, SAGA). This helped me a lot, because I ...


13

How about something simple like: if len(rasterList) == 0: print ("This directory does not contain any raster data.") else: # Your raster processing code The len() function calculates the length of the returned string/list, so if it returns 0 then you know nothing in the folder matched the criterion (in this case, being a raster). This way, if the ...


13

I've been using "in_memory" quite a bit recently. It can be very useful, as it has the potential to dramatically increase processing speeds for certain tasks, however if you are working with very large datasets, it might cause your program to crash. You can use "in_memory" to define process outputs... often, if I am performing a task on a feature class, ...


13

A da.searchcursor should work for you. for row in arcpy.da.SearchCursor("path2data", ["SHAPE@WKT"]): print row[0] POINT Z (-119.53753379999995 49.854383300000052 303.14500000000407) doc here: http://resources.arcgis.com/en/help/main/10.1/index.html#//002z0000001t000000 Note: SHAPE@JSON, SHAPE@WKB, and SHAPE@WKT tokens were made available ...


13

you can use python for getting EXIF info: from PIL import Image from PIL.ExifTags import TAGS from pprint import pprint def getexif(im): res = {} try: img = Image.open(im) info = img._getexif() for tag, val in info.items(): dec = TAGS.get(tag, tag) res[dec] = val except IOError: print im ...


12

Instead of creating and trying to add a polygon to your array, add your array of points to the array of parts. Change this: polygon = arcpy.Polygon(pntArray) pntArray.removeAll() partArray.add(polygon) To this: partArray.add(pntArray) pntArray.removeAll() Also, there's a problem with your code that tries to insert the row. You need to use your insert ...


12

GP cursors read date values as datetime objects, so you can use datetime.strftime() to format it as you like, or datetime.ctime() to format it as the default format (%a %b %d %H:%M:%S %Y). Here's an example using mm/dd/yyyy: import arcpy from datetime import datetime fc = r"C:\GISData\test.gdb\atlantic_hurricanes_2000" rows = arcpy.SearchCursor(fc) for row ...


12

As seen in this question, I believe you should use the Delete Tool to remove a table view once it has been created. arcpy.Delete_management(tblView)


12

I am not aware of an ArcObjects way to get it, but you can enable the Size column in the Customize menu -> ArcCatalog Options -> Contents tab: This works on file geodatabases but not on SDE geodatabases (in that case you could use some DBMS-specific queries to determine it though). It does not work on personal geodatabases.


12

The first thing I would do is monitor your system's resource utilization using something like Resource Monitor in Windows 7 or perfmon in Vista/XP to get a feel for whether you are CPU-, memory- or IO-bound. If you are memory or IO-bound there is likely very little that you can do but upgrade hardware, reduce the problem size, or change the approach ...


12

A couple potential suggestions to help speed up your process are: Select Layer By Attribute can be in a Python-only script, without ever launching ArcGIS Desktop. You need to convert your "buff" reference from a file-based reference to an "ArcGIS layer" reference, which ArcGIS can process selection queries against. Use ...


12

Try Googling for "python on error resume next" or similar. This returns a number of hits including this one from StackOverflow: If you know which statements might fail, and how they might fail, then you can use exception handling to specifically clean up the problems which might occur with a particular block of statements before moving on to the ...


12

For people using ESRI I think GRASS would be a very similar environment with a GUI python environment and organized in separate 'toolkits' for different tasks (raster, vector, solar toolkits etc.). The scripting has other options besides Python but that is how I use it. Definitely check out this great link which is up-to-date (I believe): ...



Only top voted, non community-wiki answers of a minimum length are eligible