|
POST
|
And if I try the the code below to make PG float and make the whole result an integer, I get this error: Traceback (most recent call last): File "test.py", line 174, in <module> expression3 = int("float('!PG!') * 12425") ValueError: invalid literal for int() with base 10: "float('!PG!') * 12425" expression3 = int("float('!PCTGROWTH!') * 12425")
arcpy.CalculateField_management(inFeatures, fieldName3, expression3, "PYTHON_9.3")
... View more
03-10-2015
07:37 AM
|
0
|
4
|
2077
|
|
POST
|
Hi all, I have been having trouble with getting Calculatefield_management to accept my SQL expression variables. I have tried various ways to enter the variables to get the first two calculate field functions to work. The error is now occurring with the 3rd calculate field/expression3/calculating the NA in the code below. [arcpy.CalculateField_management(inFeatures, fieldName3, expression3, "PYTHON_9.3")] I get different errors depending on how I enter in the variable. One of the errors I get while debugging now: Traceback (most recent call last): File "test.py", line 175, in <module> arcpy.CalculateField_management(inFeatures, fieldName3, expression3, "PYTHON_9.3") File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\management.py", line 3354, in CalculateField raise e ExecuteError: ERROR 999999: Error executing function. The value type is incompatible with the field type. [NA] Failed to execute (CalculateField). Method The first calculatefield updates the RG field based on the numbers in the !Join_Count! features column. RG is a short integer. The second calculatefield updates the PG field which is (!RG!/sum of RG) * 100. PG should be a float since it's finding the percentage. The third calcualtefield udpates the NA field which is !PG! * 12425. NA should be a short integer. Any suggestions on how I can write expression3 to be the correct field type format for NA? Thanks. My Background -Novice Programmer -Using the Python 2.75 Idle Shell -Using ArcMap 10.2.1 Sample Code Snippet: # Import ArcPy site-package to use Arcgis and os modules to use operating system
import arcpy, os, sys, string, numpy
from arcpy import env
env.overwriteOutput = True
#set environment settings to where mxd is saved
env.workspace = r'J:\folder\scripts'
#folders
output = r'J:\folder\scripts\output' + "\\"
inFeatures = output + "joined_" + c.name + "_" + w.name + ".dbf"
print inFeatures
#First Calculate Field from spatial join count numbers
fieldName = "RG" #SHORT
expression = '!Join_Count!' #LONG type
arcpy.CalculateField_management(inFeatures, fieldName, expression, "PYTHON_9.3")
print "Join Count numbers added to RG Field"
#Need sum of rg...
arr = arcpy.da.FeatureClassToNumPyArray(inFeatures, ('RG'))
# Sum the RG field
print "The total sum of features in RG is: "
rg_sum = arr["RG"].sum()
print rg_sum
flnum = "!RG!"
print flnum
#Calculate PG which equals (!RG!/Sum of !RG!) * 100
fieldName2 = "PG" #FLOAT type, it's a percentage number
arcpy.CalculateField_management(inFeatures, fieldName2, "(float('!RG!')) / " + str(rg_sum) + "* 100" , "PYTHON_9.3")
arr = arcpy.da.FeatureClassToNumPyArray(inFeatures, ('PG'))
PG_sum = arr["PG"].sum()
print "The total sum of features in PG is: " + str(PG_sum) #should equal 100.0
# Calculate NA, which equals !PG! * 12425
fieldName3 = "NA" #SHORT type, it needs to be a whole number
expression3 = "'!PG!' * 12425"
arcpy.CalculateField_management(inFeatures, fieldName3, expression3, "PYTHON_9.3")
arr = arcpy.da.FeatureClassToNumPyArray(inFeatures, ('NA'))
NA_sum = arr["NA"].sum()
print "The total sum of features in NA is: " + str(NA_sum) #needs to equal 12425
... View more
03-10-2015
07:27 AM
|
0
|
5
|
6571
|
|
POST
|
Hi Kelly, I just noticed that the code to turn off popups when the measurement button is on messes up my code for printing. It's no longer working. I'm either getting a time out error, or depending on what computer I'm using, I get this error in Firefox:Loading mixed (insecure) display content on a secure page. Any ideas? Code for printer in main.js file: //for PRINTER *********************** if (this.config.enablePrintButton) { //if the printing function is enabled true this._printer = new Print({ //create a new printer widget called this._printer map: this.map, //the map to print templates: [{
label: "Layout",
format: "PDF",
layout: "A3 Landscape",
layoutOptions: {
titleText: "Map",
}
}],
url: "printing service URL here. just removed for now" //the url to export the web map task }, dom.byId("printButton")); //html element where the print widget button/drop down will be rendered this._printer.startup(); //finalize the creation of the widget
... View more
03-09-2015
07:09 AM
|
0
|
1
|
735
|
|
POST
|
Ok, this is what I used to get it to work: But now, I'm having trouble with getting it not to interfere with the pop ups. if (this.config.enableAddText) { //var textAdd = query("div#mapDiv").on('click', lang.hitch (this, function (evt){ var textSub = query("div#TextButton .dijitButton .dijitButtonNode").on('click', lang.hitch (this, function (){ var map = this.map; console.log("in text Submit"); var textAdd = query("div#mapDiv").on('click', lang.hitch (this, function (evt){ console.log("in text Add"); var map = this.map; map.setInfoWindowOnClick(false); map.graphics.add( new Graphic( new Point(evt.mapPoint.x, evt.mapPoint.y, new esri.SpatialReference({ wkid: 102100 })), new TextSymbol(dojo.byId("tsText").value).setColor( new Color([0,0,0])).setAlign(esri.symbol.Font.ALIGN_START).setAngle(0).setOffset(0,0).setFont( new Font("12pt").setWeight(esri.symbol.Font.WEIGHT_BOLD)) ) ); console.log(map); console.log(evt.mapPoint.x); console.log(evt.mapPoint.y); console.log(dojo.byId("tsText").value); console.log("added text graphic"); textAdd.remove(); map.setInfoWindowOnClick(true); } ) ) // text add query })); }
... View more
02-25-2015
01:29 PM
|
0
|
1
|
1854
|
|
POST
|
This map is a great example of what I want, with the drawing function too! Which .js file holds your code for the add text and drawing functions?
... View more
02-25-2015
12:45 PM
|
0
|
1
|
1854
|
|
POST
|
Hi Tim Witt, I'm getting a textClick is not defined error. I changed this: query("div#mapDiv").on('click', lang.hitch (this, textClick))
to this: query("div#mapDiv").on('click', lang.hitch (this, textMe))
The map is showing again, but the text is not adding now. The "if query text button accessed message" shows in the console when I press the submit button.
... View more
02-25-2015
12:34 PM
|
0
|
3
|
1854
|
|
POST
|
Hi, I have a web map where users want to be able to add their own text to the map. But for some reason the code is ignoring my if statement that says only add text when button is clicked. What it's currently doing: -When user clicks on map, the default text entered in the Text Box displays on the map. -When user presses the submit text button, clicks on the map, the text entered in the Text Box displays on the map. -Text is added to the map even after the submit button was pressed once when user clicks on map. -It conflicts with the other tools in the map like the measure tool. What I want it to do: -I only want the text in the text box to show after the submit button is pressed once not conflict with other tools. [Ex., user presses the submit button, clicks on map, text is added to the map. User clicks on map again, no text is added to the map. If user wants text to be added to the map again, the user will have to click the submit button again.] Background Info: Level: newbie JS developer. Using ESRI JavaScript API - ESRI's Public information web map template: Esri/public-information-map-template-js · GitHub This code was added to the main.js file in the _init: function (). The code is posted below. Suggestions appreciated. Thanks. if (this.config.enableAddText) {
if (query("div#TextButton .dijitButton .dijitButtonNode").on('click', lang.hitch (this, function()
{console.log("if query text button accessed")
})))
{
var map = this.map;
console.log("text button was clicked");
query("div#mapDiv").on('click', lang.hitch (this, function (evt){
var map = this.map;
map.graphics.add(
new Graphic(
new Point(evt.mapPoint.x, evt.mapPoint.y, new esri.SpatialReference({ wkid: 102100 })),
new TextSymbol(dojo.byId("tsText").value).setColor(
new Color([0,0,0])).setAlign(esri.symbol.Font.ALIGN_START).setAngle(0).setOffset(0,0).setFont(
new Font("12pt").setWeight(esri.symbol.Font.WEIGHT_BOLD))
)
);
console.log(map);
console.log(evt.mapPoint.x);
console.log(evt.mapPoint.y);
console.log(dojo.byId("tsText").value);
console.log("added text graphic");
}));
}
};
... View more
02-25-2015
12:00 PM
|
0
|
8
|
5436
|
|
POST
|
It worked! Thanks so much! I always wondered what lang.hitch was used for. I have a lot to learn.
... View more
02-24-2015
11:11 AM
|
1
|
0
|
1235
|
|
POST
|
@khutchins-esristaff I get this error when I press one of my measurement buttons: Uncaught TypeError: Cannot read property 'setInfoWindowOnClick' of undefinedmain.js:442 (anonymous function)init.js:1492 n.__onClickinit.js:177 (anonymous function) I already added the query and on modules too. This is what I have after measurement startup in my public information template main.js page: query(".esriMeasurementButtonPane .esriButton").on("click", function(c){ var tool = measurement.getTool(); var map = this.map; if(tool){ //deactivate the popup window map.setInfoWindowOnClick(false); }else{ //activate the popup window map.setInfoWindowOnClick(true); } });
... View more
02-24-2015
09:46 AM
|
0
|
4
|
1235
|
|
POST
|
@Kelly Hutchins, yes, I had to add the measure widget to myself. I literally just copied the code from ESRI's sample page to main.js and it worked. var measurement = new Measurement({ map: this.map }, dom.byId("measureButton")); measurement.hideTool("location"); measurement.startup(); The widget shows the area and distance buttons, Measurement Result text, and area that shows the number results. So they have to press the area or distance button to turn it on and off. Is it possible to do this without creating buttons to turn on and off popups?
... View more
02-23-2015
07:48 AM
|
0
|
12
|
1574
|
|
POST
|
Will this turn off my pop ups completely? (beginner coder here lol) I still want my pop ups to show up, just not when I'm using the measure tool. I'm also using esri's JavaScript public information web map template with my data stored on AGOL if that matters. My map also has other widgets like draw, geocoder, adding text, and printing that I don't want to mess up as well.
... View more
02-20-2015
01:22 PM
|
0
|
15
|
1574
|
|
POST
|
A blog post would be great! I'm surprised this topic is not talked about more. It seems like most web maps could make use of this functionality.
... View more
02-20-2015
11:35 AM
|
0
|
0
|
1399
|
|
POST
|
Any recent suggestions for the AMD Module? Popups configured in my AGOL based JavaScript web map keep popping up when ESRI's measure widget is used. [My popups are configured in AGOL; not created manually in my code with infowindow.]
... View more
02-20-2015
11:31 AM
|
0
|
18
|
1574
|
|
POST
|
I think you're going to have to download the web app builder and manually code it in yourself for web app builder.
... View more
02-19-2015
10:44 AM
|
1
|
1
|
2683
|
|
POST
|
Thanks so much odoe! It now works!! I'm just wondering now why it works. Lol. Do you mind explaining what it's doing? I wonder why this code works vs the one you mention before below: // get the URL parameters var params = urlUtils.urlToObject(document.location.href); // check that parameters exist in the URL if (params.query && params.query.address) { var address = params.query.address; map.graphics.clear(); // build address params var addressParams = { "SingleLine": params.query.address }; locator.outSpatialReference = map.spatialReference; var options = { address: addressParams, outFields: ["Loc_name"] }; // send to locator locator.addressToLocations(options);
... View more
02-19-2015
07:56 AM
|
0
|
2
|
1399
|
| Title | Kudos | Posted |
|---|---|---|
| 2 | 01-08-2016 10:52 AM | |
| 1 | 02-24-2015 11:11 AM | |
| 1 | 02-19-2015 10:44 AM |
| Online Status |
Offline
|
| Date Last Visited |
11-11-2020
02:23 AM
|