POST
|
I should have been more clear. By "ArcGIS", I meant a script tool that I was running from ArcGIS.
... View more
11-28-2018
10:07 AM
|
0
|
0
|
7512
|
POST
|
Thank you Dan. As you suggested, I converted my pandas DataFrame to a NumPy Array and then used the NumPyArrayToTable module to create a dBASE Table. I found this resource to be helpful in making the conversion: pandas.DataFrame to ArcGIS Table - Community for Data Integration - myUSGS Confluence Once the dBASE Table was created, I was able to add the dBASE content to my Feature Class. Thanks for the help!
... View more
11-28-2018
10:05 AM
|
0
|
2
|
7512
|
POST
|
I'm creating a script tool where the user is able to map the trade of commodities from an exporting country to a set of importing countries. In the script, a Feature Class is created representing the latitude and longitude of the captial of the exporting country and the latitude and longitude of the capitals of the importing countries. A line is then drawn between these sets of points to indicate the flow of the commodity. The commodity data used in the script tool were downloaded as a csv file and then converted to a pandas DataFrame. The individual using the tool is able to specify parameters to subset the pandas DataFrame. For example, a user could specify that they're interested in the trade of Coffee from Burundi for the years 2010 and 2011. The tool will then display the flow of coffee to Burundi's trade partners for the years 2010 and 2011. In subsetting the DataFrame, the only information left in the DataFrame is that which is needed to map the flows between trade partners. Unfortunately, I'm running into trouble when I attempt to add the content of the pandas DataFrame to the Feature Class. When the Feature Class is created it simply represents the connections between exporting and importing countries (the attribute table of the Feature Class at this stage is shown in the attached image CommodityFlows1). I then add columns for the data that I intend to bring in from the pandas DataFrame (the attribute table after these columns are added are shown in CommodityFlows2). I then attempt to use UpdateCursor to add the information from the pandas DataFrame to the Feature Class' attribute table. However, when I do this, I receive the error: "An error occurred: 0". I've isolated the problem to this part of my code: #add year, value, commodity name, origin, and destination information
j = 0
with arcpy.da.UpdateCursor(fc, ("Year", "Value", "Commodity", "Origin", "Dest")) as cursor:
for ROW in cursor:
ROW[0] = df_trade["year"][j]
ROW[1] = df_trade["export_val"][j]
ROW[2] = df_trade["comm_name"][j]
ROW[3] = df_trade["country_origin"][j]
ROW[4] = df_trade["country_dest"][j]
cursor.updateRow(ROW)
j += 1 What I'm doing in the above snippet is updating the attribute table shown in CommodityFlows2 using UpdateCursor. I'm going line-by-line in the Feature Class and adding the value from the pandas DataFrame (df_trade) and adding the value for each row for the particular variable of interest. I'm iterating row-by-row in the pandas DataFrame using j += 1. What is confusing to me is that my entire script runs just fine if I use IDLE (in other words, my Feature Class is created, the flows of commodities are drawn, and the information in the pandas DataFrame is added to the Feature Class). Am I somehow using the UpdateCursor incorrectly in the ArcGIS environment?
... View more
11-27-2018
10:39 AM
|
1
|
8
|
9115
|
POST
|
When they just view the Story Map Basic app they have no trouble seeing the content. It does seem like this is a sharing issue, but I've checked all of the apps and web maps that I'm using in the Story Map and everything is publicly shared. Since I was only embedding the Story Map Basic to retain the legend in the Web Map when implementing the Story Action, I've decided to simply display the Web Map after executing the Story Action and include an image of the legend within the side panel. It isn't an ideal solution, but the user is still able to see the legend and the content in the main stage, and in doing it this way I can avoid embedding another Story Map. Thanks for your help.
... View more
10-30-2018
10:07 AM
|
0
|
1
|
1375
|
POST
|
Hello Rupert, I am using the Story Map Journal template. And I'm embedding a Web Mapping Application. This WMA is a Story Map Basic template within which I have a Web Map of cargo traffic. The reason that I'm embedding this Basic Story Map within the Journal Story Map is so that I can retain the map legend for the Web Map that is displayed by the Basic Story Map. I could not find any other way to include the legend when changing the Main Stage through a Story Action. In talking to a few other people in my lab and having them test this issue, I discovered that the content will display for those who are signed into ArcGIS Online. For those who are not signed in, they receive the message that I posted in my original post. Is it possible that this is the reason this error occurs?
... View more
10-29-2018
01:48 PM
|
0
|
3
|
1375
|
POST
|
I've created a Story Map that is now being hosted on my research center's website. However, we're having a problem where, for some users, the content in the Main Stage disappears seconds after it's loaded. In this part of the Story Map, the viewer is instructed to click on text, which triggers a Story Action that changes the content of the Main Stage to a web map that I've embedded as a website (I did this by including '&embed' at the end of the web page link following this resource). The message that some of the viewers of the Story Map have been getting indicates that the connection to the web map was refused. I've attached the error to this post. I haven't experienced this problem myself, but I watched two other people in my lab click on the Story Action and they both received the error (although several others that I watched did not have the problem). I will say that the web map that appears after the viewer triggers the Story Action does have a large amount of polylines. Could the issue be the size of the web map? It seems strange though that only some people have had this problem.
... View more
10-26-2018
08:46 AM
|
0
|
5
|
1549
|
POST
|
Hello, I have integrated the eSearch widget in my web application. It works great. My question is purely an aesthetic one: We don't need to search By Shape for our purposes, only by By Value. Is there any way to remove search By Shape from the tool's initial view when it is opened? We are using the eSearch widget v2.6.1. Thank you, Paul
... View more
08-17-2018
06:47 AM
|
0
|
2
|
694
|
POST
|
Thanks Dan, your assistance in guiding me through this issue was much appreciated!
... View more
06-19-2018
01:44 PM
|
0
|
1
|
6303
|
POST
|
Ugh, it's a stubborn issue. I'm now just importing pygal as you suggested (rather than 'import pygal as pg'). And I've changed all pg.blah to pygal.blah, as well as adding 'del pygal' to the end of the script. Unfortunately the problem remains in that I'm getting the same error (AttributeError: 'NoneType' object has no attribute 'modules').
... View more
06-19-2018
11:56 AM
|
0
|
3
|
6303
|
POST
|
Dan, Thanks again for the suggestions. The try-except statement from my initial script had some careless errors on my part. I've now fixed this. Here is the script again with the corrections made. #Import modules
import sys
import os
import numpy as np
import pandas as pd
import pygal as pg
import arcpy
arcpy.env.overwriteOutput = True
arcpy.env.outputCoordinateSystem = arcpy.SpatialReference(3857)
def plotFAO(df, iso_code, fao_indicator, itemCodeFS, countrySelection, outputLocation):
arcpy.AddMessage("IN FAO LOOP")
#Select the appropriate indicator
df_selected = df[df["Item Code"] == itemCodeFS]
#color code for plots
customColorStyle = pg.style.Style(colors = ['#D35400', '#979A9A', '#797D7F', '#5F6A6A', '#515A5A'], title_font_size = 18)
arcpy.AddMessage("added Style")
if itemCodeFS == 21010:
#Creat the line chart plot
line_chart = pg.Line(title = u"Average Dietary Energy Supply Adequacy - \n" + countrySelection, x_title = "End Year of '3-Year Average'", y_title = "% - 3-Year Average", style = customColorStyle, show_dots = False, stroke_style = {'width': 3}, show_minor_y_labels = True)
line_chart.x_labels = map(str, range(2001, 2018))
#Get just the Value column for the country of interest and the country groupings
country_series = df_selected.loc[df_selected["ISO_code"] == iso_code, "Value"]
low_income_series = df_selected.loc[df_selected["ISO_code"] == "lowestIncome", "Value"]
mid_lower_income_series = df_selected.loc[df_selected["ISO_code"] == "midLowerIncome", "Value"]
mid_upper_income_series = df_selected.loc[df_selected["ISO_code"] == "midUpperIncome", "Value"]
high_income_series = df_selected.loc[df_selected["ISO_code"] == "uppermostIncome", "Value"]
#Add Pd Series to the line chart
line_chart.add(countrySelection, country_series)
line_chart.add("Low-Income", low_income_series)
line_chart.add("Lower-Middle-Income", mid_lower_income_series)
line_chart.add("Upper-Middle-Income", mid_upper_income_series)
line_chart.add("High-Income", high_income_series)
#Output the plot
line_chart.render_to_file(os.path.join(outputLocation, 'test_pygal3.svg'))
def foodSecurity_v1():
#FAO Data
fao_clean = "C:\\test\\foodSecurity\\fao_clean.csv"
#Country ISO codes
country_iso_csv = "C:\\test\\foodSecurity\\FAO_Area_Export.csv"
#Set tool parameters
#Local variables
out_src_FeatureSet = r"in_memory\src_feature_set"
#User specified parameters
src_FeatureSet = arcpy.GetParameterAsText(0)
countrySelection = arcpy.GetParameterAsText(1)
fao_indicator = arcpy.GetParameterAsText(2)
outputLocation = arcpy.GetParameterAsText(3)
try:
#Save the Feature Set to Feature Layer
arcpy.MakeFeatureLayer_management(src_FeatureSet, out_src_FeatureSet)
aoi = arcpy.CopyFeatures_management(out_src_FeatureSet, os.path.join(arcpy.env.scratchFolder, "AOI_layer.shp"))
#Obtain the country ISO code to avoid formatting problems with country name
df_iso = pd.read_csv(country_iso_csv)
countryDF = df_iso[df_iso["Area"] == countrySelection]
iso_code = countryDF["ISO_code"].iloc[0]
arcpy.AddMessage("country: " + countrySelection + ", code: " + iso_code)
arcpy.AddMessage(iso_code)
#Obtain the Item Code and Item Description selected by the user
if fao_indicator == "Average dietary energy supply adequacy (%) (3-year average)":
itemCodeFS = 21010
if fao_indicator == "Average value of food production (constant I$ per person) (3-year average)":
itemCodeFS = 21011
if fao_indicator == "Share of dietary energy supply derived from cereals, roots and tubers (%) (3-year average)":
itemCodeFS = 21012
if fao_indicator == "Average protein supply (g/capita/day) (3-year average)":
itemCodeFS = 21013
if fao_indicator == "Average supply of protein of animal origin (g/capita/day) (3-year average)":
itemCodeFS = 21014
if fao_indicator == "Rail-lines density (per 100 square km of land area)":
itemCodeFS = 21016
if fao_indicator == "Gross domestic product per capita, PPP (constant 2011 international $)":
itemCodeFS = 22013
if fao_indicator == "Prevalence of undernourishment (%) (3-year average)":
itemCodeFS = 21004
if fao_indicator == "Depth of the food deficit (kcal/capita/day) (3-year average)":
itemCodeFS = 21023
#Select FAO Food Security information of interest
df = pd.read_csv(fao_clean, dtype = {"Area": "S100", "Area Code": "f8", "Element": "S25", "Element Code": "f8", "Flag": "S25",
"Flag Description": "S25", "ISO_code": "S25", "Item": "S150", "Item Code": "i4", "Unit": "S25",
"Value": "f8", "Year": "S25", "Year Code": "f8", "YearEnd": "i4"})
plotFAO(df, iso_code, fao_indicator, itemCodeFS, countrySelection, outputLocation)
#test output layer
arcpy.SetParameter(4, aoi)
#arcpy.SetParameter(4, fig)
except Exception:
e = sys.exc_info()[1]
arcpy.AddError('An error occurred: {}'.format(e.args[0]))
if __name__ == '__main__':
foodSecurity_v1() I've tried several ways to correct this issue where the tool fails the second time it is run, including removing the try-except statement, rearranging the order in which the Pygal module is imported, and placing the script and all csv files on which it relies in a folder where all spaces in the path have been removed. Unfortunately, the process still fails the second time the tool is run. So, when I run it the first time, I'm able to produce the FAO food security plot, but the second time I run the tool, I get the same 'NoneType' error. When I restart ArcMap, I'm able to run the tool again (but it then fails the second time the tool is run). I've tried to isolate the problem, and what I've discovered is that when I comment out 'import pygal as pg' from the module imports at the beginning of the script, the tool will run as many times in succession as I like. But as soon as 'import pygal as pg' is included in my script, it fails the second time the tool runs. So, it isn't a particular Pygal function that is causing the tool to fail, it is the importing of Pygal itself. However, as you suggested, rearranging the order in which the module is imported does not seem to fix the issue.
... View more
06-19-2018
07:30 AM
|
0
|
5
|
6303
|
POST
|
That was it! There was a protection that I needed to disable. It populated immediately after being disabled. Thanks!
... View more
02-02-2018
10:45 AM
|
1
|
0
|
1013
|
POST
|
It doesn't look like that was it since I'm still having the same problem after re-adding it. Could it just be that there are too many features (ie, too many municipalities)? I just did a test where I clipped out 100 municipalities from the 3,500 and the eSearch widget worked just fine on this clip. It was able to populate the drop-down list with no problems. This still doesn't explain why the widget worked fine when the layer was hosted on AGOL.
... View more
02-02-2018
10:32 AM
|
0
|
2
|
1013
|
POST
|
Hello, I'm having an issue with the eSearch widget (2.6.1) where the dropdown list fails to populate. The layer that the search is based on is hosted on ArcGIS for Server. This layer has around 3,500 features. I've configured the update search layer properties as follows: And my expression selects Unique municipality names: As you can see, the tool appears to be working, meaning that it is processing the unique municipality name values. However, the list never populates and it never appears to read any values since it remains at '0 of 3568.' One thing that is worth mentioning is that I originally hosted this layer on ArcGIS Online rather than Arc Server. When it was on AGOL, I was able to get the list to populate, which causes me some concern that the issue is how the Search URL to Arc Server is being interpreted. Could this be the issue?
... View more
02-02-2018
08:58 AM
|
0
|
4
|
1156
|
POST
|
Hello, I'm having this same issue with the dropdown list for the eSearch widget failing to populate, and I'm curious how the issue was resolved. I'm using eSearch 2.6.1. The layer that the search is based on is hosted on ArcGIS for Server. This layer has around 3,500 features. I've configured the update search layer properties as follows: And my expression selects Unique municipality names: As you can see, the tool appears to be working, meaning that it is processing the unique municipality name values. However, the list never populates and it never appears to read any values since it remains at '0 of 3568.' One thing that is worth mentioning is that I originally hosted this layer on ArcGIS Online rather than Arc Server. When it was on AGOL, I was able to get the list to populate, which causes me some concern that the issue is how the Search URL to Arc Server is being interpreted. Could this be the issue?
... View more
02-02-2018
07:39 AM
|
0
|
1
|
1295
|
Title | Kudos | Posted |
---|---|---|
1 | 11-27-2018 10:39 AM | |
1 | 02-02-2018 10:45 AM |
Online Status |
Offline
|
Date Last Visited |
01-08-2021
12:28 PM
|