Tag Info

New answers tagged

0

I answered a question here that is probably similar to what you want (the second part of the answer, which also links to this answer regarding Bakeries and States...). Using Spatial Join works also, but it creates another layer which might not be desirable. Your code might look something like this... import arcpy # Set overwrite option ...


0

A safer way to do this would be: val = raw_input("Ask for something. ") query = """ "ATTRIBUTE_NAME" = '%s'"""%val arcpy.SelectLayerByAttribute_management("Sample", "NEW_SELECTION", query) In this case, using %s will convert the value you get to string. This way, if the user inputs an integer, the + operator won't fail to create the query. If you ...


3

You'll make life simpler in the future by using Add Field Delimiters. This will work for shapefiles, feature classes in a file geodatabase, personal geodatabase, etc. You might find that str.format() also makes building strings with quotation marks easier to read/write. val = raw_input("Ask user for something:\n") fc = "Sample" field = ...


1

I've not tried doing such in that particular circumstance, but normally when doing similar work in python, I would do something like the following: val = raw_input("Ask user for something.") selection = str(""" "ATTRIBUTENAME" = '""" + val + "'") arcpy.SelectLayerByAttribute_management("Sample", "NEW_SELECTION", selection) Also note, that, at least in ...


2

I can think of two things off the top of my head. If you want to stick with an Add-In, you can use the onLinemethod and simply iterate through the line geometry the user creates and pass those points into an array and convert that to a polygon. The can add segments and finishes by double clicking. Or, another option is to make a script tool. With a ...


1

There's actually no need for Python for this. Look into a Spatial Join. Add your point and line feature classes to ArcMap, right-click on your points, Joins and Relates, Join..., Join data from another layer based on the spatial location. If you do wish to automate the process, arcpy has the Spatial Join tool.


0

You should look into Attribute Assistant, which can be downloaded as part of one of the templates from the Local Government Information Model like the Address Data Management template. The Dynamic Values Table lets you configure many automated behaviors during editing. To get data from a layer touched by a point you would use the Intersecting Features ...


2

Alright great I managed to solve it, I hope this answer helps others. while True: try: YesNo = raw_input("Do you need to change a field name (Yes/No): ") except ValueError: print("Your Input is invalid") continue if YesNo == "Yes": VB = raw_input("Enter VB Expression to change Your Field: ") ##This is the expression I use: ...


2

As I said, points and lines are overkill. Same with "fromn" and "ton" - from and to nodes names. This is a simplified answer, let's make it exercise. Create shapefile like this: Call this layer "nodes" in the table of content. Add spatial join to itself (remove all of the fields!): Links table will look like that Add output to map, call it ...


1

In your code you have not specified the pathname to your shapefile correctly. Instead of: sFile = "E:\boundary\sample.shp" try: sFile = r"E:\boundary\sample.shp" This should make the 000732 error disappear.


2

Your problem is at line 102 with cursor.updateRow(row2), where it appears you forgot you were using cursor2 (not cursor, as cursor is your searchcursor and cursor2 is your updatecursor).


1

You can simply use: my_sr = arcpy.SpatialReference(my_wkid) Then use my_sr however you wish. ESRI Documentation - ArcPy SpatialReference


4

Hi Emil. The technique is called "conflation" and unfortunately ESRI did a lot of development in conflation for 10.2. There is even a toolbox in 10.2 fully devoted to your problem. I would say, try using a spatial join, or using the "Attribute Transfer Tool" in the Spatial Adjustment toolbar in ArcMap. Or if you're really ambitious depending on the ...


1

I am going to assume that name is set to a string and that STATE_NAME is a text field. In which case I think this should work. Change: arcpy.SelectLayerByAttribute_management ("SC.STATES", "NEW_SELECTION", " \"STATE_NAME\" = name") to: arcpy.SelectLayerByAttribute_management ("SC.STATES", "NEW_SELECTION", '"STATE_NAME" = ' + "'" + name + "'") Note ...


1

You can use the Copy GP tool for copying the entire feature dataset where the ND resides + it will copy all the related ND tables found in the geodatabase (outside of FD). This will preserve the ND and you don't need to create one. You are correct that it is not allowed to run the Dissolve network on an ND stored within the SDE geodatabase, you do need to ...


1

I really like using feature layers and selection for this kind of thing. Below I find all my relevant fields, then try selecting Nulls/''. If there's a selection, I field calculate. I haven't tested the script, so it may not be perfect. def removeNumericNulls (inFeatureClass): import arcpy #Relevant field types fieldTypes = ["Double", ...


1

Here is an Update Cursor approach: import arcpy shp = r'C:\path\to\your\shapefile.shp' with arcpy.da.UpdateCursor(shp, ["field1", "field2"]) as cursor: for row in cursor: row[1] = row[0][:4] cursor.updateRow(row)


4

kind of figured it out as soon as I posted. Figured I should post the answer... arcpy.CalculateField_management(myFeatureLayer, field2, "!field1![0:4]", "PYTHON") suppose I should add that one can apply any standard Python string functions to !field1! and that this syntax can be used in the Field Calculator if one toggles the Python radio button to the on ...


1

Indeed, you could create a python addin to do this for you! http://resources.arcgis.com/en/help/main/10.1/index.html#//014p00000025000000 Basically, you would be able to create a tool that could sit in your bosses tool bar. Using the tool your boss could click the map and get the data back for the area as you described. The tool would take care of all the ...


4

Here's a script I put together. The script uses your point and your line feature class, and outputs a new line feature class of line features as desired. The basic steps: Iterate through points Create a buffer around each point Create East-West line from each point. This will be used to slice your buffer in half Create point north of each input point. This ...


0

So this bug has been reported to ESRI and hopefully they'll fix it, but in the meantime, here's the work around: First create a new field: import arcpy from arcpy import env env.workspace = "C:/data/test.gdb" #Name of Feature Class fc = "Table1" #New Field Name newFieldName = "New_Field_Name" #Add new field to table arcpy.AddField_management(fc, ...


0

A workflow using the Generate Near Table tool will generally (but not always, see below) get your desired result. It will create a table describing listing the nearest n features to each input feature within a specified distance, as well as the bearing angle between the input feature and each near feature: parameters = {} #Dictionary of parameters, will be ...


0

The actual issue was my naming conventions. My .tif file was long and began with a number. I should have realized this earlier. Thanks for all the help.


3

I've certainly created something like this; it's a great use for definition queries. Here's a copy/paste/modification from a tool I've written. You'll have to look up how to create a script tool in a toolbox. When you do, make two parameters, one to hold the input shapefile/feature class (type = Feature Class or Layer), and one to enter the "layer by" ...


2

If the crash doesn't happen when copying from a local geodatabase I'd start by looking at some aspects of the source geodatabase: The Feature Class Bad features can cause problems with exporting data, faults such as self-intersecting or unclosed polygons, rings in the wrong direction etc.. Most DBMS have a methods for validating the geometry of the ...


1

When you created your script tool you would have gone through that wizard to wire up your script to a tool interface. At the stage where you point it to the script python file (.py) there is a check box which is usually un-ticked which is Show command window when executing script, try ticking that on?


3

You are collecting the extents for each polygon correctly, but need to zoom to them within the loop, or a later loop depending on what you want to do. For example to zoom in the same loop as the search cursor e.g. with arcpy.da.SearchCursor(SelLayer,"SHAPE@") as SCur: for feat in SCur: # I'm going to assume polygon/polyline ...


0

You set a workspace, so any outputs from the script will default to that location unless you explicitly put them somewhere else. Create a folder for the outputs, then write your output rasters to that folder. import arcpy import os workspace = "D:\Jiawei default download" feature_classes = [] outputFolder = r'c:\outputfolder' walk = ...


0

You can run your cell statistics with all the rasters (GRIDs) as they are. Provided you haven't put them into folders that are too deep in the folder structure (more than 128 characters), but there are ways to get around even that: In a command window type SUBST /?, this will show you the help for the subst command. You can set a 'fake' drive to a path deep ...


0

I have a visit tool (in C#, converted from VB.net, which was upgraded from VB6 which was influenced by a tool I wrote in AML)... anyway, the key is to use the Envelope of the geometry in the case of polygon, polyline or multipoint and recentre the map extent. Here is a very basic start for you: import arcpy mxd = arcpy.mapping.MapDocument('CURRENT') df = ...


0

I answered a question here that is probably similar to what you want (the second part of the answer). Using Spatial Join works also, but it creates another layer which might not be desirable. If you have specific layers/shapefiles, post them in your question and I'll try to create usable code for your particular issue.


2

You're script above probably still has a lock onto the data. Specifically this line: rows = arcpy.SearchCursor(path, fields="alpha; beta") You've got two ways to get around the lock. Delete the rows variable after your loop rows = arcpy.SearchCursor(path, fields="alpha; beta") for row in rows: print("{0} => {1}").format(row.getValue("alpha"), ...


2

See comments below: import arcpy #Get data frame object mxd = arcpy.mapping.MapDocument(r'C:/test.mxd') df = arcpy.mapping.ListDataFrames(mxd, 'Layers')[0] #Get spatial reference object from data frame SR = df.spatialReference #List all layers in data frame layers = arcpy.mapping.ListLayers (mxd, "", df) #Iterator for naming files i = 0 #Iterate all ...


1

I think the comments on this question are worth placing into an answer which I'll make Community Wiki: Try applying the spatial reference to the shape -- poly = arcpy.Polygon(ar,wgs) – Vince Jun 25 at 12:08 Yes, I would do as Vince says and add a spatial reference, otherwise the polygon has no idea where it is supposed to be. Also, you can ...


1

You can incorporate your code as above to include the following: Use arcpy.da.searchcursor() make a python list of those selected features Iterate through your python list using a unique ID to create and use an SQL expression letting you Select By Attribute, then zoom to selected features. Playing around I think something along these lines will work...it ...


0

You might try an OS Crawl while listing your rasters and running the CellStatistics and saving the result into the same location as the parent. I got the following to work on folders of .tiff rasters. import arcpy import os import math arcpy.CheckOutExtension("Spatial") from arcpy.sa import* import sys arcpy.env.overwriteOutput ...


1

There are remnant variables that have no value, as I remember the task you're trying to replace only the gdb feature classes that have new shapefiles: # Import arcpy module import os, sys, arcpy InGDB = "C:\\Users\\mwisniewski\\My Documents\\NRM_Base_Data.gdb" # this isn't the path in your question InShpFolder = "C:\\Users\\mwisniewski\\My ...


0

Use Spatial Join tool. You can find more about field mapping functionality along with your join in here.


2

You can use an Update Cursor to delete rows based on your conditions. In this example, any rows where OBJECTID > 5 is deleted. import arcpy fc = r'C:\temp\test.gdb\tmp' with arcpy.da.UpdateCursor(fc, "OBJECTID") as cursor: for row in cursor: if row[0] > 5: cursor.deleteRow() Alternatively, use Select Layer By Attribute (Data ...


1

Since the given Spatial References in ArcGIS have got their own parameters for the vertical part, as far as I know there is no way of introducing vertical part by using the given factory codes or like sr = arcpy.SpatialReference(horizontal_wkid,vertical_wkid) that one may think it should work, but it is not. However, you can create your own spatial ...


0

For a pure python solution, you can use os.path.isfile to check if the shapefile exists and is indeed a file. import os myfile = r'C:\temp\myshp.shp' if os.path.isfile(myfile): print "The file exists" # Do something


1

As a cavaet, be very careful about doing any geometry comparisons particularly geometry objects. One should be aware that the geometric operations are 2D whether you have 3D objects. You will have to compare the individual values to check for equality, preferably in Python. On a second, but related point, be careful what the geometry means. Consider the ...


0

There's a property for layer objects .isBroken, this will return true if the data source is not valid. Try this folderPath = r"C:\PROJECT\02_USER_FOLDERS\JOHN_SMITH\LAYERS" def Get_Layer_files(Folderpath): import arcpy,os ws = arcpy.env.workspace = folderPath arcpy.env.overwriteOutput = True Layer_Container =[] Layer_List = ...


1

If we print out your formatted string we get this: '"OB_ID" =\'id_LCC\'' This is not what you want. Format considerations for file GDBS are as follows: Field names are not qouted If the value is a string, use single quotes If the value is a number, do not use quotes Review the help docs for more details Use .format to simplify the variable substitution ...


1

I am using something like this with great success. import arcpy, os, csv inTables = r"pathToWorkspace" for dirpath, dirnames, filenames in arcpy.da.Walk(inTables, datatype="Table", type="ALL"): for tableName in filenames: print "Appending tables from " + tableName + " to " + newTable ...


1

An option that has worked for me is using the data source options you have from python. This has allowed me to write a script to transfer pie chart symbology, which isn't possible for some reason with standard tools. It also lets me repair broken links where symbology gets dropped when the data source is relinked from layer properties. You can also relink ...


0

New to ArcGis 10+ is the Raster object... this needs a bit of an idiom shift to get used to it. To turn a file path into a raster use arcpy.Raster("d:\\path\\to\\raster.ext") or just "raster.ext" if it's in your current arcpy.env.workspace. This also means that you need to get rid of these objects using del. Some tools will work with either a path or a ...


3

Use the geometry object's equals method. With polygons and polylines, if their symmetric difference is empty they are considered equal. So for example, in the below, g2 is the same as g1, it just has an extra vertex in the middle, and g3 is opposite to g1, so always equal. >>> g1 = arcpy.Polyline(arcpy.Array([arcpy.Point(1, 1), arcpy.Point(3, ...


2

Probably the best way to do this is with a dictionary, this is an object that stores values like Key,Value (not an easy python concept so bear with me).. There are some tutorials that describe dictionaries and what they can do here and here. First thing we need to do is go through the 'to' database finding all the feature classes and storing their full ...


4

You can use Find Identical, using the geometry of the features. Alternately, you can spatially join a feature class to itself, and use the "ARE_IDENTICAL_TO" as your match option. This can be useful if you have a bunch of features stacked on top of each other and you want to deduplicate (features with a Join_Count > 1). I recently used this to clean up some ...



Top 50 recent answers are included