|
POST
|
Apologies if I wasn't very clear. I was more or less wondering if the len() function was doing what I intended it to, which was to count the occurrences of the COVID-19 element not the length of the string. The script is meant to find the number of times "COVID-19" occurs in that URL. If that number changes the next time the script runs (through Task Scheduler) it triggers an email to one of the GIS staff members here (I left those parts out for clarification). I see what you mean, though. You have to really study the HTML in able to get the script to accurately find things. It's a little difficult to find time to know a website that good when you're looking at every municipal and school district website in the county, however. They change constantly.
... View more
08-20-2020
07:45 AM
|
0
|
3
|
9881
|
|
POST
|
I think this gets me the length of the text count for "COVID-19" because it prints 8. import requests
from bs4 import BeautifulSoup
import re
url = r'https://www.bolingbrook.com/coronavirus'
#request webpage
soup = BeautifulSoup(requests.get(url.content, "lxml")
#find occurences of string
print(len(soup.find_all(string=re.compile("COVID-19"))))
#prints
>>> 8 When I do a CTRL+F for "COVID-19" on the webpage I get a count of 5 occurrences. When I do a CTRL+F for "COVID-19" in the Developer tools I get 15. I'm trying to get the count for the total occurrences of the string "COVID-19". How can I set up the code to do that?
... View more
08-19-2020
08:15 AM
|
0
|
5
|
9982
|
|
POST
|
I figured out a work-around. I created a PNG of the legend and pasted it into the editor of the Info widget. So now it shows the sub-text beneath the legend, and then some other things. Not the greatest, but it works.
... View more
08-14-2020
08:33 AM
|
0
|
0
|
1141
|
|
POST
|
Is there a way to add an endnote to a feature in the legend? I need to further clarify what the feature is. Here's an image of what I mean (I added the text in a graphics editor). The endnotes are circled in red.
... View more
08-13-2020
12:58 PM
|
1
|
2
|
1176
|
|
POST
|
How do I set up autocomplete on a query? My app is already set up to query a feature layer. I'd just like to know how to incorporate an autocomplete on the feature layer query so that the feature's attributes from the Category field will be listed as the user types. These help docs are similar, but I don't need another text box: -Auto complete a textbox from a map service in a widget -https://community.esri.com/people/mlewis22/blog/2014/10/21/autocomplete-search-box-using-arcgis-services <script>
// JavaScript source code
require([
"esri/Map",
"esri/views/MapView",
"esri/layers/FeatureLayer",
"esri/layers/GraphicsLayer",
"esri/widgets/Home",
], function (
Map,
MapView,
FeatureLayer,
GraphicsLayer,
Home
) {
var catTypeSelect = document.getElementById("category");
var keyTypeSelect = document.getElementById("keyword");
var filterButton = document.getElementById("filterBtn");
var resRb = document.getElementById("ResidentialRB");
// Recycle
var recycleLayer = new FeatureLayer({
portalItem: {
// autocasts as new PortalItem()
id: "b5665da3feab4b6091914cbfe4ab028f"
},
});
// GraphicsLayer for displaying results
var resultsLayer = new GraphicsLayer();
//Set map view
var map = new Map({
basemap: "dark-gray",
layers: [recycleLayer, resultsLayer]
});
var view = new MapView({
container: "viewDiv",
map: map,
center: [-87.95, 41.47],
zoom: 9
});
// query all features from the recycle layer
view
.when(function () {
return recycleLayer.when(function () {
var query = recycleLayer.createQuery();
return recycleLayer.queryFeatures(query);
});
})
.then(getValues)
.then(getUniqueValues)
.then(addToSelect)
// re-query the layer based on the selected Category and re-populate the keyword select
catTypeSelect.addEventListener("change", function () {
var sqlExp = "";
if (catTypeSelect.selectedIndex > 0) {
sqlExp += "Category LIKE '%" + catTypeSelect.options[catTypeSelect.selectedIndex].value + "%'";
}
var query = recycleLayer.createQuery();
query.where = sqlExp;
recycleLayer.queryFeatures(query)
.then(getValues2)
.then(getUniqueValues2)
.then(addToSelect2)
});
// return an array of all the values in the
// Category and item_keyword fields of the Recycle layer
function getValues(response) {
var features = response.features;
var values = features.map(function (feature) {
return {
Category: feature.attributes.Category,
item_keyword: feature.attributes.item_keyword
}
});
return values;
}
// re-query the layer based on the selected Category and re-populate the keyword select
function getValues2(response) {
var features = response.features;
var values = features.map(function (feature) {
return feature.attributes.item_keyword
});
return values;
}
// return an array of unique values in
// the item_keyword and Category fields of the Recycle layer
function getUniqueValues(values) {
var uniqueKeyValues = [];
var uniqueCatValues = [];
values.forEach(function (item, i) {
var keyVal = item.item_keyword.split(";");
var catVal = item.Category.split(";");
catVal.map(function (val1) {
if (
(uniqueCatValues.length < 1 || uniqueCatValues.indexOf(val1) === -1) &&
val1 !== ""
) {
uniqueCatValues.push(val1);
}
});
keyVal.map(function (val2) {
if (
(uniqueKeyValues.length < 1 || uniqueKeyValues.indexOf(val2) === -1) &&
val2 !== ""
) {
uniqueKeyValues.push(val2);
}
});
});
return {
uKeyVals: uniqueKeyValues,
uCatVals: uniqueCatValues
};
}
// re-query the layer based on the selected Category and re-populate the keyword select
function getUniqueValues2(values) {
var uniqueKeyValues = [];
values.forEach(function (item, i) {
var keyVal = item.split(";");
keyVal.map(function (val2) {
if (
(uniqueKeyValues.length < 1 || uniqueKeyValues.indexOf(val2) === -1) &&
val2 !== ""
) {
uniqueKeyValues.push(val2);
}
});
});
return uniqueKeyValues;
}
// Add the unique values to the recycle type
// select element. This will allow the user
// to filter categories by type.
function addToSelect(values) {
var dOpt = document.createElement("option");
dOpt.value = "";
dOpt.selected = true;
dOpt.text = "Select one";
catTypeSelect.add(dOpt);
values.uCatVals.sort();
values.uCatVals.forEach(function (value) {
var option = document.createElement("option");
option.text = value;
catTypeSelect.add(option);
});
var dOpt2 = document.createElement("option");
dOpt2.value = "";
dOpt2.selected = true;
dOpt2.text = "Select one";
keyTypeSelect.add(dOpt2);
values.uKeyVals.sort();
values.uKeyVals.forEach(function (value) {
var option = document.createElement("option");
option.text = value;
keyTypeSelect.add(option);
});
return setDefinitionExpression();
}
// re-query the layer based on the selected Category and re-populate the keyword select
function addToSelect2(values) {
while (keyTypeSelect.options.length > 0) {
keyTypeSelect.remove(0);
}
var dOpt2 = document.createElement("option");
dOpt2.value = "";
dOpt2.disabled = true;
dOpt2.selected = true;
dOpt2.text = "Select one";
keyTypeSelect.add(dOpt2);
values.sort();
values.forEach(function (value) {
var option = document.createElement("option");
option.text = value;
keyTypeSelect.add(option);
});
return true
}
// set the definition expression on the recycle
// layer to reflect the selection of the user
function setDefinitionExpression() {
var sqlExp = "";
if (catTypeSelect.selectedIndex > 0) {
sqlExp += "Category LIKE '%" + catTypeSelect.options[catTypeSelect.selectedIndex].value + "%'";
}
if (keyTypeSelect.selectedIndex > 0) {
if (sqlExp === "") {
sqlExp += "item_keyword LIKE '%" + keyTypeSelect.options[keyTypeSelect.selectedIndex].value + "%'";
} else {
sqlExp += " AND item_keyword LIKE '%" + keyTypeSelect.options[keyTypeSelect.selectedIndex].value + "%'";
}
}
if (resRb.checked) {
if (sqlExp !== "") {
sqlExp += " AND USER_IsRes = 'TRUE'";
}
} else {
if (sqlExp !== "") {
sqlExp += " AND USER_IsBus = 'TRUE'";
}
}
console.info(sqlExp);
recycleLayer.definitionExpression = sqlExp;
if (!recycleLayer.visible) {
recycleLayer.visible = true;
}
return queryForGeometries();
}
// Get all the geometries of the recycle layer
// the createQuery() method creates a query
// object that respects the definitionExpression
// of the layer
function queryForGeometries() {
var rQuery = recycleLayer.createQuery();
return recycleLayer.queryFeatures(rQuery).then(function (response) {
rGeometries = response.features.map(function (feature) {
return feature.geometry;
});
return rGeometries;
});
}
filterButton.addEventListener("click", function () {
setDefinitionExpression();
});
});
</script> Here's the whole app on Codepen.
... View more
08-05-2020
01:44 PM
|
0
|
0
|
1379
|
|
POST
|
Hannah, I think maybe your problem is here: if oldtext in elm.text:
elm.text = newtext As the help doc points out, you have to find the text with the Equal To operator. It doesn't look like you tried that. Try this: for lyt in aprx.listLayouts():
for elm in lyt.listElements("TEXT_ELEMENT"):
if elm.text == oldtext:
elm.text = newtext
... View more
08-05-2020
07:15 AM
|
1
|
0
|
4171
|
|
POST
|
I have a text element that I can't seem to find. I'm using this support document: TextElement—ArcGIS Pro | Documentation I can find it if I use the the text Name (Text 37), but in my case I have a multitude of maps and Text 37 might have irrelevant text in another map. So, in short I need to find and replace the Text. Here's the script I'm using but it doesn't change the Text. I think maybe it's because "Lawrence M. Walsh Will County Executive" is in two lines. Can anyone see what the issue may be? import arcpy, os
#workspace folder
arcpy.env.workspace = ws = r"pathto\TestFolder"
#print the number of aprx files in the workspace folder
aprxlist = arcpy.ListFiles("*.aprx")
print("Currently {0} maps to be updated.".format(len(aprxlist)))
#list the aprxs of the workspace folder
for aprxname in arcpy.ListFiles("*.aprx"):
print("changing text: {}\t".format(aprxname))
aprx = arcpy.mp.ArcGISProject(ws + "\\" + aprxname)
#replace title date that occurs in the document
for lyt in aprx.listLayouts():
for elm in lyt.listElements('TEXT_ELEMENT'):
if elm.text == 'Lawrence M. Walsh': #text
elm.text = 'Denise Winfrey' #new text
print(elm.text)
aprx.save()
#do not include this delete statement inside the above loop or it will
#delete the mxd object inside the loop. Make sure to dedent.
del aprx
print("----done----")
... View more
07-29-2020
02:43 PM
|
0
|
4
|
4225
|
|
POST
|
Does anyone know what this little symbol is, or how I get rid of it? It must be coming from the attributes of the hosted feature layer, but I have know idea how to type it in a search? The drop-down is in an JS API 4.16 app. The data is coming from a hosted feature layer.
... View more
07-24-2020
08:38 PM
|
0
|
0
|
753
|
|
POST
|
In my app, I'm having trouble shrinking the size of the sidebar so that it looks good on a mobile device. Here's the app in Code Pen: https://codepen.io/underjollyroger/pen/XWXPgqm?editors=1100 In this older post they collapse the sidebar into a button, but they're using Bootstrap: First attempt at bootstrap w/ sidebar. I was wondering how to do that based on this Responsive apps using CSS sample code because I'm not familiar with Bootstrap. (1) When the width breakpoint is less than medium (769-992 pixels) I'd like the sidebar to disappear. (2) In its place I'd like there to be a button. When the button is clicked I'd like to show the content of the sidebar. To at least get the sidebar to disappear, I can't even find its element ID. This doesn't work: .esri-view-width-less-than-medium .sidebar {
display: none;
}
... View more
07-16-2020
09:44 AM
|
0
|
0
|
1527
|
|
POST
|
Thanks again Robert. I'll plug that in. In the meantime, you already answered the thread. I'll mark it correct.
... View more
07-10-2020
02:07 PM
|
0
|
0
|
2761
|
|
POST
|
Thanks Robert! I need them to be able to select it because when a Category is selected it is supposed to filter the corresponding keyword(s). If "Select one" is not selectable I don't see how the user can sort of reset their search. Honestly, the app is not functioning correctly at the moment, so when it is I probably won't have to remove that line. I've requested ESRI's help in the matter, but here's how it is supposed to (i.e. how I'd like it to) work: User selects Category --> Keyword(s) automatically get filtered leaving only those features in the map. All Categories have their corresponding keywords, for example Asbestos Info / Removal Service: I'm basically lacking a function that filters a Categories' corresponding Keyword(s), I guess.
... View more
07-10-2020
12:23 PM
|
0
|
2
|
2761
|
|
POST
|
Hi Robert, Thanks for that. I implemented those changes and it does what I asked! But, is there a way to make the "Select one" selectable? Right now, the end-user can see it but can't click it.
... View more
07-10-2020
11:42 AM
|
0
|
4
|
2761
|
|
POST
|
How do I add "Select One" to the top of the drop-down such as this? Right now the first choice is the first value in the table when sorted ascending (i.e. Appliance Recycling). Also, something's wrong because even though it shows "Appliance Recycling" ALL the features are in fact on the map. There are actually only 16 "Appliance Recycling" categories. I'm not sure if this is related to the table or something in the code. Current Code <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
<title>Recycling Map</title>
<link rel="stylesheet" href="https://js.arcgis.com/4.15/esri/themes/light/main.css" />
<script src="https://js.arcgis.com/4.15/"></script>
<style>
html,
body,
#viewDiv {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
#viewDiv {
position: absolute;
height: calc(100% - 67px);
top: 67px;
}
#filterDiv {
position: relative;
background-color: white;
color: black;
padding: 6px;
top: 0;
background: #d4e1c0;
border-bottom: 1px dotted #91dca1;
}
#category,
#keyword {
margin-top: 8px;
margin-bottom: 8px;
display: inline-block;
}
.drop-downs {
width: 100%;
}
.oneline {
display: inline-block;
margin-right: 6px;
}
#filterBtn {
position: fixed;
right: 6px;
top: 6px;
width: 50px;
font: bold 12px Trebuchet MS;
color: #fff;
background-color: #098941;
border: 1px solid #1c9c52;
text-decoration: none;
cursor: pointer;
padding: 2px 4px;
}
#filterBtn:hover {
background-color: #098dd1;
border: 1px solid #0ab0ed;
}
.docking-control {
position: absolute;
z-index: 10;
top: 50%;
left: 50%;
width: 250px;
height: 80px;
padding: 10px;
box-sizing: border-box;
margin: -40px 0 0 -125px;
background-color: #fff;
color: #323232;
text-align: center;
-webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}
.docking-control label {
display: inline-block;
font-weight: bold;
margin: 0 0 10px 0;
padding: 0;
font-size: 16px;
}
#titleDiv {
padding: 10px;
}
#titleText {
color: #098941;
font-size: 20pt;
font-weight: 500;
padding-bottom: 10px;
}
</style>
<script>
require([
"esri/Map",
"esri/views/MapView",
"esri/layers/FeatureLayer",
"esri/layers/GraphicsLayer",
"esri/geometry/geometryEngine",
"esri/Graphic"
], function (
Map,
MapView,
FeatureLayer,
GraphicsLayer,
geometryEngine,
Graphic,
) {
var catTypeSelect = document.getElementById("category");
var keyTypeSelect = document.getElementById("keyword");
var filterButton = document.getElementById("filterBtn");
var resRb = document.getElementById("ResidentialRB");
//***popups***
//popup template
var template = { //autocasts the new template
title: "<b>{USER_Name}</b>",
content: [
{ //set content elements in the order to display
type: "fields",
fieldInfos: [{
fieldName: "USER_Addre",
label: "Address",
visible: true,
}, {
fieldName: "USER_City",
label: "City",
visible: true,
},
{
fieldName: "USER_Phone",
label: " Phone",
visible: true,
},
{
fieldName: "USER_Email",
label: "Email",
visible: true,
},
{
fieldName: "USER_Notes",
label: "Notes",
visible: true,
},]
},
{
// You can also set a descriptive text element
type: "text", // TextContentElement
text: "<font color= '#098941'><b>{Description}</b>"
}],
};
// Recycle
var recycleLayer = new FeatureLayer({
portalItem: {
// autocasts as new PortalItem()
id: "227061be60a14cc89946a978b440d227"
},
popupTemplate: template,
outFields: ["*"],
visible: false
});
// GraphicsLayer for displaying results
var resultsLayer = new GraphicsLayer();
var map = new Map({
basemap: "dark-gray",
layers: [recycleLayer, resultsLayer]
});
var view = new MapView({
container: "viewDiv",
map: map,
center: [-87.95, 41.47],
zoom: 10,
//popup
popup: {
}
});
popup = view.popup;
// query all features from the recycle layer
view
.when(function () {
return recycleLayer.when(function () {
var query = recycleLayer.createQuery();
return recycleLayer.queryFeatures(query);
});
})
.then(getValues)
.then(getUniqueValues)
.then(addToSelect)
// return an array of all the values in the
// Category and USER_Keywo fields of the Recycle layer
function getValues(response) {
var features = response.features;
var values = features.map(function (feature) {
return {
Category: feature.attributes.Category,
USER_Keywo: feature.attributes.USER_Keywo
}
});
return values;
}
// return an array of unique values in
// the USER_Keywo and Category fields of the Recycle layer
function getUniqueValues(values) {
var uniqueKeyValues = [];
var uniqueCatValues = [];
values.forEach(function (item, i) {
var keyVal = item.USER_Keywo.split(";");
var catVal = item.Category.split(";");
catVal.map(function (val1) {
if (
(uniqueCatValues.length < 1 || uniqueCatValues.indexOf(val1) === -1) &&
val1 !== ""
) {
uniqueCatValues.push(val1);
}
});
keyVal.map(function (val2) {
if (
(uniqueKeyValues.length < 1 || uniqueKeyValues.indexOf(val2) === -1) &&
val2 !== ""
) {
uniqueKeyValues.push(val2);
}
});
});
return {
uKeyVals: uniqueKeyValues,
uCatVals: uniqueCatValues
};
}
// Add the unique values to the recycle type
// select element. This will allow the user
// to filter categories by type.
function addToSelect(values) {
values.uCatVals.sort();
values.uCatVals.forEach(function (value) {
var option = document.createElement("option");
option.text = value;
catTypeSelect.add(option);
});
values.uKeyVals.sort();
values.uKeyVals.forEach(function (value) {
var option = document.createElement("option");
option.text = value;
keyTypeSelect.add(option);
});
return setDefinitionExpression();
}
// set the definition expression on the recycle
// layer to reflect the selection of the user
function setDefinitionExpression() {
var sqlExp = "";
if (catTypeSelect.selectedIndex > 0) {
sqlExp += "Category LIKE '%" + catTypeSelect.options[catTypeSelect.selectedIndex].value + "%'";
}
if (keyTypeSelect.selectedIndex > 0) {
if (sqlExp === "") {
sqlExp += "USER_Keywo LIKE '%" + keyTypeSelect.options[keyTypeSelect.selectedIndex].value + "%'";
} else {
sqlExp += " AND USER_Keywo LIKE '%" + keyTypeSelect.options[keyTypeSelect.selectedIndex].value + "%'";
}
}
if (resRb.checked) {
if (sqlExp !== "") {
sqlExp += " AND USER_IsRes = 'TRUE'";
}
} else {
if (sqlExp !== "") {
sqlExp += " AND USER_IsBus = 'TRUE'";
}
}
console.info(sqlExp);
recycleLayer.definitionExpression = sqlExp;
if (!recycleLayer.visible) {
recycleLayer.visible = true;
}
return queryForGeometries();
}
// Get all the geometries of the recycle layer
// the createQuery() method creates a query
// object that respects the definitionExpression
// of the layer
function queryForGeometries() {
var rQuery = recycleLayer.createQuery();
return recycleLayer.queryFeatures(rQuery).then(function (response) {
rGeometries = response.features.map(function (feature) {
return feature.geometry;
});
return rGeometries;
});
}
filterButton.addEventListener("click", function () {
setDefinitionExpression();
});
view.ui.add("titleDiv", "bottom-right");
});
</script>
</head>
<body>
<div id="viewDiv"></div>
<div id="filterDiv">
<div class="drop-downs">
<div class="oneline">Select Category:</div>
<select id="category" class="oneline"></select>
<div class="oneline">Select Keyword:</div>
<select id="keyword" class="oneline"></select>
<div>
<input id="ResidentialRB" name="resorbus" type="radio" value="Residential" checked="checked"><label for="ResidentialRB">Residential</label>
<input id="BusinessRB" name="resorbus" type="radio" value="Business"><label for="BusinessRB">Business</label>
</div>
<button id="filterBtn">Search</button>
</div>
<div id="titleDiv" class="esri-widget">
<div id="titleText">Green Guide</div>
<div>Easy Ways To Be More Green</div>
</div>
</div>
</body>
</html>
... View more
07-09-2020
01:48 PM
|
0
|
6
|
2851
|
|
POST
|
That worked. Thanks a lot. The script worked until it ran into a KeyError. I think that may have to do with the fact that the 'Compost Facilities/Landscape Waste Transfer Stations' field is NULL. I'll fix that and try again. In the meantime i'll mark your answer correct! ---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-32-9dbca838b891> in <module>
23 for row in cursor:
24 # for each feature, looks up description from the description_dict, using the category as the key
---> 25 row[0] = description_dict[row[1]]
26 cursor.updateRow(row)
KeyError: 'Compost Facilities/Landscape Waste Transfer Stations'
... View more
07-08-2020
01:32 PM
|
0
|
1
|
5132
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 4 weeks ago | |
| 1 | 05-04-2026 08:45 AM | |
| 1 | 04-20-2026 01:20 PM | |
| 1 | 07-24-2025 01:27 PM | |
| 1 | 11-13-2025 08:22 AM |
| Online Status |
Offline
|
| Date Last Visited |
16 hours ago
|