|
POST
|
import arcpy
import pandas as pd
for lyr in arcpy.mapping.ListLayers(mxd, "", df):
if lyr.name == 'LV UG Electric Line SegmentH':
narr = arcpy.da.FeatureClassToNumPyArray(lyr, ('SubtypeCD', 'SHAPE_Length'))
df = pd.DataFrame(narr, columns=['SubtypeCD', 'SHAPE_Length'])
idxs = df.groupby(by='SubtypeCD', as_index=True)['SHAPE_Length'].sum()
print idxs
... View more
10-12-2017
07:56 AM
|
2
|
1
|
4076
|
|
POST
|
This thread shows how they set the workspace to a specific version: https://gis.stackexchange.com/questions/123621/how-to-get-a-search-cursor-on-a-particular-version-in-arcpy
... View more
10-09-2017
11:21 AM
|
1
|
0
|
4632
|
|
POST
|
You should be able to get the version info from the feature classes themselves. Just add to my previous example some ESRI sample code: import arcpy
import os
mxdpath = os.path.join('PathToTheMxd','SomeMXDFile.mxd')
mxd = arcpy.mapping.MapDocument(mxdpath)
df = arcpy.mapping.ListDataFrames(mxd)[0]
for lyr in arcpy.mapping.ListLayers(mxd, "", df):
print lyr.name
dirname = os.path.dirname(arcpy.Describe(lyr).catalogPath)
desc = arcpy.Describe(dirname)
# Print workspace properties
#
print("%-24s %s" % ("Connection String:", desc.connectionString))
print("%-24s %s" % ("WorkspaceFactoryProgID:", desc.workspaceFactoryProgID))
print("%-24s %s" % ("Workspace Type:", desc.workspaceType))
# Print Connection properties
#
cp = desc.connectionProperties
print("\nDatabase Connection Properties:")
print("%-12s %s" % (" Server:", cp.server))
print("%-12s %s" % (" Instance:", cp.instance))
print("%-12s %s" % (" Database:", cp.database))
print("%-12s %s" % (" User:", cp.user))
print("%-12s %s" % (" Version:", cp.version))
... View more
10-09-2017
11:00 AM
|
1
|
1
|
4632
|
|
POST
|
I'm not fully clear on your issue(s) but to access the layers within an mxd you could try something like: mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
for lyr in arcpy.mapping.ListLayers(mxd, "", df):
if lyr.name == "SomeLayerName":
'do stuff to the lyr
... View more
10-09-2017
10:42 AM
|
0
|
4
|
4632
|
|
POST
|
Hi Mike, See my last post on this thread. I show how I broke it all down using arcpy methods.
... View more
10-06-2017
10:31 AM
|
0
|
0
|
5992
|
|
POST
|
Edit: Sorry, I misread/misunderstood what you were asking for. You will want to implement urlib2. approw[2] is the 'SHAPE@JSON' key of a SearchCursor of the feature class we are intersecting with the map service features. import urllib, urllib2
#process waterbody features
#FDEP is the authoritative source and steward for this data and is accessed via thier published map service
queryURL = "http://ca.dep.state.fl.us/arcgis/rest/services/OpenData/WBIDS/MapServer/0/query"
params = urllib.urlencode({'f': 'json', 'geometryType': 'esriGeometryPolygon',
'geometry': approw[2], 'spatialRel': 'esriSpatialRelIntersects',
'where': '1=1', 'outFields': 'WBID,WATER_TYPE,WATERBODY_NAME,CLASS', 'returnGeometry': 'false'})
req = urllib2.Request(queryURL, params)
response = urllib2.urlopen(req)
print '*** req start ***'
print str(approw[2])
print '*** req end ***'
jsonResult = json.load(response)
for feature in jsonResult['features']:
wbdy = feature['attributes']['WATERBODY_NAME']
wbdytype = feature['attributes']['WATER_TYPE']
wbid = feature['attributes']['WBID']
wbdyclass = feature['attributes']['CLASS']
#print wbdy, wbdytype, wbid
values = {'WATERBODYID': wbid,
'WATERBODYNAME': wbdy,
'WATERBODYTYPE': wbdytype,
'WATERBODYCLASS': wbdyclass
}
waterbodieslst.append(values)
data.update({'WATERBODIES': waterbodieslst})
... View more
10-05-2017
10:32 AM
|
1
|
1
|
1653
|
|
POST
|
ah ha! The solution is to implement arcpy.GridIndexFeatures_cartography along with the fishnet output. No Advanced licensing needed and still keeps processing sub-10secs
... View more
10-04-2017
11:02 AM
|
0
|
0
|
938
|
|
POST
|
Thanks for the idea! I implemented it and it performed well, very close to the Fishnet approach I laid out. Unfortunately, the Dice_management requires an Advanced license level, which is not available on the ArcGIS Server this GP service will be published too. This also has me back at the drawing board to get the output Fishnet line features converted to polygons too because the FeatureToPolygon_management I implemented in my example solution requires that same Advanced license.
... View more
10-04-2017
10:18 AM
|
0
|
0
|
938
|
|
POST
|
Edit: added clip_analysis to generate the final polygons to use in SelectLayerByLocation process. I think the best solution I've tested so far is to break up the polygon into individual polygons and then iterating over each polygon to perform the SelectbyLocation on the point features, checking to see if any features fall inside, then break out of that loop if that's the case. Pretty straight forward: 1. CreateFishnet_management of the polygon feature. 2. FeatureToPolygon_management of the output Fishnet 3. Search cursor loop over each polygon in the fishnet 4. SelectLayerByLocation and perform test to count result. 5. If count > 0 then break and return with Boolean TRUE What's interesting and the challenge is that the combination of rows/cols for the fishnet vs. the overall size of the input polygon geometry will determine the efficiency of the overall process. That is, if it's a large input polygon and too many rows/cols are created for the fishnet, then it will take longer to loop, but it also takes less time to SelectLayerByLocation. There's a direct correlation between the content of the fishnet vs. the processing time of the SelectLayerByLocation. That is, if the faster it finds points within one of the fishnet polygons, the faster the overall process. This beats any straight-up SelectLayerByLocation call against the full extent of the original point / polygon feature classes! arcpy.MakeFeatureLayer_management(pnt_fc, "PointFeatures")
extent = polygon.extent
originXY = extent.lowerLeft
yaxisXY = extent.upperLeft
opp_corner =extent.upperRight
print "origin: " + str(originXY)
print "yaxis: " + str(yaxisXY)
print "opposite corner: " + str(opp_corner)
#keep the cell width/height set to zero as it will use the opp_corner to figure it out
cellWidth = 0
cellHeight = 0
#plug in the #rows/#cols you want the output grids to contain
nrows = 4
ncols = 4
outFC = r'in_memory\outsections_line'
outFishnet = r'in_memory\outsections'
outClip = r'in_memory\clipfeatures'
arcpy.CreateFishnet_management(outFC, str(originXY), str(yaxisXY), cellWidth, cellHeight, nrows, ncols, str(opp_corner))
arcpy.FeatureToPolygon_management(outFC, outFishnet)
arcpy.Clip_analysis(outFishnet, polygon, outClip)
with arcpy.da.SearchCursor(outClip, ['SHAPE@']) as outcur:
for outrow in outcur:
tshape = outrow[0]
arcpy.SelectLayerByLocation_management("PointFeatures", "INTERSECT", tshape)
rowcounter = int(arcpy.GetCount_management("PointFeatures").getOutput(0))
if rowcounter > 0:
print "rowcounter: " + str(rowcounter)
return True
break
else:
print "rowcounter: " + str(rowcounter)
... View more
10-03-2017
01:12 PM
|
1
|
0
|
9376
|
|
POST
|
Ultimately, the FGDB is local to the ArcGIS Server that it is registered to. I will check on the z-values. Thanks for your input!
... View more
10-03-2017
11:01 AM
|
0
|
0
|
3384
|
|
POST
|
It's not clear to me how I will efficiently set the "pnts" array from the point feature class containing the 85million features. arcpy.da.FeatureClassToNumPyArray is very slow.
... View more
10-03-2017
10:32 AM
|
0
|
1
|
3384
|
|
POST
|
I don't know what could be the issue, but I'd think TruncateTable_management would be the better option if you are simply deleting all features/rows and then appending (no recovery of deleted features though!). Also, be sure to correctly implement arcpy.ClearWorkspaceCache_management since you are working in an enterprise environment and this should help to eliminate connections. I've not done much with Append and typically rely on arcpy.da cursor to perform appends, updates and deletes.
... View more
10-03-2017
09:56 AM
|
1
|
1
|
2203
|
|
POST
|
Is it a complete deletion of all features and then append? If so, perhaps TruncateTable_management is appropriate (I think requires owner account to perform this operation tho). Define "trouble getting it to work". Any error messages? Which lines of code failed? If it's an enterprise dataset, is it versioned? Are you starting/stopping an edit session? We were having some issues with SDE updates on non-versioned feature classes (Oracle) and cleared things up by implementing arcpy.ClearWorkspaceCache_management.
... View more
10-03-2017
07:02 AM
|
0
|
3
|
2203
|
|
POST
|
Thank you for the idea! The Generate Near Table was not as efficient compared to the SelectByLocation method.
... View more
10-03-2017
05:52 AM
|
0
|
2
|
3384
|
|
POST
|
Great work Dan -- I'll take what I can and implement something now. Following the document too.
... View more
10-02-2017
06:14 AM
|
0
|
1
|
3385
|
| 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
|