Tag Info

New answers tagged

2

The following script converts all of the feature datasets and feature classes of a personal geodatabase to a new file geodatabase. import arcpy, os # Set the in and out workspaces inws = r'C:\temp' outws = r'C:\temp\outws' # List the Access Databases arcpy.env.workspace = inws mdbs = arcpy.ListWorkspaces(workspace_type = "Access") count = 1 for m in ...


1

It may be not the "neat way" what you have asked for, but i would go for this if i have a lots of points (but you have only 1400(c) points). Separate each block ( in your image there are three blocks) using arcmap fishnet tool or others. Now run following operation on every block (for your image the rightmost block where 90 points are in place) Run sort ...


3

Assuming that your code is working OK to create file geodatabases with the same names as your personal geodatabases, I think your next steps should be to: use ListDatasets to produce a list of feature datasets in your Personal Geodatabase, and then use Create Feature Dataset to create new ones with the same names in your File Geodatabase.


0

Make sure that you are formatting your paths correctly. Currently your CulvertFeature = "C:\Users\rdcoopercaroselli\RowynProjects\LiDAR_Work\AutomationTest\Automation_try2.gdb/Culverts" There are a number of other paths with the same issue.


0

I just used the below code to transfer a shapefile into PostGIS. I saw your post and thought it might help. The Shape@WKT makes it really easy to transfer the geometry. Everything is hard coded and works which I am happy with and will probably revisit at a later date when my coding improves. If anything is not clear please let me know. import psycopg2, ...


2

Sounds like you are not aware of the tool points to line! The line ID would be your CULV_ID. Would PTID be the order of your points? Having used that tool to create the lines you would to write some code that reads for each ID and build the fields to transfer the information over.


1

I'll try to do a little better job of explaining. This line is not necessary: arcpy.SelectLayerByAttribute_management("temp", "NEW_SELECTION", "FID" = count) Because you can instead just use the SearchCursor to loop through every feature in the temp layer, and use each feature's geometry object in the SelectByLocation. The geom variable is getting the ...


1

To try and debug this I would run the test below: import arcpy fc = "C:/Users/xkuai2/Downloads/temp/temp.shp" cursor = arcpy.SearchCursor(fc) for row in cursor: count = 0 Vol = row.getValue("Volume") print Vol This will mean your testing cycles are quicker than when doing the additional Geoprocessing. Your syntax up to that point looks OK to ...


0

The layers you add to your group layer has to be physically on disk or in an MXD. To add a layer to a group layer you need to get a list of layer in your MXD. Once you have this list, you can loop through it and see if the layer is a group layer. If it is get a reference to your layer in your directory and add it to the group layer. Sample code below ...


2

Raster Calculator is an option but limits what you can do. When using arcpy, you must convert your raster dataset to a raster object to perform map algebra. When defining the parameters in a python toolbox, it may be sufficient to change the data type to GPRasterLayer or GPRasterDataset. Otherwise, just cast the path of the raster to a raster object with ...


0

I presume you are looking for a solution in ESRI environment.That being the case customizing ESRI sample on drive time polygons or another JS sample could help you. Firstly you can find the drive time polygons for a given time period using centroid or some random locations within inner buffer of the precinct polygon.An intersection test of the resulting ...


2

How you have it now, you're going to run the tool using the FID and SHAPE fields. You need to limit your fields to the ones you actually want to use as input. Also, when you use field as the input in the tool, it's actually the field object. You need to use field.name instead. import arcpy #should use two backslashes in file path arcpy.env.workspace = ...


1

Here's the arcpy script. It will take a while to run, but should print out the information you need. On the desktop, create a new text file call "script.py" (rename the extension to .py instead of .txt), right-click, Edit in IDLE, paste in the following code, change the paths, and then hit F5 to run it. import arcpy shp = r"C:\path\to\shapefile.shp" ...


3

The topic that I think you are looking for is Linear Referencing and, to perform line-on-line overlay, the tool to use is Overlay Route Events. I recommend reviewing About overlaying event data: Overlaying events is another way to create new event data. This process combines two input event tables to create a single output event table. The new ...


1

Since I used from arcpy import * (not shown), the line: cursor = InsertCursor (outFc, ["SHAPE@XY", "PGA"]) ...was calling the older version of InsertCursor. The proper code is: cursor = da.InsertCursor (outFc, ["SHAPE@XY", "PGA"]) This line calls the data access InsertCursor.


0

I do not have access to the SPLINE command documentation of ArcInfo Workstation, but my recollection is that it was a command for "smoothing" the coordinates of vector features, whereas Spline from ArcGIS for Desktop: Interpolates a raster surface from points using a two-dimensional minimum curvature spline technique. I did not use the GRID module of ...


