Tag Info

Hot answers tagged

31

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


26

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


17

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


17

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


16

The Delete tool should accept the name of a feature layer to remove it from the TOC.


16

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


13

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


12

Check out the replace function in the calculate field examples. Something like this should do it: NewString = Replace([comments], "&", "and")


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

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


12

The principle is simple if you have R installed and is usable in command line. You can create and/or execute a R Script from QGIS using Processing in QGIS version 2.0 or Sextante in version 1.8): see: Setting “R Folder” Path in QGIS Sextante Port your R scripts to QGIS using SEXTANTE QGIS with R: Working with the SEXTANTE plugin and others


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

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


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

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


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

Here is a list of references I have started to put together for myself: ArcGIS 10 and Python


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


9

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


9

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


9

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


8

This will do it import arcpy arcpy.env.workspace = r'c:\temp\x' fcs = arcpy.ListFeatureClasses() for fc in fcs: arcpy.AddField_management(fc, 'shpname','text') arcpy.CalculateField_management(fc, 'shpname', '"'+fc+'"') arcpy.Merge_management(fcs, 'out.shp')


8

I know your question is Python-centric, but R has a wealth of value statistical analysis methods, some of which can be used for spatial analysis. @Whuber has a good answer here illustrating how to clip a raster to a box in two lines.


8

Remember that all of ArcGIS' Python stuff dealing with strings starting in 9.3 uses Unicode objects, which will make your life quite a bit easier because encoding becomes less of a big deal in the data. You'll still need to think about it in your scripts, but if you use UTF-8 in any Python source you write outside of dialogs in Arc*.exe ArcGIS will handle it ...


8

You can call the GP tools in two ways: arcpy.%toolbox%.%toolname% or arcpy.%toolname%_%toolbox% Both are calling the same function, so there is no difference. It is a matter of taste; I always call functions in the arcpy.Buffer_analysis format because I seem to read the name tool faster in this way (I see first the toolname, and often seeing the ...


7

You can invoke arcpy.RemoveLayer to remove a layer from the TOC.


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

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


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



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