POST
|
Sorry.. here's the formatted version of the code if testCount==0:
msg = "You must first add a polygon layer or feature class and select some features to report their acreage."
pythonaddins.MessageBox(msg, 'Area Report', 0)
else:
for lyr in arcpy.mapping.ListLayers(mxd):
if lyr.isGroupLayer:
for sublyr in lyr:
tlyr = lyr
else:
tlyr = lyr
dsc = arcpy.Describe(tlyr)
sel_set = dsc.FIDSet
if dsc.shapeType == "Polygon":
if len(sel_set) > 0:
with arcpy.da.SearchCursor(tlyr, ("OID@", "SHAPE@AREA")) as cursor:
for row in cursor:
parea = row[1] + parea
resSQFT = parea
resAC = parea / 43560
resHA = parea / 107639.104
... View more
05-02-2014
12:05 PM
|
0
|
0
|
143
|
POST
|
Sorry.. here's the formatted version of the code if testCount==0: msg = "You must first add a polygon layer or feature class and select some features to report their acreage." pythonaddins.MessageBox(msg, 'Area Report', 0) else: for lyr in arcpy.mapping.ListLayers(mxd): if lyr.isGroupLayer: for sublyr in lyr: tlyr = lyr else: tlyr = lyr dsc = arcpy.Describe(tlyr) sel_set = dsc.FIDSet if dsc.shapeType == "Polygon": if len(sel_set) > 0: with arcpy.da.SearchCursor(tlyr, ("OID@", "SHAPE@AREA")) as cursor: for row in cursor: parea = row[1] + parea resSQFT = parea resAC = parea / 43560 resHA = parea / 107639.104
... View more
05-02-2014
10:39 AM
|
0
|
0
|
143
|
POST
|
I am working on what I thought was a simple button to calculate the area of a selected polygon.. however the script fails if there is a raster dataset loaded in the .mxd - even if it is not selected, due to the FIDSet command.. any ideas on how to get around this (other than removing the raster)? Code in reply below...
... View more
05-02-2014
10:02 AM
|
0
|
2
|
480
|
POST
|
I love this thread. I got the code working by saving a new layer and polygon object to memory but it just "felt" bulky.. I also recently just got upgraded to 10.1 so hadn't heard of the da module before, but I'm excited to try it out. THANK YOU both!!
... View more
10-01-2013
12:16 PM
|
0
|
0
|
526
|
POST
|
Thanks Dave. That looks like it's what I want. However, I'm still mentally stuck on populating the polygon object based on a selected feature. Would you do this using the CopyFeatures_management function?
... View more
09-30-2013
11:44 AM
|
0
|
0
|
526
|
POST
|
Good afternoon, I'm working on a custom button using the Python GUI and perhaps add-in manager in 10.1 to calculate the area of a selected polygon and then display the result as a popup message box. I've got several of the pieces together, using an IF loop with GetCount() to verify a record has been selected before proceeding and easygui.msgbox to report the result; however I'm struggling to figure out how to calculate the area of the selection without writing to the attribute table. I don't want to have to create a new feature class or table - I want to allow a user to interactively select a polygon, calculate the geometry on the fly, or in memory, convert the number to acres, if necessary, and use that result as the variable to report in my pop-up. Any ideas?
... View more
09-30-2013
11:04 AM
|
0
|
5
|
2712
|
POST
|
Your solution would work, but I need to develop a where clause to select an individual county.. here's my outline: inCnty = "flcounties.shp" inHos= "flhospit.shp" arcpy.MakeFeatureLayer_management(inHos, "hospitals_FL", "POP2000 > 1000000") # make a featurelayer for flhospit arcpy.MakeFeatureLayer_management(inCnty, "county_FL") # make a featurelayer for flcounties popFld = "POP2000" delimitedName = arcpy.AddFieldDelimiters(inCnty, popFld) where = delimitedName + ">1000000" rows = arcpy.SearchCursor(inCnty, where) row = rows.next() while row : # build a new where clause to get single county with pop 1M+ - this is where I'm stuck # use SelectLayerByAttribute_management for the single county from the county featurelayer # use SelectLayerByLocation_management to select out the hospitals within the single county # copy the selection as a new feature class (may be a temporary one) # use a new search cursor to the new feature class, loop through and get the count of hospitals row = rows.next() del row del rows
... View more
11-05-2011
06:15 AM
|
0
|
0
|
253
|
POST
|
I am trying to write a python program using a "counties.shp" shapefile and a "hospitals.shape" shapefile. I need to find out which counties have more than one million population in 2000 and for the counties with more than one million people in 2000, find out how many hospitals are within each county. Counties.shp has a field called POP2000 that lists the county's population Hospitals.shp has a field called COUNTY that lists the county the hospital is found in. I was able to do the first part by: def findpop(): rows = arcpy.SearchCursor("counties.shp") row = rows.next() popFld = "POP2000" while row: ctyPop = row.getValue(popFld) if ctyPop > 999999 : ctyName = row.NAME #print "County: ", ctyName, "\tPopulation: ", ctyPop ctylst.append(ctyName) row = rows.next() but I am having trouble with the WHERE clause on the second part. I need to use the identified counties from the first operation for the next one. This is what I've come up with, but after making quite a mess of it, I'm of ideas.. can someone help? SO say, County1 and County2 had more than 1 million people I need to find out how many hospitals are in County 1 and how many are in County 2 ctyFld = "COUNTY" where = ctyFld = ctylst rows = arcpy.SearchCursor("hospital.shp, where") row = rows.next() hospTotal = 0 i = 0 while row : ctychck = ctylist where " hospTotal += 1 i+=1 row = rows.next() print hospTotal
... View more
11-01-2011
04:19 PM
|
0
|
3
|
364
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|