POST
|
Hi Dan, thank you for your response, You are right on that, I did not get any errors but I did not obtain the results I need. After running the code the min and max values from the lists were assigned to each field in each feature class but the values were the wrong ones. The values assigned to all of the feature classes are the ones from the last lists only: Expected behavior: Each list corresponds to one feature class. Each element on the list corresponds to one field. Actual Behavior: The elements on the lists marked in red were assigned to all of the feature classes. Please see results for two feature classes below: The blue box shows the min MEDIAN_HOUSEHOLD_INCOME_2018 and the values from the list above assigned to each field. The green box shows the max MEDIAN_HOUSEHOLD_INCOME_2018 and the values from the list above assigned to each field. The same values are assigned to all of the feature classes. Feature class _1 : Feature class_2: I am not sure how to iterate through so many things at the same time. I need to iterate through: 1. Multiple feature classes 2. Rows within each feature class 3. Fields within each feature class 4. Lists (to select the values I need to assign in the fields) - List of Max and Min MEDIAN_HOUSEHOLD_INCOME_2018 - List of Max and Min construction_lists I really appreciate your help in this matter, Thank you!
... View more
11-03-2020
06:52 AM
|
0
|
0
|
1716
|
POST
|
Hello, Here's the code I wrote to do the following: 1. Assign a min and max value to multiple fields on multiple feature classes. 2. The Min and Max values have to correlate with the min and max value in a different field on the same feature class. For example: A. Select the min value from the MEDIAN_HOUSEHOLD_INCOME_2018 field and assign a specific value to all of the other fields in the feature class. All of the values are different for each field and each feature class. B. Do the same but for the max value of the MEDIAN_HOUSEHOLD_INCOME_2018 field I am having trouble with the loops when assigning the Construction costs to all of the different feature classes. I am creating too many loops and I don't know what are really necessary and which ones I don't need. I would appreciate any help with this, I am learning and have tried to fix it for a day and haven't been able to identify how to do it, I am aware that there is a major problem with the iteration of the different lists, thank you! import operator
import arcpy
# script to assign construction costs to census tracts where we have construction cost data from cummings
# https://gis.stackexchange.com/questions/264051/selecting-maximum-value-in-attribute-table-using-python-code
arcpy.env.workspace = r"D:\APRX_MXDS\FAR_Initialization_Project\10_2020_Linear_Regression_USA\construction_costs\test_gdb.gdb"
arcpy.env.overwriteOutput = True
#create a list of all the feature classes
feature_class_list = []
list_fc = arcpy.ListFeatureClasses()
for m in list_fc:
feature_class_list.append(m)
print(feature_class_list)
field_list = ["MEDIAN_HOUSEHOLD_INCOME_2018", "CONST_PRICE_PER_SF_CONDO", "CONST_PRICE_PER_SF_MULTIFAM", "CONST_PRICE_PER_SF_OFFICE", "CONST_PRICE_PER_SF_RETAIL", "CONST_PRICE_PER_SF_HOTEL",
"CONST_PRICE_PER_SF_INDUSTRIAL", "CONST_PRICE_PER_SF_PARKING"]
fc_list = ['Atlanta', 'Boston', 'Chicago', 'Dallas', 'Denver', 'Honolulu', 'Las_Vegas', 'Los_Angeles', 'Miami', 'Nashville', 'New_York', 'Orlando',
'Philadelphia', 'Portland', 'Raleigh', 'Sacramento', 'San_Diego', 'San_Francisco', 'Seattle', 'Washington']
# list of all the max and min median incomes per city
max_list = []
min_list = []
for fc in fc_list:
print("Starting with feature class: {}".format(fc))
all_entries = [row for row in arcpy.da.SearchCursor(fc, ['MEDIAN_HOUSEHOLD_INCOME_2018'])]
maximum = (max(all_entries)[0])
minimum = (min(all_entries)[0])
max_list.append(maximum)
min_list.append(minimum)
print("Maximum Values List: {}".format(max_list))
print("Minimum Values List: {}".format(min_list))
max_construction_lists = [[394, 394, 674, 452, 708, 589, 139], [510, 510, 874, 586, 912, 763, 180], [534, 534, 914, 613, 906, 798, 188],
[383, 383, 657, 440, 685, 573, 135], [314, 314, 485, 461, 717, 600, 142], [537, 537, 690, 617, 960, 803, 189],
[469, 469, 803, 538, 838, 701, 165], [529, 529, 688, 607, 945, 790, 186], [379, 379, 648, 435, 676, 566, 133],
[390, 390, 667, 447, 662, 583, 186], [859, 859, 1026, 687, 1108, 895, 211], [372, 372, 637, 427, 664, 556, 131],
[512, 512, 876, 587, 914, 765, 180], [445, 445, 661, 511, 796, 666, 157], [373, 373, 641, 429, 673, 559, 132], [463, 463, 624, 536, 655, 695, 125],
[503, 503, 678, 583, 712, 755, 180], [584, 584, 1001, 671, 1044, 874, 168], [469, 469, 696, 538, 838, 701, 175], [418, 418, 716, 480, 747, 625, 147]]
min_construction_lists = [[303, 303, 245, 253, 333, 152, 50], [392, 392, 318, 327, 532, 196, 65], [411, 411, 332, 343, 483, 206, 68],
[295, 295, 239, 246, 336, 148, 49], [133, 133, 135, 258, 364, 155, 51], [413, 413, 335, 345, 480, 207, 8],
[361, 361, 292, 301, 354, 180, 60], [294, 294, 327, 165, 425, 203, 49], [230, 230, 235, 242, 351, 146, 48],
[300, 300, 243, 250, 353, 150, 49], [461, 461, 373, 384, 625, 231, 76], [190, 190, 231, 238, 345, 143, 47],
[393, 393, 319, 328, 534, 197, 65], [343, 343, 277, 286, 358, 171, 65], [288, 288, 233, 240, 317, 144, 4],
[251, 251, 289, 150, 320, 178, 61], [273, 273, 325, 163, 348, 194, 66], [449, 449, 364, 375, 555, 225, 79],
[361, 361, 292, 301, 376, 180, 68], [322, 322, 260, 268, 436, 161, 53]]
# Assign Max construction cost values to all cities
for fc in fc_list: # iterate through each feature class
with arcpy.da.UpdateCursor(fc, field_list) as cursor:
for row in cursor: # iterate through each row
for max_income in max_list: # iterate through each max MEDIAN_HOUSEHOLD_INCOME_2018 value
print(max_income)
for lists in max_construction_lists: # iterate through each city's list of max construction values
print(lists)
if row[0] == max_income: # if MEDIAN_HOUSEHOLD_INCOME_2018 equals to max income
row[1] = lists[0]# assign the first element of each list of the max_construction_Lists. For example: For the first feature class iteration I would expect row[0] = 394
print("This should be the condo max value for each city: {}".format(lists[0]))
row[2] = lists[1]
row[3] = lists[2]
row[4] = lists[3]
row[5] = lists[4]
row[6] = lists[5]
row[7] = lists[6]
cursor.updateRow(row)
print("Done updating max construction costs in all cities")
# Assign Min construction cost values to all cities
for fc in fc_list: # iterate through each feature class
with arcpy.da.UpdateCursor(fc, field_list) as cursor:
for row in cursor: # iterate through each row
for min_income in min_list: # iterate through each max MEDIAN_HOUSEHOLD_INCOME_2018 value
for lists in min_construction_lists: # iterate through each city's list of min construction values
if row[0] == min_income: # if MEDIAN_HOUSEHOLD_INCOME_2018 equals to min income
row[1] = lists[0]
row[2] = lists[1]
row[3] = lists[2]
row[4] = lists[3]
row[5] = lists[4]
row[6] = lists[5]
row[7] = lists[6]
cursor.updateRow(row)
print("Done updating min construction costs in all cities")
... View more
11-02-2020
06:48 PM
|
0
|
4
|
1799
|
POST
|
thank you so much for your replies. I will test all these and will let you know how it went
... View more
11-02-2020
06:23 PM
|
0
|
0
|
1550
|
POST
|
Hello, I am trying to extract the largest number from a string. More details: I have a feature class with a text field. Each feature has a string like this: "3, 5, 3.9, 2.5 FAR Values" and I need to extract the higher number and put it in a new field. From that string I would need number 5. There are some features that have Null values and some with just text and no numbers. I wrote the following script using a python function from the internet but I am not sure how to apply it in Arcpy. import arcpy
# find largest number in a string
arcpy.env.workspace = r"D:\APRX_MXDS\USA_App_Project\usa_parcels_with_FARField.gdb"
arcpy.env.overwriteOutput = True
fc = "temp"
with arcpy.da.UpdateCursor(fc, "FAR_INTEGER") as cursor: # Loop through each feature
for row in cursor:
ls = list()
for w in row[0].split():
try:
ls.append(int(w))
except:
pass
try:
return max(ls)
except:
return None
... View more
06-18-2020
09:08 AM
|
0
|
4
|
1657
|
POST
|
thank you Marco this is very helpful. Will try specifying the specific fields with the initial import using the same tool I've been using which is the OSM File Loader (Load Only) Tool. This tool is taking a very long time even to load very small testing areas so I don't want to use even a slower tool. But it is good to know that there is the OSM Attribute Selector tool as well. Will let you know how that goes !
... View more
05-28-2020
03:35 PM
|
0
|
1
|
2341
|
POST
|
Hi Marco thank you and yes I was able to figure this out and I finally imported the OSM data into GIS. But I have a new problem... 😕 this seems to never end.. I do not see any building height data in the attribute table. I only see one field with building data but it seems to be just the building use not the height. I first ran a test to see if OSM data contained building height data. I downloaded an extract directly from OSM, which I then converted to shp and then opened it in ArcGIS and I saw a field with building height data. I expected to see this field as well when downloading the osm.xml file from Geofabrik but I don't see it. Do you know if there are any other data providers that offer this field? I haven't found any documentation whatsoever on this other than this document from Geofabrik saying they sell the building height attribute data for shapefiles. I am not sure how to move forward with this. Your help is much appreciated!
... View more
05-28-2020
01:27 PM
|
0
|
3
|
5414
|
POST
|
Hello, I am having trouble with the OSM File Loader (Load Only) tool. I've run the tool a couple of times with different files and the tool runs but in the end I don't see any of the data from OSM inside my gdb. The osm.xml file from OSM that I chose is at the state level. I downloaded the .osm.bz2 option because if I understand correctly, when decompressed this yields an OSM XML file. This is where I downloaded the data from: https://download.geofabrik.de/north-america/us.html I wanted to attach an image showing you my inputs for the tool but for some reason it is not letting me attach anything to this response. These are my inputs for the tool: OSM File: new-jersey-latest.osm.bz2 OpenStreetMap point features: the gdb and the name of the point features OpenStreetMap line features: the gdb and the name of the line features OpenStreetMap polygon features: the gdb and the name of the polygon features After the tool runs I expect to have 3 feature classes inside my gdb each one with all of the point, line and polygon data from OSM. I don't see anything... I am going to keep trying but would really appreciate your help. Thank you! Natalia
... View more
05-28-2020
08:49 AM
|
0
|
0
|
599
|
POST
|
Hi Marco, I am having trouble with the OSM File Loader (Load Only) tool. I've run the tool a couple of times with different files and the tool runs but in the end I don't see any of the data from OSM inside my gdb. The osm.xml file from OSM that I chose is at the state level. I downloaded the .osm.bz2 option because if I understand correctly, when decompressed this yields an OSM XML file. This is where I downloaded the data from: https://download.geofabrik.de/north-america/us.html I wanted to attach an image showing you my inputs for the tool but for some reason it is not letting me attach anything to this response. These are my inputs for the tool: OSM File: new-jersey-latest.osm.bz2 OpenStreetMap point features: the gdb and the name of the point features OpenStreetMap line features: the gdb and the name of the line features OpenStreetMap polygon features: the gdb and the name of the polygon features After the tool runs I expect to have 3 feature classes inside my gdb each one with all of the point, line and polygon data from OSM. I don't see anything... I am going to keep trying but would really appreciate your help. Thank you! Natalia
... View more
05-28-2020
08:13 AM
|
0
|
0
|
7586
|
POST
|
thank you, I haven't checked it out. Will do now Thank you so much for your help in this matter Marco. Much appreciated!
... View more
05-21-2020
02:28 PM
|
0
|
0
|
7586
|
POST
|
Hi Marco, I really appreciate your detailed response on this matter. I will make sure to download version 10.7.x of ArcMap. Do you know if I can select the version of ArcMap I need? I am in the process of buying it since I only have ArcGIS Pro. Being able to filter the OSM XML file and write a new XML file with only buildings sounds ideal to expedite this process. The only problem with this is that it seemed quite difficult to me since I don't know a lot of coding. I will try to do more research to see if I can learn how to do it with the Osmium Tool. Thank you! Natalia
... View more
05-21-2020
08:44 AM
|
0
|
4
|
7586
|
POST
|
Hello, I am trying to figure out how to work with OSM data. My goal is to get building height and building footprints for the USA from OpenStreetMaps. The problem is that if I download the state level shapefiles from Geofabrik (https://download.geofabrik.de/ ) they don't have building height data. The only way I've been able to see building height data is if I download the OSM.pdf file format and then convert it to shapefile with a third party converter software such as MyGeodata Cloud - GIS Data Warehouse, Converter, Maps . I currently have ArcGIS Pro and from other posts I've read, I can only see OSM.pdf data in ArcMap. Will I be able to import OSM.pdf data into ArcMap, convert it to file geodatabase and then take it to ArcGIS Pro? I need to run calculations, manipulate this data, and integrate it into some work I am doing. I would appreciate your help, Thank you, Natalia
... View more
05-20-2020
02:43 PM
|
0
|
15
|
10357
|
POST
|
yes definitely getting a lot better! thanks to you guys in here. I really appreciate it! I don't know what I would do without your help
... View more
05-06-2020
02:21 PM
|
0
|
0
|
1569
|
POST
|
Thank you Joe. As I told Dan, your answers will guide me for the next time I have to work on something similar. In the end I had to do it manually because it was taking me too long to automate it.
... View more
05-06-2020
01:28 PM
|
0
|
2
|
1569
|
POST
|
Thank you Dan. In the end I had to do some more research on the topic before I was able to automate this. Because I needed this very urgent I decided to do it manually since it was taking me to long to automate. I am using your answer as a guide for the next time I have to do something similar.
... View more
05-06-2020
01:27 PM
|
0
|
0
|
270
|
Title | Kudos | Posted |
---|---|---|
1 | 11-15-2018 02:42 PM | |
2 | 03-06-2020 09:18 AM | |
2 | 11-15-2018 03:02 PM |
Online Status |
Offline
|
Date Last Visited |
12-14-2020
03:44 PM
|