|
POST
|
It is because you are returning with each if statement. Once the first if condition is met, the code will build that label and exit the function.
... View more
03-02-2015
09:14 AM
|
1
|
2
|
4515
|
|
POST
|
In you want to start branching out into installing additional Python packages, I encourage you to read Installing Packages from the Python Packing User Guide.
... View more
03-02-2015
09:05 AM
|
0
|
0
|
4307
|
|
POST
|
Try building the Extent object from scratch instead of reconstructing one you get from the DataFrame object. If I understand what you are expecting for results, the following code works for me in the interactive Python window in ArcMap: custom_extent = {'XMin':-87.678956, 'XMax':-87.611652, 'YMin':41.867129, 'YMax':41.954932}
newExtent = arcpy.Extent(**custom_extent)
print data_frame.extent.XMin
data_frame.spatialReference = arcpy.SpatialReference("WGS 1984")
print data_frame.extent.XMin
data_frame.extent = newExtent
print data_frame.extent.XMin If you want to use a dictionary to store an extent's bounds, may I suggest using key names that correspond to function parameters. That way, you can just pass the dictionary as keyword arguments to an Extent function. Update: It dawned on me after posting the code above why your original code might not be working. I believe it fails because you change the spatial reference of the data frame after getting the extent object from the data frame. If you change the spatial reference first, it seems to work. custom_extent = {1:-87.678956, 2: -87.611652, 3:41.867129, 4:41.954932}
print data_frame.extent.XMin
data_frame.spatialReference = arcpy.SpatialReference("WGS 1984")
print data_frame.extent.XMin
newExtent = data_frame.extent
newExtent.XMin, newExtent.XMax = custom_extent[1], custom_extent[2]
newExtent.YMin, newExtent.YMax = custom_extent[3], custom_extent[4]
data_frame.extent = newExtent
print data_frame.extent.XMin
... View more
03-01-2015
09:15 AM
|
0
|
0
|
462
|
|
POST
|
Since the OGC Simple Feature Access - Part 1: Common Architecture doesn't allow parts of a multipart polygon to share edges, what you are really after is either a geometry bag or geometry collection, neither of which are implemented in ArcPy. Even if ArcPy implemented geometry bags, you still can't store them in a feature class because Esri doesn't have a geometry bag/collection type for feature classes. If you work outside of ArcGIS, in SQL Server for example, you can build and store a geometry collection. Using your original example and a SQL Server workspace, you can see what I am speaking to: import arcpy
# a square
part = [[0,0],[0,1],[1,1],[1,0],[0,0]]
mp = ""
for x_shift in range(0,3):
for y_shift in range(0,5):
new_part = ", ".join(["{} {}".format(x+x_shift,y+y_shift) for [x,y] in part])
mp = "{}, POLYGON(({}))".format(mp, new_part)
mp = mp[2:]
sqlWS = #SQL Server or SQL Server Express SDE connection file
out_name = "test_pol_mp"
fc = arcpy.CreateFeatureclass_management(sqlWS, out_name, "POLYGON")
shape = arcpy.Describe(fc).shapeFieldName
sde_conn = arcpy.ArcSDESQLExecute(sqlWS)
sql = ("INSERT INTO {} ({}) "
"VALUES (\'GEOMETRYCOLLECTION({})\')".format(out_name, shape, mp))
sde_conn.execute(sql)
sql = ("SELECT [{}].STNumGeometries() AS partCount, "
"[{}].STNumPoints() AS pointCount "
"FROM {}".format(shape, shape, out_name))
partCount, pointCount = sde_conn.execute(sql)[0]
print "Polygon partCount : {0}".format(partCount)
print "Polygon pointCount: {0}".format(pointCount)
#... Polygon partCount : 15
#... Polygon pointCount: 75 Viewing the geometry collection in SQL Server Management Studio gives: Wheres trying to view it in ArcMap gives:
... View more
02-28-2015
12:12 PM
|
1
|
0
|
1302
|
|
POST
|
Darren Wiens you are correct in that it isn't an ArcPy limitation. In fact, it isn't even an ArcGIS or Esri limitation, per se. The quote from the Help link you provide is basically Esri paraphrasing an OGC standard without attribution or providing the 'why' to the user. The OGC Simple Feature Access - Part 1: Common Architecture document clearly states the "boundaries of any 2 Polygons that are elements of a MultiPolygon may not 'cross' and may touch at only a finite number of Points," i.e., parts of a multipart polygon can't share an edge. MultiLineStrings can have shared lines or lines on top of each other. The Esri Knowledge Base article FAQ: Why are polygon features grouped into multi-line string features by the ArcSDE sdegroup command? speaks to this issue. In short, the standard doesn't allow for it. Esri implements the standard, and their way of staying compliant is to dissolve parts of multipart polygons that share edges. Microsoft implements the standard as well, but their way of handling the situation in SQL Server is to let the user create an invalid polygon and then let it err out later when someone tries to work with the geometry. Same standard, two different products, and two different ways of coping with a user creating an invalid multipart polygon.
... View more
02-28-2015
11:59 AM
|
1
|
0
|
7575
|
|
POST
|
If the cursor isn't going to be used once and disposed of, using a Python with statement ensures the cursor is reset for its next use. But then again, maybe having the cursor automatically reset isn't what someone wants. Just depends on the situation and need.
... View more
02-27-2015
07:55 AM
|
0
|
0
|
7715
|
|
POST
|
True, for now and in the ArcPy realm, calling the search cursor's next method will get the same result. I suggested using the built-in next method because of broader changes happening with Python outside of ArcPy. For Python 3 after PEP 3114 was approved, it meant the next() iterator method was going away. The Transition Plan for PEP 3114 covers two additional changes needed for moving to Python 3: Method definitions named next will be renamed to __next__ . Explicit calls to the next method will be replaced with calls to the built-in next function. For example, x.next() will become next(x) . The built-in next function was introduced in Python 2.6 to smooth the transition. Since we know that Esri has made the leap to Python 3 with ArcGIS Pro, I suggested an approach using the built-in function. For now, Esri's implementation of the ArcPy Data Access (arcpy.da) module in ArcGIS Pro still includes cursors having explicit next() methods, but I argue the current ArcGIS Pro implementation isn't very pythonic since the explicit next() methods don't add any special functionality beyond simply iterating.
... View more
02-27-2015
07:52 AM
|
1
|
2
|
7715
|
|
POST
|
Are you looking for only a single record/point per SRAddress? I recall you mentioning there may be up to 10 types or collections. Do you want a table that has [Type1, EWT1, ItemCount1, ...., Type10, EWT10, ItemCount10] columns? A table with at least 30 columns, most of which will be empty? Or, are you wanting a separate table that has [SRAddress, Type, EWT, ItemCOunt] that you can use to relate back to a point feature class that has the point locations for each SRAddress? I guess I don't understand what you want the final data structure to look like in terms of how many tables and what those tables look like.
... View more
02-26-2015
03:04 PM
|
0
|
1
|
1705
|
|
POST
|
As Owen Earley suggests, the Summary Statistics tool should work, and it is scriptable through Python. You could also use a data access (arcpy.da) search cursor approach, a bit more involved but likely more performant than Summary Statistics. # import functions from modules that are available but not commonly imported
from collections import defaultdict
from numpy import fromiter, dtype
# sum PCE_VOLU_3 by NO
stats = defaultdict(int)
with arcpy.da.SearchCursor(input_fc, ['NO','PCE_VOLU_3']) as cur:
for k, v in cur:
stats += v
# create iterable and populate numpy array
stats_iterable = ((k, v) for (k, v) in stats.iteritems())
tmp1 = fromiter(stats_iterable,
dtype([('NO', 'i4'), ('SUM_PCE_', 'f8')]))
# Dump numpy array to table
arcpy.da.NumPyArrayToTable(tmp1, out_table)
del tmp1
del stats
... View more
02-26-2015
02:51 PM
|
0
|
0
|
2041
|
|
POST
|
Once you sum the values, how do you want to store them? Do you want a separate table? Do you want a new column in this table where is shows the same sum for all of the records with the same NO?
... View more
02-26-2015
02:23 PM
|
0
|
3
|
2041
|
|
POST
|
Since the arcpy.da.SearchCursor is an iterable that returns one list per row of the table/cursor, the Python built-in next() function can be used to retrieve the next row, which would be the first row if the cursor was just created or reset. import arcpy
fc = 'c:/data/base.gdb/features'
# Open a cursor on some fields in a table
with arcpy.da.SearchCursor(fc, ['OID@', 'SHAPE@AREA']) as cursor:
row = next(cursor)
# Do something with the first row of data here
del cursor
... View more
02-26-2015
02:02 PM
|
4
|
0
|
7715
|
|
POST
|
Python dictionaries are implemented using a hash table. They are effectively an unordered collection of items, which means you shouldn't rely on the order of the elements. I mention this because it seems to me you may be trying to do just that. Instead of an item dictionary, I think an item list of tuples would work better and be more straightforward. f2 = open('C:\Users\Administrator\Desktop\DetailView.json', 'r')
data2 = jsonpickle.encode( jsonpickle.decode(f2.read()) )
url2 = "https://myla311.lacity.org/myla311router/mylasrbe/1/QuerySR"
headers2 = {'Content-type': 'text/plain', 'Accept': '/'}
r2 = requests.post(url2, data=data2, headers=headers2)
decoded2 = json.loads(r2.text)
items = []
for sr in decoded2['Response']['ListOfServiceRequest']['ServiceRequest']:
SRAddress = sr['SRAddress']
latitude = sr['Latitude']
longitude = sr['Longitude']
for ew in sr["ListOfLa311ElectronicWaste"][u"La311ElectronicWaste"]:
CommodityType = ew['Type']
ItemType = ew['ElectronicWestType']
ItemCount = ew['ItemCount']
items.append((SRAddress,
latitude,
longitude,
CommodityType,
ItemType,
ItemCount))
import numpy as np #NOTE THIS
dt = np.dtype([('SRAddress', 'U40'),
('latitude', '<f8'),
('longitude', '<f8'),
('Type', 'U40'),
('ElectronicWestType', 'U40'),
('ItemCount', 'U40')])
arr = np.array(items,dtype=dt)
sr = arcpy.SpatialReference(4326)
arcpy.da.NumPyArrayToFeatureClass(arr, fc, ['longitude', 'latitude'], sr )
... View more
02-26-2015
01:43 PM
|
2
|
3
|
1705
|
|
POST
|
Can you re-post your current code with the loop now integrated into it?
... View more
02-26-2015
11:22 AM
|
0
|
5
|
1705
|
|
POST
|
You are passing the string, '5810 N WILLIS AVE, 91411', as a key name (either for k1, ..., or k6), and the error message is telling you there is not key named that address string.
... View more
02-26-2015
11:19 AM
|
0
|
0
|
7875
|
|
POST
|
ItemCount is holding the item count for a single type, not all of the item counts for all of the type of electronic waste. In the code I provided, the last loop over the electronic waste items grabs the VCR/DVD Players, which has an item count of 1. After the loops are finished, and since I didn't delete ItemCount, it stills exists and has the last value of 1 stored in it.
... View more
02-26-2015
11:17 AM
|
0
|
0
|
7875
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 06-11-2026 07:04 AM | |
| 1 | 07-17-2026 06:54 AM | |
| 2 | 07-06-2026 12:29 PM | |
| 1 | 07-06-2026 12:00 PM | |
| 2 | 06-05-2026 10:30 AM |
| Online Status |
Offline
|
| Date Last Visited |
Wednesday
|