Tag Info

New answers tagged

3

For this line: arcpy.RasterToPolygon_conversion(inraster, outPolygons, "NO_SIMPLIFY", field) You are inserting a list not an individual raster file, trying changing it to: arcpy.RasterToPolygon_conversion(i, outPolygons, "NO_SIMPLIFY", field)


1

Here is a general python script that will compare pre and post lengths and create the >30% select feature class (make sure your line layer has a unique ID column to base the join field method on): import arcpy arcpy.env.workspace = 'C:/Temp/test.gdb' arcpy.Intersect_analysis(["line", "AOI_polygon"], "line_intersect", "ALL", "", "") ...


2

An InsertCursor can write to a Table, your text file is not a Table! Also you create iCur but never actually do anything with it... Try this code: outputfile = r"D:\Julia_T\output\output.txt" with arcpy.da.SearchCursor(env.workspace + "\\" + rastFile,["Value","Prozent"],""""Value" = 8""") as sCur: for row in sCur: print row [0], row [1] ...


0

Sounds like a lot of data to process. Make sure your data is in a File GeoDatabase which will ensure there is a spatial index. Without knowing your data I do not know how long your lines are, so if they extend across many of your polygons then consider using the SPLIT tool to improve the efficiency of the spatial index. So what are these polygons, ward ...


0

This answer will be similar to the one I gave here... If I understand your question right, you have parcels (and maybe some other layers) and neighborhoods. You want to calculate a field in the Parcels layer (named SITE_CODE) based on what Neighborhood it's in... if so, try this code... import arcpy # Set overwrite option arcpy.env.overwriteOutput = ...


2

In your code try replacing this: for row in searchC: A = [x.split('Point') for x in row[:-1] ] with this: for row in searchC: print row[:-1] A = [x.split('Point') for x in row[:-1] ] and I think you will see that row[:-1] is returning a list of integers that you are iterating and then cannot split individually.


2

Your rename won't work because you are replacing the extension with nothing. Use os.path.splitext() to remove the extension and then you can add it back. polyFCs = arcpy.ListFeatureClasses("*_Value.shp", "POLYGON") field = "Area" #Don't need to keep redefining this each loop. field = "SHAPE@AREA" #Or, use this to grab the area of the feature. for polyf ...


1

Try this for your cursor (as I stated your cursor field parameter needs to be a string or a list and using the da.cursor use row[0] for getting the value): with arcpy.da.SearchCursor(polyf, field) as cursor: for row in cursor: if row[0] > X: # your rename here


-2

Do you have an actual field named 'Area', or are you using a shape_area field? Assuming you have an actual field 'Area', you need to check the value from row.getValue against X (although where is the value for X coming from?). You're checking the string 'Area'. Try something like: for row in cursor: if row.getValue(field) > X: # I ...


1

Add the two together, they are just lists. FCS = arcpy.ListFeatureClasses("X_*") + arcpy.ListFeatureClasses("*_Y") To eliminate duplicates: FCS = set(arcpy.ListFeatureClasses("X_*") + arcpy.ListFeatureClasses("*_Y"))


5

You could approach it a bit differently: import arcpy import os arcpy.env.workspace = 'c:\temp' fcs = [fc for fc in arcpy.ListFeatureClasses() if fc.startswith('X_') or os.path.splitext(fc)[0].endswith('_Y')]


0

