Tag Info

Hot answers tagged

19

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: Pure Python Library for Geometry Operations What tools in Python are available for doing great circle distance + ...


16

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 ...


14

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 ...


12

From ArcPy examples, it seems like sys.exit() is the correct way to terminate a script early. The Python documentation notes that sys.exit(): is implemented by raising the SystemExit exception, so cleanup actions specified by finally clauses of try statements are honored, and it is possible to intercept the exit attempt at an outer level. The easy ...


12

Get the shape object in your cursor and access its extent property. See ArcGIS Help Working with geometry in Python: shapeName = arcpy.Describe(inFeatures).shapeFieldName for row in rows: feat = row.getValue(shapeName) extent = feat.extent print extent.XMin,extent.YMin,extent.XMax,extent.YMax


12

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 ...


12

First of all, I see you made your way here from reddit... I thought I recognized this script. Welcome! How you get your inputs depends 100% on who the end user will be, but you're right, you won't be able to use raw_input in ArcMap at all. If you are going to be the only one using the script, there's nothing wrong with getting your inputs through ...


12

This is a Programmers Competency Matrix. As far as I know there are no such standardized rating systems for GIS scripting, but I might suggest modifying this one - the Programming heading/matrix would be the most relevant and needs little modification to make it relevant to GIS as most of the same principles apply. The nice thing about a matrix like this is ...


11

I am afraid I disagree with you. I think the ArcGIS help/forums/blogs/vids/etc give a great perspective on what you can achieve with the ArcGIS range of products. Your not limited to Python to manipulate your spatial data. You can still use VBA at 931 and 10 to access the ArcObjects library, or you could take it a step further and use .NET to do all sorts ...


11

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): ...


10

If you are convenient with Python then writing script for this task is preferred. Take a look at these key things: Get a list of featureclasses/shapefiles in gdb/folder - ListFeatureClasses. In the bottom of this help article there is also an example "Copy shapefiles to a geodatabase" which you can use to start writing script. Check for existence of ...


10

You are on the right track with your script. It looks like your problem lies in how you are comparing the Layer object, to the Name of the Layer in the Table of Contents. When you use the ListLayers function, what is returned is a Layer object. You cannot then compare this to a text string to see if they are equal, you need to access the Name of the Layer ...


10

I think the answers given so far cover basically all package out there worth mentioning (espically GDAL, OGR, pyshp, NumPy) But there is also the GIS and Python Software Laboratory, that hosts a couple of interesting modules. They are: Fiona: OGR's neater API Rtree: spatial index for Python GIS Shapely: Python package for manipulation and analysis of ...


9

You can use a Python script to do the heavy work for ya: Check this out and adapt it to your needs. Needless to say, this is not tested, and don't use it on production data WITHOUT MAKING A BACKUP FIRST. import arcgisscripting gp = arcgisscripting.create(9.3) gp.Workspace = "path_to_your_geodatabase" # you can use absolute path to this function ...


9

In a global dataset you will have cases where a point is close to the equator, or Greenwich meridian. At these points a sign change could leave your location in the same country, but at the wrong location. An alternative approach is to geocode the locations based on the city, county, and country fields. Create a field measuring the distance from the ...


8

In addition to @egdetti's great suggestions, you can greatly simplify your script by making some assumptions instead of writing if/else logic for every little condition. For example: Instead of checking whether each item exists beforehand, just assume it does and overwrite it by setting arcpy.env.overwriteOutput = True. Now you may have some reason why ...


8

If the intent of your application is to provide the user a simplified view when identifying features then I would suggest just turn off all the other fields within the layer properties that you do not want to show. When the user identifies a feature, they will only see info for the two that are turned on. This can be done by: Right click layer in the ...


7

Just use os.path.join(), noting the caveat for Windows at http://docs.python.org/dev/library/os.path.html. It takes care of the os.sep for you and makes your code more portable (not that ArcPy is portable, but in general). for fc in fcList: arcpy.Copy_management( fc, os.path.join("d:/base/output.gdb", fc.rstrip(".shp")))


7

Instead of using while statements, I'd go with your idea of using a prevX var. The key is that you declare the variable after you know the value of X is for each turn through the loop. By declaring prevX in each of your control structures (if or elif statement), you know what the value of X was in that loop. This is just a nested conditional (you could ...


7

You can select some rows and right-click the field you want to populate and click Calculate Field. For a small to medium number of features/rows, I would suggest doing this within an edit session so that you can undo/redo. Then enter an expression (in either VBScript or Python syntax) and click OK. More here: Making simple field calculations.


7

I have simplified your code and corrected the error by using the da module introduced in 10.1. It greatly streamlines the reading of data using cursors, and used in conjunction with the with command this code should be more stable than if it used the the older method of file access. It works by making a list of all the fields and then removing the fields ...


7

Try this using a combination of Add Field, Calculate Field, and Delete Field arcpy tools: if fieldInfo.getFieldName(index)=="status": # Process: Add Field arcpy.AddField_management(layer, "stat", "TEXT", "", "", "50", "", "NULLABLE", "NON_REQUIRED", "") # Process: Calculate Field ...


6

As I understand your question there is no need for cursors. This is a very common and simple task to do with simple sql. If we call your two tables roadsegments and adresspoints with fields like this: roadsegments gid the_geom min_address max_address adresspoints streetname housenumber Then you can first create the column for the roadid in the ...


6

Units are always tied to your coordinate system. Assuming we're talking about a projected coordinate system, the units are in the units used by the spatial reference of your dataset. If you're dataset is in meters, your area will be in square meters. You should be able to get this info from your dataset's spatial reference. You can get your dataset's spatial ...


6

Code: import arcpy mxd = arcpy.mapping.MapDocument("CURRENT") elmWidth = 4.0 elmText = '<dyn type="document" property="title"/>' elm = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "MapTitle")[0] x = 100 elm.text = '<FNT name="Arial" size="' + str(x) + '">' + elmText + '</FNT>' while elm.elementWidth > float(elmWidth): ...


6

Within an Excel VBA macro, the following calls a Python script called test.py: Sub test() rsp = Shell(Environ$("COMSPEC") & " /c C:/test.py", vbNormalFocus) End Sub (Original source here) I've forgotten how to run an ArcGIS VBA module, but perhaps a similar line would work to call your python script. Another strategy that might work could be to ...


6

You already have your answer; you have your start X/Y and finish X/Y, so you have a range and the distance between the points Calculate the amount of points you will create per axis xRange = maxX - minX yRange= maxY - minY xloop = int(xRange /0.125)+1 yloop = int(yRange /0.125)+1 Create your point variables pointGeometryList = [] point = ...


6

I never understand why people even try to mess with CalculateField_management within a Python script instead of just doing their updates within an UpdateCursor. Not only do you not have to worry about escaping characters and writing Python functions within Python strings (shudder), you can update multiple fields at once. It's very easy with the newer arcpy ...


6

The Bounding Container toolset does exactly what you want. Should you just want code snippets, examine the functions within the scripts, one deals explicitly with extent. EDIT I should add that the script will add values to a Left, Right, Top and Bottom field in the created output file which can be used for subsequent processing


6

I think you want the arcpy.Exists function: >>> import arcpy >>> arcpy.env.workspace = r"D:\temp" >>> if arcpy.Exists("Cameron.shp"): ... print "Exists" ... Exists >>>



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