|
POST
|
#specify the workspace rasters are located in
ws = "H:\Documents\ArcGIS\Default.gdb"
arcpy.env.workspace = ws
#for each Raster in the workspace, do something
rasters = arcpy.ListRasters()
for r in rasters:
desc = arcpy.Describe(r)
rastername = desc.Name
print "Raster Name: %s" % (rastername)
... View more
04-07-2014
03:49 AM
|
0
|
0
|
699
|
|
POST
|
the indents dont show up in the copy paste, but they are indented as needed. i get no errors on that Use the "#" Code Wrap function on the toolbar when you make a post
import arcpy
from arcpy import env
env.workspace = "C:\work"
env.overwriteOutput = True
# Local variables
Voters = "Voters.shp" # these are the voters, point file
PollingSite = "Polling.shp" # this is the point file of the voter sites
distance = "distance.DBF" # this will be the output of the distance table
#need to define rows, updatecursor seems to be required
rows = arcpy.UpdateCursor(PollingSite)
rows2 = arcpy.UpdateCursor(Voters)
#run a for loop to go to each row in attribute table.
for row in rows: #rows is the PollingSite shapefile
p_precinct = row.Pre #this is the precinct column for PollingSite
v_precinct = rows2.PrecinctNa # this is the precinct column for Voters
if p_precinct == v_precinct:
PointDistance_analysis(Voters, PollingSite, distance)
... View more
04-04-2014
03:23 AM
|
0
|
0
|
2609
|
|
POST
|
I don't have this Foundation extension to be able to test but if it works in your ArcMap/Python environment but not in a PythonIDE, then perhaps an environment variable is confusing you IDE install somehow. That is, the Python executing from ArcMap is using the correct Python.exe install but your standalone copy is not. Just a guess really.
... View more
03-26-2014
09:30 AM
|
0
|
0
|
2511
|
|
POST
|
Just a shot in the dark, but maybe problem is with escape characters in your string paths? Or perhaps not having the extension available? Not sure but you can deal with these possible issues:
in_ds = r'C:\Temp\Python\GRSM_20140326075058.gdb\Boundaries_And_AOIs\grsm_bndry_polygon'
target_db = r'C:\Temp\Python\GRSM_20140326075333.gdb'
### see if spatial analyst extension is available for use
availability = arcpy.CheckExtension("Foundation")
if availability == "Available":
arcpy.CheckOutExtension("Foundation")
arcpy.AddMessage("Foundation Ext checked out")
else:
arcpy.AddError("%s extension is not available (%s)"%("Foundation Extension",availability))
arcpy.AddError("Please ask someone who has it checked out but not using to turn off the extension")
return
arcpy.ExtractData_production(in_ds,target_db,"DO_NOT_REUSE","NO_FILTER_BY_GEOMETRY","INTERSECTS","")
#return the extension
arcpy.CheckInExtension("Foundation")
... View more
03-26-2014
07:27 AM
|
0
|
0
|
2511
|
|
POST
|
Alternative to ESRI stack is to use Pandas library for this kind of stuff. Here I just pulled in your sample data into the Default.gdb as a table, but it could also be a feature class too -- doesn't really matter. Or it could be just about any data source (.txt, .csv, cx_Oracle cursor, etc...) Here's a GIS-centric solution using Pandas. Source data sampdata.csv: ID,Field01,Field02,Field03 01,Q1,W1,02.00 02,Q1,W1,48.00 03,Q1,W2,50.00 04,Q2,W3,90.00 05,Q2,W4,10.00
import pandas as pd
import numpy as np
#just pull in sample data into a gbd table
_dfsource = r'H:\Documents\ArcGIS\Default.gdb\sampdat'
#specify fields to use and convert the gdb tab to a numpy array
flds = ['ID', 'Field01', 'Field02', 'Field03']
_numparr = arcpy.da.TableToNumPyArray(_dfsource, flds)
#convert the numpy array to a pandas data frame for easy-peezy grouping functions
_dfarr = pd.DataFrame(_numparr, columns=['ID', 'Field01', 'Field02', 'Field03'])
_dfarrGrouped = _dfarr.groupby(['Field01'])['Field03'].max().reset_index()
print _dfarrGrouped
Result: Field01 Field03 0 Q1 50 1 Q2 90
... View more
03-26-2014
04:23 AM
|
0
|
0
|
3131
|
|
POST
|
jamesfreddyc that sounds intresting, but how would pass the click (input) to do the selection by location on the parcels? thanks for the replay. See this thread for some examples: http://gis.stackexchange.com/questions/49713/select-and-copy-features-in-arcmap-using-python-add-in-tool Important part is: def onMouseDownMap(self, x, y, button, shift): mxd = arcpy.mapping.MapDocument("CURRENT") pointGeom = arcpy.PointGeometry(arcpy.Point(x, y), mxd.activeDataFrame.spatialReference) searchdistance = getSearchDistanceInches(mxd.activeDataFrame.scale) lyr = arcpy.mapping.ListLayers(mxd)[0] # assumes you want to select features from 1st layer in TOC arcpy.SelectLayerByLocation_management(lyr, "INTERSECT", pointGeom, "%d INCHES" % searchdistance) arcpy.RefreshActiveView() Make sure "lyr" is referencing your Parcel layer, then after the refresh you should be able get access to the attributes with a SearchCursor. Use the values in the cursor to populate your point feature with. (note: I have not implemented the code above, so you would have validate it works.)
... View more
03-25-2014
09:15 AM
|
0
|
0
|
2800
|
|
POST
|
Yeah, I've seen that, but I don't really see how it helps unless I'm missing something obvious. Not sure. off topic: you must have helped a lot of members to get >4 billion points! wow!
... View more
03-24-2014
10:16 AM
|
0
|
0
|
2279
|
|
POST
|
Relevant info at the bottom of the reference page with example that may help you figure it out http://resources.arcgis.com/en/help/main/10.1/index.html#//002z0000001q000000
... View more
03-24-2014
09:38 AM
|
0
|
0
|
2279
|
|
POST
|
I have not performed this operation and unsure of an exact solution, but have a look at the arcpy.ImportXMLWorkspaceDocument_management method: http://resources.arcgis.com/en/help/main/10.1/index.html#//00170000014s000000 IIRC, you can specify the target Geodatabase as an ArcSDE instance, perhaps if you have connections already setup you can simply reference the .sde file to set the workspace??? Not sure on that but might be worth to check into.
... View more
03-24-2014
03:57 AM
|
0
|
0
|
1904
|
|
POST
|
Thanks for the suggestions, but I'm looking to avoid a counter. arcpy.GetCount_management doesn't work for you?
... View more
03-21-2014
12:22 PM
|
0
|
0
|
17208
|
|
POST
|
This works (and should honor any selections):
myFeatClass = r'C:\MyGDB\myFeatureClass'
result = int(arcpy.GetCount_management(fc).getOutput(0))
print result
This also works:
rowcount = 0
myFeatClass = r'C:\MyGDB\myFeatureClass'
with arcpy.da.SearchCursor(myFeatClass, "*") as cursor:
for row in cursor:
count = count + 1
print rowcount
Edit: You can also apply an sql conditional statement too
rowcount = 0
sql = "OBJECTID = 29821"
myFeatClass = r'C:\MyGDB\myFeatureClass'
with arcpy.da.SearchCursor(myFeatClass, "*", sql) as cursor:
for row in cursor:
count = count + 1
print rowcount
... View more
03-21-2014
11:23 AM
|
2
|
0
|
17208
|
|
POST
|
This is a new script that i am trying to build and get working. I am not sure if it's working or not because when i run it the script that i posted above ArcMap just sits there thinking and thinking, i eventually have to use task manager to close arc map. I believe my problem is that the script takes every point and every taxparcels in the spatial join instead of just the newly point and the taxparcel it sits on. but i am not 100% certain becasue my python is not very good. what i have been trying to is do a select by location on the parcel layer to see what parcel the new point sits on then populate/copy the point with certain fields from that selected parcel only. As an alternative to a SelectByLocation after your point creation process, why not collect the Parcel attributes when you first click the location to create the point? Hold them in variables to populate the attributes of the new point feature you create later. This would alleviate the need to perform a lengthy SelectByLocation process (if that is what is causing your performance hit, my guess this is the culprit if you have 10's of thousands of parcels).
... View more
03-21-2014
07:20 AM
|
0
|
0
|
879
|
|
POST
|
https://pypi.python.org/pypi/pyBarcode/0.7 Then insert the resulting .png into layout?
... View more
03-20-2014
11:47 AM
|
0
|
0
|
3498
|
|
POST
|
Is it possible to update the data in enterprise Geodatabase using Python Script? e.g. insert , update, delete etc. I want to store some data in my Model Builder, based on some condition. If yes, then how. Please share some code snippets. define "data". Is the SDE db versioned? Maybe this will get you started: http://resources.arcgis.com/en/help/main/10.1/index.html#//018w00000005000000
... View more
03-20-2014
09:40 AM
|
0
|
0
|
702
|
|
POST
|
This works for me.
if arcpy.Exists("in_memory\\matchtable"):
arcpy.Delete_management("in_memory\\matchtable")
## setup for the attachments
input = r"H:\Documents\ArcGIS\Default.gdb\InstantValues"
inputField = "InstantValues_staname"
matchTable = arcpy.CreateTable_management("in_memory", "matchtable")
matchField = "STATION"
pathField = "Picture"
arcpy.AddField_management(matchTable, matchField, "TEXT")
arcpy.AddField_management(matchTable, pathField, "TEXT")
picFolder = str(outfolder)
## check to see if matchtable exists and remove attachements if it does
fields = ["STATION", "Picture"]
cursor = arcpy.da.InsertCursor(matchTable, fields)
##go thru the picFolder of .png images to attach
for file in os.listdir(picFolder):
if str(file).find(".png") > -1:
pos = int(str(file).find("."))
newfile = str(file)[0:pos]
cursor.insertRow((newfile, file))
del cursor
# the input feature class must first be GDB attachments enabled
arcpy.EnableAttachments_management(input)
# use the match table with the Add Attachments tool
arcpy.AddAttachments_management(input, inputField, matchTable, matchField, pathField, picFolder)
arcpy.AddMessage("Attachments enabled/created")
... View more
03-19-2014
05:38 AM
|
0
|
0
|
1915
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 02-17-2020 10:47 AM | |
| 1 | 10-25-2022 11:46 AM | |
| 1 | 08-08-2022 01:40 PM | |
| 1 | 02-15-2019 08:21 AM | |
| 2 | 08-14-2023 07:14 AM |
| Online Status |
Offline
|
| Date Last Visited |
01-22-2025
02:28 PM
|