Ok, it is done know – my first script. Thanks for your support! `import arcpy import os from arcpy import env env.overwriteOutput = True env.workspace = ...


0

If this is the full code then I believe the code is failing as where do you specify the mxd variable? The ListLayers function takes a map document object.


2

Instead of using arcpy.mapping.ListLayers try using arcpy.ListFeatureClasses. It will go off of the workspace, which you are already setting, and I have found it pretty easy to use. See more information HERE


0

At the moment your code looks like it would produce errors. I think you should change it from: fcs = arcpy.arcpy.ListFeatureClasses("*_Value", "POLYGON") for fc in fcs: select = arcpy.SelectLayerByLocation_management("fieldname_layer", "INTERSECT", short) result = int(arcpy.GetCount_management(select).getOutput(0)) print ...


0

Yes it was the data type that was the issue. On advice of @dklassen switching the value passed to LinkID to an int data type solved the issue.


1

Use the arcpy.Describe method on the featureset parameter and get the file property. import arcpy notRequiredFeatureSet = arcpy.GetParameter(0) arcpy.AddMessage('AOI is: ' + arcpy.Describe(notRequiredFeatureSet).file) if a Feature set was added: Executing: Script "C:\Program Files\ArcGIS\Desktop10.2\ArcGlobeData\continent.shp" Start Time: Wed ...


1

So, many thanks to all who commented on this. I will go ahead and answer this based on the discussion from those comments and my personal experience. As mentioned by @blah238 and @Branco, there is a JSON property on a featureSet that can be checked, however, when running the script from within ArcMap and using a featureClass as input, checking for that ...


0

Have you seen arcpy.mapping? Many of the things you're looking to accomplish can be done using this module (e.g. turning layers on and off, changing symbology, etc.). Have a look at the functions list. However, the team at ESRI has stressed that they aren't trying to expose everything that's available in ArcObjects, so you may find things that you can't ...


2

The real issue lies in the line: for j in newraster: where you are indeed trying to loop (iterate) through a raster object, which is not "loopable". As Erica points out, this won't work and is not necessary. I think you are simply trying to figure out what % of the cells have a value >= 14, correct? Erica has a correct answer - althoiugh populating a new ...


2

I suggest that you do not need to make a second raster to accomplish this. Rather, use Python to sub-set the dictionary to select only the desired values. This should both bypass the problem, and run faster. # original dictionary from raster dct = {row[0]:row[1] for row in arcpy.da.SearchCursor(i, flds)} sumcnt = sum(dct.values()) # new dictionary with ...


0

If you look at the QGIS Processing Toolbox: QGIS uses the Python subprocess module to run the commands of Taudem (and GRASS GIS, SAGA GIS, R, Orfeo and others) # fused_command = Taudem command line proc = subprocess.Popen(fused_command, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True).stdout ...


0

Like Erica said, your second format is easy. If all your street names were one word, you could check the length of the list after splitting the original field. Length of 3 = no prefix, length of 4 = has a prefix (also assuming SUFTYPE is always populated). This fails when a street is more than one word, such as 'Grand River'. You could check if the second ...


0

Make sure your input is in string format and simply use the string.split() function which will split on white space and return a list. (ex. "1234 W Main St." would return ["1234","W","Main","St."]) From there I would use some conditional statements to check your data depending on how consistent your input is. If the only inconsistency in your data is that ...


8

Instead of using multiple RegExes to parse addresses, just use Esri's out of the box tool that is designed for this task, Standardize Addresses. It's available at all license levels and my experience with it has been positive.


1

You can achieve this in field calculator using python. This may not be the most elegant but it's a start, assuming the simpliest case (ie. your addresses all look the same). I would first create the additional fields needed. Assuming your column with the full address is called "Address". For HOUSENO in the field calculator write: ##Return just numbers ...


3

I think the largest problem was with the structure of the update cursor. Also, you have two ListFeatureClasses (you only need one to create the list and start the for loop). Try this: bufferCalc = arcpy.ListFeatureClasses("*.shp") for calc in bufferCalc: # pull out the shapefile name shpName = os.path.splitext(calc)[0] # define update cursor ...


0

The ASCIIToRaster tool is not interpreting the file names correctly, despite you setting the workspace environment. You need to include the full path, so in your case your line should be: arcpy.ASCIIToRaster_conversion(env.workspace + "\\" + ascFile, env.workspace + "\\" + rastFile, "INTEGER") Also as @Erica says you should get into the habit of placing ...


0

Check whether the raster exists by using a print statement, e.g. for ascFile in ascFileList: print ascFile If that prints a list of .asc files, try rebooting. If that doesn't work, check that the ASCII file will convert properly by testing just one (in a separate temporary script). import arcpy ...


3

Another non-proprietary python option to list files is os.walk: import os for root, dirs, files in os.walk('C:/Temp'): for f in files: if f.endswith('.asc'): print os.path.join(root, f) The benefit of this method opposed to arcpy.ListFiles is that it can recursively search through sub-directories.


4

The ModelBuilder functions (like arcpy.IterateFiles_mb) only work within ModelBuilder, and don't do as desired within a Python script. But, for loops do just as well (if not better). In this case, you want to loop through all the .asc files in a workspace. Define the workspace (you got that far): import arcpy from arcpy import env env.workspace = ...


0

Algorithm to get desired result: Take the Line in focus Add some buffer (0.0000005) at Right (or Left) side of the Line geometry. Check whether buffer geometry is ‘Inside’ the Polygon geometry or ‘Overlap’ with Polygon geometry.


1

Gdal PYthon binding works with conjuration with gdal. You need to have installed GDAL along with the binding to work. A quick skim over the errors you provided they suggest that while you installed gdal-python you haven't install the gdal by itself: A possible solution chain is: Install GDAL (http://www.gisinternals.com/sdk/) Append the installation ...


4

Yep, this is a pretty straightforward script. import arcpy, os folder = "" arcpy.env.workspace = folder num = 50 for shp in arcpy.ListFeatureClasses(): count = int(arpcy.GetCount_management(shp)[0]) if count >= num base, ext = os.path.splitext(shp) #Append _ and the number of features in the shapefile to filename ...


0

Thanks folks. It turned out ArcMap or arcpy were corrupted. I uninstalled and reinstalled ArcMap and it worked fine.


1

I am confident that an uninstall/reinstall of ArcGIS for Desktop with Python will at least get IDLE working again. Although there may be ways to avoid doing this, employing them successfully will depend on your skillset and experience, and for me, I would find an uninstall/reinstall to be the expedient.


1

Short answer - No, ArcGIS will always pass parameters as as positional arguments. Longer answer - Sort of, if you use a slightly hacky technique of accepting both positional arguments or options in your script, using the parse_known_args method. Something like: import argparse def main(arg1,arg2,arg3): print arg1,arg2,arg3 parser = ...


4

You're probably getting some sort of exception being raised. Perhaps use a Queue to pass messages back to the parent process. Tested working code: import os, arcpy, arcgisscripting, time, sys from multiprocessing import Process from multiprocessing.queues import SimpleQueue def ConvertCADtoGDB(msgs,in_dgn,out_gdb): try: gp = ...


2

I suspect the issue is the GDAL 1.11 bindings you're fetching from gohlke do not match the internal GDAL inside of Arc*. Your bindings need to be compiled against ESRI's GDAL to work reliably. It's possible they can be made to work, but it is going to be a lot of headache. In short, ESRI needs to provide the gdal_i.lib stub file that GDAL generates as part ...


2

You need to pass in the full file path name to the arcpy.Describe method. It looks like you are only passing in the layer name and without knowing where to go to look for the layer, it can't find it and is telling you that it doesn't exist. When using the python window, it knows the workspace in which to look. When using a script you either need to set the ...


0

I don't see anywhere in the documentation for Clip_analysis where # is a valid argument. That position is reserved for cluster tolerance. However, that wouldn't give you the error you're getting. I wouldn't assume there are no errors just because it came from an esri course, either.


0

You could try creating a Model in ArcCatalog, add the tool you want to use to the Model. Run it as a Model first to be sure it works, then export it to a python script. Then, try running that python script from the os command line. Or, open the script in a text editor and run it line by line in the ArcCatalog Python window. Might still not work, but it might ...


0

My guess would be it is a garbage collection problem - one of the classes isn't going out of scope long enough for collection to occur before it is re-initialised. Managed frameworks don't always get round to it when their resources are at maximum usage and the fact it only occurs during the script version and then somewhat randomly (which might be down to ...


1

Buffer the points by 10 metres and then ERASE


0

I suggest to change arcpy.SpatialJoin_analysis(census_tracts_shp, feature_class, spatial_join, "JOIN_ONE_TO_MANY", "KEEP_ALL","", "INTERSECT", "", "") to arcpy.SpatialJoin_analysis(feature_class,census_tracts_shp, spatial_join, "JOIN_ONE_TO_ONE", "KEEP_ALL","", "INTERSECT", "", "")


1

I do it this way by creating an Array of Point objects that form a line that closes back on itself, and then creating a Polygon object from that Array: # feature_info eventually takes the following form: [[734855.5142000001, 4744379.424500001], [740607.6685000001, 4744379.424500001], [740607.6685000001, 4736862.1753], [734855.5142000001, 4736862.1753]] ...


1

Related to answer I gave to a similar question (determine min and max elevation ... within my current extent), I wonder if this would work: import arcpy # this sets extent to current display, you can instead set it to ROI polygon arcpy.env.extent = arcpy.mapping.MapDocument.activeView.Extent # for a multi-band raster, pay attention to the band index (last ...


2

You could still use zonal statistics with the minimum option. It produces a raster would could be used for further processing Zonal Statistics


2

Using IDLE, I ran your test using ArcGIS 10.2.2 for Desktop, immediately after a reboot (by coincidence) so there should be nothing laying around from previous tests. The code is identical to the third example at Writing Geometries, and I agree with you that the point does not get written. I believe that part of the documentation is in error and that ...


2

PyScripter is somewhat lax with object lifetimes and will keep stuff around after it's run. Use the with statement to ensure you close the edit session. import arcpy fc = r"C:\Users\djh\Desktop\topo_map\test.gdb\well_location" xy = (206901.75, 5997594.47) with arcpy.da.InsertCursor(fc, ["SHAPE@XY"]) as cursor: cursor.insertRow([xy])



Top 50 recent answers are included