|
POST
|
I added a possible solution to your post in the Python forum section.
... View more
12-19-2017
10:24 AM
|
0
|
0
|
1949
|
|
POST
|
Setup a request and process the response using json, urlib import json
import urllib, urllib2, urlparse
qURL = "https://somedomain.com/rest/services/GPServicename/GPServer/GPTaskName/execute"
params = urllib.urlencode({'f': 'json',
'inputGUID': <some value>,
'inputFilePath': <some value>,
'returnZ': 'false', 'returnM': 'false'})
req = urllib2.Request(qURL, params)
response = urllib2.urlopen(req)
jsonResult = json.load(response)
print jsonResult
#parse the result as necessary
... View more
12-19-2017
10:07 AM
|
0
|
0
|
1700
|
|
POST
|
I think this is close: lastEditDateStr = feature['attributes']['last_edited_date']
s = lastEditDateStr/ 1000.0
dFormat = "%Y-%m-%d %H:%M:%S.%f"
d = datetime.datetime.fromtimestamp(s).strftime('%Y-%m-%d %H:%M:%S.%f')
... View more
12-19-2017
07:53 AM
|
1
|
0
|
2160
|
|
POST
|
I'm querying against an ArcGIS Server feature service and need an assist to convert the date information being returned. The feature class itself has editor tracking enabled and I'd like to format the last_edit_date value. Description: {
"name": "last_edited_date",
"alias": "last_edited_date",
"type": "esriFieldTypeDate",
"length": 8
} Value: "last_edited_date": 1512413066000 I'd like to take the value and apply this format: '%Y-%m-%d %H:%M:%S' So far I'm not seeing any success with the various attempts: #go thru the response
for feature in jsonResultApp['features']:
lastEditDateStr = feature['attributes']['last_edited_date']
dFormat = "%Y-%m-%d %H:%M:%S.%f"
#all of these below fail with various errors
#attempt 1
lastEditDate = datetime.datetime.fromtimestamp(lastEditDateStr).strftime('%Y-%m-%d %H:%M:%S')
#attempt 2
lastEditDate = datetime.datetime.fromtimestamp(lastEditDateStr).strftime('%c')
#attempt 3
lastEditDate = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(lastEditDateStr))
#attempt 4
lastEditDate = datetime.datetime.strftime(d1, dFormat)
... View more
12-19-2017
07:34 AM
|
0
|
1
|
3120
|
|
POST
|
I think I've been able to work thru this. Pretty sure it's your original code that I'm trying to parse a JSON result --- that iteritems() always confused me on how to access other attributes from the source. countyCount = (jsonResult['features'])
if countyCount > 0:
for key,value in jsonResult.iteritems():
if value == 'FeatureCollection':
pass
else:
for i in value:
try:
for k1,v1 in i.iteritems():
if k1 == 'attributes':
cn = v1['POLYGON_NM']
for k,v in i.iteritems():
if k == 'geometry':
features = []
feature = v['rings']
#countyPolygon = arcpy.Polygon(arcpy.Array([arcpy.Point(*coords) for coords in feature]), inSr)
for feat in feature:
polyArray = arcpy.Array()
for pointsPair in feat:
newpoint = arcpy.Point(*pointsPair)
polyArray.add(newpoint)
countyPolygon = arcpy.Polygon(polyArray)
insertCursor = arcpy.da.InsertCursor(tmpCounties, ['SHAPE@','COUNTYNAME'])
insertData = countyPolygon, cn
insertCursor.insertRow(insertData)
else:
pass
except:
pass
... View more
12-18-2017
01:15 PM
|
1
|
0
|
3411
|
|
POST
|
It's a dictionary populated from a map service layer. My requirement is to be able to clip polygon features in this map service, but that is not available via REST, so I plan to get the features of interest from the map service with its attributes (NOT just the coordinate info), then convert to a temporary feature class that I can then clip.
... View more
12-18-2017
12:15 PM
|
0
|
1
|
3411
|
|
POST
|
What's fastest way to convert the dictionary below of polygon features into an in_memory feature class? {
"COUNTIES": [
{
"COUNTY": "COUNTY 1",
"COUNTYRINGFEATURE": {
"rings": [
[
[
-8930981.5967,
3040606.1534
],
[
-8930880.296,
3040593.7322000004
],
[
-8930860.2585,
3040604.911200002
],
[
-8930361.547,
3040438.4703
],
[
-8929910.703,
3040288.178100001
],
[
-8929241.6727,
3040065.848200001
],
[
-8928384.5124,
3039780.1779000014
],
[
-8928253.1552,
3039740.4329000004
],
[
-8930981.5967,
3040606.1534
]
]
]
},
"COUNTYOID": 50
},
{
"COUNTY": "COUNTY 2",
"COUNTYRINGFEATURE": {
"rings": [
[
[
-8947371.1721,
3118264.7214
],
[
-8947243.1547,
3118263.4723999985
],
[
-8946191.1852,
3118252.2322999984
],
[
-8946173.3741,
3118252.2322999984
],
[
-8946160.0158,
3118250.9833999984
],
[
-8946099.9032,
3118250.9833999984
],
[
-8945873.9246,
3118249.7346
],
[
-8945723.6431,
3118244.7388000004
],
[
-8945527.7209,
3118244.7388000004
],
[
-8945303.9686,
3118242.2410999984
],
[
-8945138.1025,
3118238.4943999983
],
[
-8945100.2539,
3118238.4943999983
],
[
-8941077.1663,
3118199.7786
],
[
-8937553.9034,
3118162.3117000014
],
[
-8947371.1721,
3118264.7214
]
]
]
},
"COUNTYOID": 61
}
]
}
... View more
12-18-2017
11:31 AM
|
1
|
10
|
4511
|
|
POST
|
Looking at the dba's schema printout: they are entirely different SLQ Server db's: db1: "read only, nonversioned" db2: "editable, nonversioned" Also, switching the order produced similar initial times on the first connection, subsequent connections no matter if it is an entirely different db are much faster. So, I guess it's not anything specific to the SDE connection or db, rather with how the python execution spins up those connections.
... View more
12-14-2017
02:03 PM
|
1
|
0
|
2521
|
|
POST
|
I'm just timing each method to arcpy.MakeFeatureLayer_management -- and I might see 6 seconds on the first workspace (print msgtscratch), while the other may be 1 second or less (print msgtscratch2)! Something like this: #time the first make feature layer call from SDE gdb1
tscratch = Timer()
with tscratch:
arcpy.MakeFeatureLayer_management(input_fc1, "input_fl1")
msgtscratch = "Create Scratch FL (EGIS) completed in %.02f secs." % (tscratch.interval)
print msgtscratch
#time the first make feature layer call from SDE gdb2
tscratch2 = Timer()
with tscratch2:
arcpy.MakeFeatureLayer_management(input_fc2, "input_fl2")
msgtscratch2 = "Create Scratch FL2 (EGIS2) completed in %.02f secs." % (tscratch2.interval)
print msgtscratch2
... View more
12-14-2017
12:50 PM
|
0
|
2
|
2521
|
|
POST
|
Randy, I have a Timer class that I use: class Timer:
def __enter__(self):
self.start = time.clock()
return self
def __exit__(self, *args):
self.end = time.clock()
self.interval = self.end - self.start Then just generate time messages at runtime to print out. tscratch = Timer()
with tscratch:
arcpy.MakeFeatureLayer_management(input_fc1, "input_fl1")
msgtscratch = "Create Scratch FL (EGIS) completed in %.02f secs." % (tscratch.interval)
print msgtscratch This is being executed in pyScripter.
... View more
12-14-2017
12:35 PM
|
0
|
4
|
2521
|
|
POST
|
I'm seeing wildly different performance when establishing Feature Layers in different SDE databases. ws1 = r'\\somenetworkpath\gdb1.sde'
fcname = r'gdb1.someschema.FCNAME
input_fc1 = os.path.join(ws1, fcname)
arcpy.MakeFeatureLayer_management(input_fc1, "input_fl1")
ws2 = r'\\somenetworkpath\gdb2.sde'
fcname = r'gdb2.someschema.FCNAME
input_fc2 = os.path.join(ws2, fcname)
arcpy.MakeFeatureLayer_management(input_fc2, "input_fl2") In the above examples, ws1 takes over 6 seconds on the MakeFeatureLayer_management line, while the other is sub-1 second! ws1 is a "publication" SDE database where no editing is done. ws2 is non-versioned editing. Any input or what to look for? Thanks!
... View more
12-14-2017
12:15 PM
|
0
|
6
|
2735
|
|
POST
|
Not sure if having update cursor within search cursors is a good idea. I think you may want to research on populating some kind of list or dictionary with the area totals and their OID's, then use that dictionary in a new update cursor. Sorry I haven't gone down that road.
... View more
12-06-2017
02:00 PM
|
0
|
0
|
3263
|
|
POST
|
See if this works: # Set the necessary product code
# import arcinfo
# Import the Arcpy Module
import arcpy
from arcpy import env
# Set up the working Environment
env.workspace = r"D:\Travis\Personal\Geoff\Nantucket\Zoning\Backlots\Backlots.gdb"
env.overwriteOutput = True
#Variables
Parcels ="R40_80000sqft"
Structures = "Nantucket_Structres"
arcpy.MakeFeatureLayer_management(parcels,"Parcels_lyr")
arcpy.MakeFeatureLayer_management(Structures,"Struc_Lyr")
Struc_Lyr = "Struc_Lyr"
Parc_Lyr = "Parcels_Lyr"
#Add a field to parcels to be populated with building area
#arcpy.AddField_management("R40_80000sqft","Bldg_Area","DOUBLE")
with arcpy.da.SearchCursor(Parc_Lyr, ['Shape@']) as parcelcursor:
for parcelrow in parcelcursor:
#get the geometry to use in the spatial selection
geom = parcelrow[0]
#select feature from the other layer using the geom variable
arcpy.SelectLayerByLocation_management(Struc_Lyr, "HAVE_THEIR_CENTER_IN", geom, "", "NEW_SELECTION")
#get the area of the selected features and sum
areasum = 0
with arcpy.da.SearchCursor(Struc_Lyr,['Shape@AREA']) as newcursor:
for newrow in newcursor:
areasum = areasum + newrow[0]
print areasum
... View more
12-06-2017
12:17 PM
|
2
|
8
|
5720
|
|
POST
|
Travis -- it's much easier for us to reply with the corrected code if you paste in your code rather than a screenshot. It looks like the problem is with the cursor. Change "Shape@" to "SHAPE@AREA'"). Like this, with arcpy.da.SearchCursor(Struc_lyr, ['SHAPE@AREA']) as newcursor:
for newrow in newcursor:
areasum = areasum + newrow[0]
... View more
12-06-2017
10:57 AM
|
2
|
10
|
5720
|
|
POST
|
Yes, I fixed the code sample. Sorry, pulled this from another implementation and missed that -- it just needs some tweaking. Looks like you have line indent issues. Look at your line #34 and make it line up with the line below it Also, you need to set "SHAPE@" as the field to use in the first cursor, not "Shape_Area". Also, make sure your "Structures" is a FeatureLayer, not a feature class for your SelectLayerByLocation_management. http://desktop.arcgis.com/en/arcmap/10.3/tools/data-management-toolbox/select-layer-by-location.htm with arcpy.da.SearchCursor(parcels, ['SHAPE@']) as parcelcursor:
for parcelrow in parcelcursor:
#get the geometry to use in the spatial selection
geom = parcelrow[0]
#select feature from the other layer
arcpy.SelectLayerByLocation_management(Structures, "HAVE_THEIR_CENTER_IN", geom, "", "NEW_SELECTION")
... View more
12-06-2017
10:22 AM
|
1
|
12
|
5720
|
| 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
|