|
POST
|
Hi @AFackler_NAPSG , You have to update the minimum distance and as @KenBuja pointed out you have to put the return outside the for loop. var searchDistance = 50;
var points = $layer;
var CurrentiaName = $feature.iaName;
var closestPoints = Intersects(points, BufferGeodetic($feature, searchDistance, "Miles"));
var minDistance = Infinity;
for(var pnt in closestPoints){
var facilityDistance = DistanceGeodetic(pnt, $feature, "miles");
if (facilityDistance < minDistance){
if (CurrentiaName != pnt.iaName) {
closestPoint = pnt;
minDistance = facilityDistance;
}
}
};
return closestPoint.iaName; Furthermore, you have to avoid returning the same input feature. You could do this by checking for an ID (I used the iaName in this case.
... View more
02-03-2021
05:48 AM
|
3
|
0
|
2604
|
|
POST
|
Hi @HussainMalik1 I suggested creating a table with the 5200 records for all archetype, year and variable combinations. Like this: (I used this snippet to create the content:) import random
# 26(archetype)*4(years)*50(variables)
for x in range(26):
archetype = "archetype {}".format(x + 1)
for y in range(4):
year = 2020 + y * 10
for z in range(50):
variable = "variable {}".format(z + 1)
value = random.random() * 25
print("{}\t{}\t{}\t{}".format(archetype, year, variable, value)) I converted the data to an ArcGIS table in a FGDB and ow you can read the values either into a dictionary and query directly on archetype and year (if you are planning to use all the data) or simply load the variables related to a specified archetype and year using a query definition while reading the table. See the code below (including both example): import arcpy
def main():
# table location and field names
tbl = r'D:\GeoNet\EnergyCalc\ArchetypeYear\Default.gdb\ArchetypeYearData'
fld_arche = 'Archetype'
fld_year = 'Year'
fld_var = 'Variable'
fld_val = 'Value'
# input values to query
archetype = 'archetype 19'
year = 2030
# get values using a dictionary
dct = ReadDataIntoDict(tbl, fld_arche, fld_year, fld_var, fld_val)
dct_res1 = GetDictValuesForArchetypeAndYear(dct, archetype, year)
print(dct_res1)
print("")
# get values using the table and a query definition
dct_res2 = GetTblValuesForArchetypeAndYear(tbl, fld_arche, fld_year, fld_var, fld_val, archetype, year)
print(dct_res2)
def ReadDataIntoDict(tbl, fld_arche, fld_year, fld_var, fld_val):
dct = {}
with arcpy.da.SearchCursor(tbl, [fld_arche, fld_year, fld_var, fld_val]) as curs:
for row in curs:
archetype = row[0]
year = row[1]
variable = row[2]
value = row[3]
if archetype in dct:
dct_arche = dct[archetype]
if year in dct_arche:
dct_year = dct_arche[year]
dct_year[variable] = value
dct_arche[year] = dct_year
dct[archetype] = dct_arche
else:
dct_arche[year] = {variable: value}
dct[archetype] = dct_arche
else:
dct[archetype] = {year: {variable: value}}
return dct
def GetDictValuesForArchetypeAndYear(dct, archetype, year):
return dct[archetype][year]
def GetTblValuesForArchetypeAndYear(tbl, fld_arche, fld_year, fld_var, fld_val, archetype, year):
dct = {}
query = "{} = '{}' AND {} = {}".format(fld_arche, archetype, fld_year, year)
with arcpy.da.SearchCursor(tbl, [fld_var, fld_val], query) as curs:
for row in curs:
dct[row[0]] = row[1]
return dct
if __name__ == '__main__':
main() In this example, specifying archetype "archetype 19" and year 2030 used the following query definition: Archetype = 'archetype 19' AND Year = 2030 ...and returned a dictionary with all the variables for this query (providing access to all the 50 variables): {'variable 1': 15.5244401870236, 'variable 2': 23.3657321633143, 'variable 3': 15.1579971665677, 'variable 4': 22.4358991530334, 'variable 5': 4.29857939816623, 'variable 6': 9.85983758111721, 'variable 7': 18.5286923152794, 'variable 8': 5.79755699855013, 'variable 9': 22.7302585515292, 'variable 10': 20.7952926242024, 'variable 11': 3.15393340209763, 'variable 12': 6.55497889635969, 'variable 13': 23.534915278783, 'variable 14': 0.320347367664924, 'variable 15': 7.48007771767636, 'variable 16': 19.7211779286983, 'variable 17': 5.28625570863067, 'variable 18': 7.73552043487549, 'variable 19': 17.2153002750518, 'variable 20': 6.89264095850893, 'variable 21': 2.36278203597135, 'variable 22': 7.46633514134018, 'variable 23': 3.48576873823912, 'variable 24': 4.14460495556789, 'variable 25': 21.7298557989618, 'variable 26': 12.3477762544827, 'variable 27': 5.06567178346359, 'variable 28': 23.3938881028709, 'variable 29': 9.22447098083539, 'variable 30': 20.6246227233889, 'variable 31': 9.2655784448017, 'variable 32': 16.7829187579809, 'variable 33': 5.41408450739008, 'variable 34': 10.4562086747899, 'variable 35': 12.3017493699073, 'variable 36': 4.87453196521707, 'variable 37': 21.2273082111302, 'variable 38': 9.83037462145755, 'variable 39': 6.71378949875001, 'variable 40': 17.1075560942317, 'variable 41': 13.9113667208803, 'variable 42': 21.2160384165932, 'variable 43': 10.144770899068, 'variable 44': 7.1533553156325, 'variable 45': 5.7455521841622, 'variable 46': 9.92663148960041, 'variable 47': 3.13525525773836, 'variable 48': 12.5155910723043, 'variable 49': 20.245329425554, 'variable 50': 0.227518270529811} This can then be used to do the calculations. When I looked at your features, I noticed that you have 4 copies of the same geometry (one for each year( and you have repetitions of multiple archetypes for a large part of the data. I don't quite see how you are planning to connect this data to the features you have. Can you explain more about this? What is a scenario supposed to return?
... View more
02-02-2021
02:30 PM
|
1
|
1
|
13066
|
|
POST
|
Hi @HussainMalik1 , Although 50*26*4 results in 5200 records, this is a number that can be loaded into a dictionary without losing performance. If you prefer, other structures can also be used. It is also a matter of defining what storage allows you and other user to maintain and update this data in case this is necessary.
... View more
02-02-2021
11:04 AM
|
0
|
3
|
7006
|
|
POST
|
Hi @HussainMalik1 , I assume that there should be, but it will be necessary to validate how these values are provided as parameters to a script. But I am sure that it should be possible.
... View more
02-02-2021
10:58 AM
|
0
|
1
|
7007
|
|
POST
|
Hi @TaylorSchyrbiak , When you construct a URL there can be multiple interpretations of the URL. For a URL to be valid I suppose you would have to apply the UrlEncode function (see: https://developers.arcgis.com/arcade/function-reference/text_functions/#urlencode ) to the geoshape in order to replace the spaces by %20 and the semicolons by %3B. I have also had some problems in the past using arcgis-survey123:// to create a valid link to Survey123 and have used "https://survey123.arcgis.app?itemID=yourID&... with better results in the past. In order to validate, I would have to create a survey and a web map with polygons to test this out and I am not sure when I will have time to do this.
... View more
02-02-2021
09:25 AM
|
0
|
2
|
4333
|
|
POST
|
Hi @HussainMalik1 , I would probably go for a table that contains all the possible combinations of archetype, year, variable and value. Something like this: Archetype Description Model Year Variable Value Large Single Storey Home built < 2007 2020 Elec_Enmax_Archetype_AverageConsumption_[MWh] 7,51924737 Large Single Storey Home built < 2007 2030 Elec_Enmax_Archetype_AverageConsumption_[MWh] 7,51924737 Large Single Storey Home built < 2007 2040 Elec_Enmax_Archetype_AverageConsumption_[MWh] 7,51924737 Large Single Storey Home built < 2007 2050 Elec_Enmax_Archetype_AverageConsumption_[MWh] 7,51924737 Large Single Storey Home built < 2007 2020 NatGas_Building_Consumption_Calibrated_[MWh] 0 Large Single Storey Home built < 2007 2030 NatGas_Building_Consumption_Calibrated_[MWh] 0 Large Single Storey Home built < 2007 2040 NatGas_Building_Consumption_Calibrated_[MWh] 35,0111111 Large Single Storey Home built < 2007 2050 NatGas_Building_Consumption_Calibrated_[MWh] 35,0111111 This could be read by the script to create a nested dictionary with this structure: {Archetype: {Year: {Variable: Value}}} When in the script you need a value you can access it using: value = dct[Archetype][Year][Variable]
... View more
02-02-2021
09:19 AM
|
0
|
9
|
6430
|
|
POST
|
Hi @HussainMalik1 , I had a quick look at the Excel and I noticed some #REF errors in column EV with the formula =$EK15*#¡REF! There are also references to external information like "Current and Future State Model with 2023 BAU (Jan18).xlsx" that will be needed to see how to best solve this.
... View more
02-02-2021
05:23 AM
|
1
|
11
|
6437
|
|
POST
|
Hi @TaylorSchyrbiak , There can be several reasons. Maybe the different text sections are not structured in a way to pass a valid URL. In Arcade you have the UrlEncode function that will replace spaces by %20 and other characters by something that is the valid representation in a URL. It is also necessary to explain how you create the URL that is presented in the pop up. It would be good if you could post an example of the URL that is formed at this moment to see what is going wrong.
... View more
02-02-2021
05:17 AM
|
0
|
4
|
4339
|
|
POST
|
Hi @JoseBarrios1 , Paul Barker has some posts explaining how to use FeatureSets, but I think this one about using FeatureSetByRelationshipName (to get access to the related records in the table) and the GroupBy (get count per specie) function is probably what you are looking for: https://www.esri.com/arcgis-blog/products/arcgis-online/mapping/whats-new-in-arcade/ Your options depend highly on how your data is stored. Do you have relationship classes? Do you have a 1:M relationship? etc...
... View more
02-02-2021
05:12 AM
|
1
|
0
|
1065
|
|
POST
|
Hi @TaylorSchyrbiak , Have you manually tried to pass the geoshape to the URL to see if it works? How are you consuming the URL with the geoshape? In a browser or using the Survey123 app? What version do you have? If I looked correctly I see that the geoshape was first introduced at version 3.6.137: https://doc.arcgis.com/en/survey123/faq/pdf/whatsnewarchive.pdf However, I am not sure if there is support for geoshapes in the URL when a Survey is edited in the browser... Since you already have the geometry would using the inbox be a solution for you? https://doc.arcgis.com/en/survey123/desktop/create-surveys/prepareforediting.htm
... View more
02-01-2021
01:49 PM
|
0
|
6
|
4351
|
|
POST
|
Hi @HussainMalik1 , Can you elaborate a bit more on the calculations that you are planning to carry out? You mention 25-30 variables and are planning to create about 90 calculated fields. Are these fields all required or are these intermediate results. Maybe it is not necessary to have all these new fields in the end result. As far as I understand you are planning to create a model. Model Builder is a very powerful tool to build a model and automatize processes. However, when things get very complicated it might be better to use scripts to solve the problem. This provided more flexibility to solve the problem but will require a certain level of Python knowledge. I am happy to help you further, but my time might be limited. So, depending on the complexity of what you are trying to accomplish, I might be able to help. It will be important to share more details so the scope and complexity can be determined correctly.
... View more
02-01-2021
11:18 AM
|
0
|
15
|
6475
|
|
POST
|
Hi @HussainMalik1 , I think I would probably use a matrix (table) to store the values for each Archetype and Year combination. This makes it easier to edit in case values change over time.
... View more
02-01-2021
05:27 AM
|
1
|
17
|
6502
|
|
POST
|
Hi @SMehta , This for sharing the idea of using Collections::Counter, which is indeed a great way of splitting a text and get a dictionary with the counts. Kudos for that. However, in your code, I don't see you are handling the creation of the same field twice which I assume should fail and using the description for the field name would also fail since the descriptions are no valid field names. @HussainMalik1 , Find below the part of the GetStats function which will now set values to 0 and avoids getting the Null values in the result: def GetStats(archetype, dct_flds):
# get the stats from the archetype
dct_cnts = {}
for description, fld_name in dct_flds.items():
dct_cnts[fld_name] = 0
archetypes = archetype.split(";")
for description in archetypes:
if description in dct_flds:
fld_name = dct_flds[description]
if fld_name in dct_cnts:
dct_cnts[fld_name] += 1
else:
# this part is no longer required
dct_cnts[fld_name] = 1
else:
# oops, value not defined in dct_flds, report this
print('{} is not included in dct_flds'.format(description))
pass
return dct_cnts
... View more
02-01-2021
05:22 AM
|
2
|
1
|
4381
|
|
POST
|
Hi @HussainMalik1 , See below the script that allows you to get the statistics: import arcpy
def main():
# read the input featureclass
# fc = arcpy.GetParameterAsText(0)
fc = r'D:\GeoNet\ExtractText\XanderBakker.gdb\Hussain_Data_ConcatenatedFieldValueCount'
# input data field
fld_name = 'ARCHETYPE'
# define how the items relate to the fields
dct_flds = {'Large Multi-Storey Home built < 2007': 'LMSHBLT2007',
'Large Multi-Storey Home built >= 2007': 'LMSHBGE2007',
'Large Multiplex built < 2007': 'LMBLT2007',
'Large Multiplex built >= 2007': 'LMBGE2007',
'Large Retail': 'LargeRetail',
'Large Schools': 'LargeSchools',
'Large Single Storey Home built < 2007': 'LSSHBLT2007',
'Large Single Storey Home built >= 2007': 'LSSHBGE2007',
'Medium Apartments Mixed': 'MediumAptMixed',
'Medium Offices': 'MediumOffices',
'Small Apartments Mixed': 'SmallAptMixed',
'Small Multi-Storey Home built < 2007': 'SMSHMLT2007',
'Small Multi-Storey Home built >= 2007': 'SMSHBGE2007',
'Small Multiplex built < 2007': 'SMBLT2007',
'Small Multiplex built >= 2007': 'SMBGE2007',
'Small Offices': 'SmallOffices',
'Small Retail': 'SmallRetail',
'Small Schools': 'SmallSchools',
'Small Single Storey Home built < 2007': 'SSSHBLT2007',
'Small Single Storey Home built >= 2007': 'SSSHBGE2007',
'UNDEFINED': 'UNDEFINED',
'Very Small Apartments Mixed': 'VerySmallAptMixed'}
# add fields if necessary
addfields = True
if addfields:
AddFields(fc, dct_flds)
# create list of fields
flds = [fld_name]
for fld in dct_flds.values():
flds.append(fld)
# loop through data
with arcpy.da.UpdateCursor(fc, flds) as curs:
for row in curs:
archetype = row[0]
# calculate statistics
dct_cnts = GetStats(archetype, dct_flds)
# set row stats values
for fld_name, cnt in dct_cnts.items():
i = flds.index(fld_name)
row[i] = cnt
# write updated row
curs.updateRow(row)
def AddFields(fc, dct_flds):
# Add the fields mentioned in the dictionary
for description, fld_name in dct_flds.items():
if not FieldExists(fc, fld_name):
arcpy.AddField_management(fc, fld_name, "LONG")
def FieldExists(fc, fld_name):
# Check if field exists
if len(arcpy.ListFields(fc, fld_name)) == 0:
return False
else:
return True
def GetStats(archetype, dct_flds):
# get the stats from the archetype
dct_cnts = {}
archetypes = archetype.split(";")
for description in archetypes:
if description in dct_flds:
fld_name = dct_flds[description]
if fld_name in dct_cnts:
dct_cnts[fld_name] += 1
else:
dct_cnts[fld_name] = 1
else:
# oops, value not defined in dct_flds, report this
print('{} is not included in dct_flds'.format(description))
pass
return dct_cnts
if __name__ == '__main__':
main() This script points on line 6 to the data you shared. I noticed that the featureclass did not have any output fields defined, so I added code to add the new fields if they don't exist. Please note that there are a large number of UNDEFINED values in the fields. Below some statistics of what was found in the data: Description Count Output Field name Large Multi-Storey Home built < 2007 272 LMSHBLT2007 Large Multi-Storey Home built >= 2007 160 LMSHBGE2007 Large Multiplex built < 2007 1708 LMBLT2007 Large Multiplex built >= 2007 1548 LMBGE2007 Large Retail 60 LargeRetail Large Schools 12 LargeSchools Large Single Storey Home built < 2007 2852 LSSHBLT2007 Large Single Storey Home built >= 2007 44 LSSHBGE2007 Medium Apartments Mixed 40 MediumAptMixed Medium Offices 8 MediumOffices Small Apartments Mixed 72 SmallAptMixed Small Multi-Storey Home built < 2007 1980 SMSHMLT2007 Small Multi-Storey Home built >= 2007 424 SMSHBGE2007 Small Multiplex built < 2007 2484 SMBLT2007 Small Multiplex built >= 2007 392 SMBGE2007 Small Offices 20 SmallOffices Small Retail 132 SmallRetail Small Schools 28 SmallSchools Small Single Storey Home built < 2007 6668 SSSHBLT2007 Small Single Storey Home built >= 2007 4 SSSHBGE2007 UNDEFINED 552 UNDEFINED Very Small Apartments Mixed 224 VerySmallAptMixed Let me know if you have any questions. I will try to send the FGDB by private message (if it fits)...
... View more
01-29-2021
02:13 PM
|
1
|
0
|
4434
|
|
POST
|
Hi @KhemAryal , The symbology will be applied to all the 3187 features, not only the 1000 mentioned in the count.
... View more
01-29-2021
11:27 AM
|
1
|
1
|
915
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 01-09-2020 09:26 AM | |
| 6 | 12-20-2019 08:41 AM | |
| 1 | 01-21-2020 07:21 AM | |
| 2 | 01-30-2020 12:46 PM | |
| 1 | 05-30-2019 08:24 AM |
| Online Status |
Offline
|
| Date Last Visited |
11-26-2025
02:43 PM
|