2

import arcpy from arcpy import * env.workspace = r"C:\IND_Rivers\New\Outputs\A3\a3_03.gdb" fcList = arcpy.ListFeatureClasses() #attempts to replace feature classes with "a1" with "a6" for fc in fcList: nn = 'a6' + fc[3:] arcpy.Rename_management(fc, nn)


2

As you have specified that the line from the point can pass in/out of the polygon then I think all you need to do is extract the Envelope of the polygon. You also state in the comment above you are look for an arcpy solution and you have a Basic license level. You can get most of the way with model builder and a sneaky use of the fishnet tool to extract the ...


1

So it turns out the tool doesn't exist. There is a request to ESRI to create it under the ideas site. If anybody comes across this post and has a similar need it would be great if you could vote for it too.


0

Following @crmackey with his mention of using the da (Data Access) module, the following code is pretty quick for this type of thing. However, as mentioned it requires 10.1 or higher. I have found that the da module is far superior when it comes to running through tables and performing tests on the data in ArcGIS. with arcpy.da.SearchCursor(fc, ...


3

I just wanted to point out that just using if not row.Stand may yield undesired results (remember, explicit is better than implicit from the Zen of Python). Take the following example: >>> for i, sample in enumerate(['a',1,None, '', ' ', 0]): if not sample: print 'value "{}" at index {} is empty'.format(sample, i) value "None" at ...


0

Convert the given polygon into a set of line segments.Find the nearest segment from the given point feature. You can also use ICurve interface to query the farthest edge.


0

From your description, I suspect that all you need to do is click the Refresh button near the lower left corner of your map, in order to refresh your Data View.


0

You want to be using dictionaries to answer this question. The answer in How to access adjacent rows will help you. To be able to answer your question you need to be supplying the row ID of the row you want to find the previous row from, my question is how are you defining that?


1

The code you require is below: import arcpy # Set workspace arcpy.env.workspace = r"C:\Scratch\fGDB_Scratch.gdb" # This returns a list of FeatureClasses in the top level of the geodatabase fcl = arcpy.ListFeatureClasses("*") # Main loop for fc in fcl: print "Adding fields to " + fc # The "#" inputs mean just use defaults ...


0

I believe with the append tool both source and destination table schemas have to be the same (field names/types). Here are some options: Use the Merge tool, select features, and field calculate (not recommended since you have to be careful what you have selected before calculating) Make sure the table schemas are the same between source and destination ...


2

I think you are seeing that particular error message from this line of your code: arcpy.KMLToLayer_conversion( r"C:\Project\gis\layers" ,r'C:\Project\gis') arcpy.KMLToLayer_conversion expects a file as its first parameter (KML or KMZ) but you are giving it a folder name. You could try concatenating the contents of your filename variable, with the ...


1

Below is the code you require: import arcpy xls = r"C:\Scratch\Book1.xls" table =r"C:\Scratch\tempxls.dbf" arcpy.ExcelToTable_conversion(xls,table) with arcpy.da.SearchCursor(table,["Feature"]) as cursor: for row in cursor: fd = row[0] print "Creating FeatureDataset: " + fd ...


0

I would probably go with ian's answer using the da cursor, but if you just want to 'fix' your script using the legacy cursor, it appears the dataset parameter isn't using your set workspace --- your workaround may be to enter the full path to your dataset. If you import os at the beginning of the script you can try this line substitution in your function: ...


1

As long as your query is structured correctly this should work. I used the da.SearchCursor instead because I noticed you were on 10.2. I also removed work from the function parameters because it wasn't being used anywhere. import arcpy arcpy.env.overwriteOutput = True workspace = "C:\\Users\\Cara\\Documents\\MPSGIS\\Programming and Scripting\\Lab6\\Lab 6 ...


0

Remove ".shp" from your featureClass string: fc= "Hospitals"


1

There is a problem with your code. if your code goes into this if statement: if lyr.name == "Parcels": then the layerStation will be None (it will not be assigned). Therefore, MakeFeatureLayer will throw an error. the proper code would be: for lyr in myLayers: if lyr.name == "Parcels": print "Parcels have been found." finalLayer = lyr ...


1

The documentation for Near Analysis indicates "NEAR_DISTANCE: The distance between the input and near feature. The value is in the linear unit of the input features coordinate system, or Meters when the Method parameter is set to GEODESIC and the input is in a geographic coordinate system." So my understanding of that statement is: A Geographic Coordinate ...


6

I would use format instead, since % is probably your wildcard character. def searchHospitals(work,strZip): fc= "Hospital.shp" whereClause= '"ZIPCODE" LIKE'+"'{0}%'".format(strZip) But you can also use double percent signs (%%) in your method: def searchHospitals(work,strZip): fc= "Hospital.shp" whereClause= '"ZIPCODE" LIKE'+"'%s%%'"% ...


1

I would suggest using a where clause to lessen the impact of pulling out geometry info that way you are not iterating through the entire table: import arcpy fc = 'c:/base/data.gdb/roads' class_field = 'Road Class' name_field = 'Name' # Create an expression with proper delimiters expression = arcpy.AddFieldDelimiters(fc, name_field) + ' = 2' # Create a ...


2

This is calling on the built in map function, which takes a function as the first argument (arcpy.AddError) and telling it to call AddError for every piece of the message split by a new line character. So for example, if the traceback message was this: Error Reading File: File is of the wrong type Needs to be CSV file the raw string would be: ...


1

If your license level allows it, use the Erase Tool. If you license level will not allow it, you can use a reverse mask and then Clip.


2

I figured it out. Rather than setting up a new variable "params" and holding the multiple parameters to be returned through that, I just simplified it to return the parameters directly as shown below. return [param0, param1] Now it loads the tool up when clicked on with both of the parameters correctly displayed. I guess it's best to keep it simple ...


1

I do not think that this can be done, and have never come across a requirement for it. My only thought was to try a backspace (\b) so I tried the code below behind a Python script tool: import arcpy arcpy.AddMessage("Doing something ...") arcpy.AddMessage ("\bDone") When I ran it this is what appeared in the tool results dialog:


0

I generally use something like this below (if I understand your question correctly) import arcpy arcpy.AddMessage("Sorting data") # code to sort data... arcpy.AddMessage("Done") This is an example from code I have used previously: arcpy.AddMessage(".....Sorting chainages based on distance") ...


0

I used IDV ( Integrated Data Viewer) software to extract (subset the .nc files). This gives 120 ( in the 2001-2010 period) monthly data. I used IDV again to process the monthly .nc files into annual means using a built-in timeseries average formula for each year. Data>Formula>Grids>Timesteps>Average Timesteps.This yields annual means. The annual means were ...


0

I was able to figure it out with a work around. I added the Lat/Long Fields and then us Convert Coordinate Notation. That generated a new feature class with two new fields: DDLat and DDLon. That got me what I needed even though I had to add a couple additional steps. The output was 076.###W, 37.####N as opposed to what I wanted which was (-76.###, 37.####) ...


1

If raster fields are not supported for use in an update cursor (see parameter 2 'field_names') you could consider using the Calculate Field (Data Management) tool on your mosaic dataset via arcpy? I just tested on a custom field and it worked as expected.


0

`Hi, ^Nebula93^, For the Create Feature Class and Add Field tools, there are a few parameters you have to sort out either in your CSV or in the script in order to make the tool abstract and generalizable like you want. For instance for your feature class, you need a variable for what geometry type is it (Point, Polygon?) and what coordinate system is it in ...


1

This is an old and long document from the 9.3 Help solved my problem. On right clicking the model and opening the properties, there was the option to use relative paths.


2

I think it is important to make this Q&A cover not just ArcGIS Desktop 10.0, Python 2.7 and Python 3.1, but also to incorporate the latest versions of desktop products from the ArcGIS platform and the Python programming language. For Python support in the (currently) latest desktop products from the ArcGIS platform I think you should consider: ArcGIS ...


4

As stated in the tool documentation for Calculate Field: Python expressions can use the geometry area and length properties with an areal or linear unit to convert the value to a different unit of measure (for example, !shape.length@kilometers!) These expressions are not usable with points or individual coordinates. Fortunately, you can use other ...


2

As requested, comment is appended below as an answer: "Also, is Feature To Polygon designed to work on a layer selection? Perhaps export the layer as a standalone feature class with Copy Features (in memory perhaps) and try running the tool that way. If that doesn't solve it, there are some threads here and here that use arcpy.Geometry.cut() for those who ...


1

If you really need your layer physically (e.g., saved on your disk), you should follow @Tangnar's advice, but if you want to play with the layer (basically what they are for), there is no such need (since you are testing layer behaviour by a script). Professionally I do not use (never, ever) MakeFeatureLayer_management to create layer in Python scripts but ...


0

Feature layers are temporary... From Arc Help "The layer that is created by the tool is temporary and will not persist after the session ends unless the layer is saved to disk or the map document is saved." If you are trying to save it, you need to save it as a layer file, or save it as a feature class. ...



Top 50 recent answers are included