|
POST
|
Joshua, That looks like exactly what I was thinking. Making a dictionary of the categories and descriptions and then using the category as the key was 'key'. I ran into a little problem, though, that I'm currently looking into. The SearchCursor is not accepting the in_table parameter. What I thought was a table is actually a 'Feature Layer Collection', which is what is causing the error I believe. Overview of Green Descriptions Table (created from a CSV). Jupyter Notebook calls the Table a 'Feature Layer Collection' I found out. Script with error. I started a new thread about this: 'in_table' is not a table or a featureclass
... View more
07-08-2020
12:40 PM
|
0
|
3
|
5129
|
|
POST
|
Why is this Table not a table? At first I had 'Table' in the type parameter and got [ ]. Then I found out the Table is actually a 'Feature Layer Collection'. So, that's great. Or so I thought. But, then I get an error telling me the table is not a table? with arcpy.da.SearchCursor(table, fields) as cursor:
for row in cursor:
description_dict[row[1]] = row[0] ---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-21-bdc66f453653> in <module>
13 description_dict = {}
14
---> 15 with arcpy.da.SearchCursor(table, fields) as cursor:
16 for row in cursor:
17 description_dict[row[1]] = row[0]
RuntimeError: 'in_table' is not a table or a featureclass
I then tried the Green Descriptions CSV but got the same error. with arcpy.da.SearchCursor(csv, fields) as cursor:
for row in cursor:
description_dict[row[1]] = row[0] ---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-22-b36d2a96d554> in <module>
13 description_dict = {}
14
---> 15 with arcpy.da.SearchCursor(csv, fields) as cursor:
16 for row in cursor:
17 description_dict[row[1]] = row[0]
RuntimeError: 'in_table' is not a table or a featureclass I've came across a similar thread posted earlier this year that was never answered Convert from Feature Collection to Feature Class
... View more
07-08-2020
12:09 PM
|
1
|
2
|
4759
|
|
POST
|
Hi Joshua, I did try the join and then the field calculator in Pro before this, and for some reason it didn't work. Now I tried again and it did work! Thanks for the idea. It now seems like overkill to go the automation route, but yes, I am still curious how it can be done. I know you can use a cursor on a feature service using the Python API, as I have used that very script (above) before. That's why I'm posting in this group.
... View more
07-08-2020
09:00 AM
|
0
|
5
|
5129
|
|
POST
|
I'm trying to populate the 'Description' field in the Recycling Locations View layer (a hosted Feature Layer) with the text from the 'Description' field in the Green Descriptions layer (a hosted Table). The 'Category' field from both have the same values. The script I have uses the UpdateCursor to populate a field based on another field from the same Feature Layer. I think I can create a list with the text from the 'Description' field, but that seems redundant seeing as though there is probably a way to bring it in straight from the hosted table? import arcpy, requests, json
#disable warnings
requests.packages.urllib3.disable_warnings()
#Recycling Locations Feature layer
fc = survey_item
#text to populate the Description field of the Recycling Locations layer
descriptions = ['Refrigerators, stoves, dishwashers, water heaters and other large appliances are considered white goods and are banned from landfills. Hazardous components such as mercury, CFCs and PCBs are dangerous and require proper handling and disposal. When purchasing an appliance, request the company to take your “old” appliance or contact your city/village. A list of certified Freon removal specialists is not currently available. The U.S. EPA administers a program to certify technicans. Their requirements can be found at http://www.epa.gov/Ozone/title6/608/608fact.html#techcert',
'ASBESTOS - Asbestos is a naturally occurring mineral found in certain rocks. Asbestos was commonly used in home building materials before the mid-1970s and occasionally until the late 1980s because it is strong, fire- and corrosion-resistant and a good insulator. If asbestos is in good condition and left in place, it should not present health risks. However, if a building is going to be demolished, renovated, or remodeled, care should be taken to prevent the release of asbestos fibers into the air. Inhalation of microscopic asbestos fibers can cause health risks. You may search for Licensed Asbestos Professionals in the Yellow Pages or call the Illinois Dept. of Public Health.',
'In most cases older vehicles are traded-in or brought to an auto salvage yard; or you may choose to donate them for parts reuse and recycling. Contact the following organizations to make arrangements, get paid or ask about tax deduction information.',
... etc.
]
#fields from the Recycling Locations layer
fields = ['Description', 'Category']
#use the updatecursor to populate the Description field from the descriptions list
with arcpy.da.UpdateCursor(fc, fields) as cursor:
for row in cursor:
if row[1] == 'Appliance Recycling':
row[0] = descriptions[0]
elif row[1] == 'Asbestos Info / Removal Service':
row[0] = descriptions[1]
elif row[1] == 'Automobile & Boat Reuse Recycling':
row[0] = descriptions[2]
cursor.updateRow(row)
del cursor
... View more
07-08-2020
07:59 AM
|
0
|
7
|
5264
|
|
POST
|
Robert, You make it seem so easy! Thanks for the constant help.
... View more
07-01-2020
08:01 AM
|
0
|
0
|
2340
|
|
POST
|
This question is a continuation of my last one: Query Features by Category and Keyword The app so far has two drop-downs. The user can query by categories and query by keywords. <!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;
}
#infoDiv {
background-color: white;
color: black;
padding: 6px;
width: 440px;
}
#titleDiv {
padding: 10px;
}
#titleText {
font-size: 20pt;
font-weight: 60;
padding-bottom: 10px;
}
#results {
font-weight: bolder;
padding-top: 10px;
}
#category,
#keyword {
margin-top: 8px;
margin-bottom: 8px;
}
</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("SelectBtn");
// Recycling Locations View
var recycleLayer = new FeatureLayer({
portalItem: {
// autocasts as new PortalItem()
id: "227061be60a14cc89946a978b440d227"
},
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
});
view.ui.add("infoDiv", "top-left");
// 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
// USER_Categ and USER_Keyword fields of the Recycle layer
function getValues(response) {
var features = response.features;
var values = features.map(function (feature) {
return {
USER_Categ: feature.attributes.USER_Categ,
USER_Keywo: feature.attributes.USER_Keywo
}
});
return values;
}
// return an array of unique values in
// the keyword 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.USER_Categ.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 category type
// select element. This will allow the user
// to filter categorys 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 += "USER_Categ 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 + "%'";
}
}
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();
});
// set a new definitionExpression on the recycle layer
// catTypeSelect.addEventListener("change", function () {
// var type = event.target.value;
// setDefinitionExpression(type, "cat");
// });
// set a new definitionExpression on the recycle layer
// keyTypeSelect.addEventListener("change", function () {
// var type = event.target.value;
// setDefinitionExpression(type, "key");
// });
view.ui.add("titleDiv", "top-right");
});
</script>
</head>
<body>
<div id="viewDiv"></div>
<div id="infoDiv" class="esri-widget">
<div id="drop-downs">
Select Category (leave blank if searching by Keyword):
<select id="category" class="esri-widget"></select>
Select Keyword:
<select id="keyword" class="esri-widget"></select>
<button id="SelectBtn" class="esri-button esri-button--secondary">Search</button>
</div>
<div id="results" class="esri-widget"></div>
</div>
<div id="titleDiv" class="esri-widget">
<div id="titleText">Green Guide</div>
<div>Easy Ways To Be More Green</div>
</div>
</body>
</html> Now I'd like to filter the categories and keywords based on two fields in the attribute table, USER_IsRes and USER_IsBus (residential and business). The values are either TRUE or FALSE-- Feature Layer View. I'm able to use a sample and loosely get that to function with the USER_IsRes field. <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="initial-scale=1,maximum-scale=1,user-scalable=no"
/>
<title>Filter features by attribute - 4.15</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 {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
#res-filter {
height: 160px;
width: 100%;
visibility: hidden;
}
.res-item {
width: 100%;
padding: 12px;
text-align: center;
vertical-align: baseline;
cursor: pointer;
height: 40px;
}
.res-item:focus {
background-color: dimgrey;
}
.res-item:hover {
background-color: dimgrey;
}
#titleDiv {
padding: 10px;
}
#titleText {
font-size: 20pt;
font-weight: 60;
padding-bottom: 10px;
}
</style>
<script>
require([
"esri/views/MapView",
"esri/Map",
"esri/layers/FeatureLayer",
"esri/widgets/Expand"
], function (MapView, Map, FeatureLayer, Expand) {
let floodLayerView;
// flash flood warnings layer
const layer = new FeatureLayer({
portalItem: {
id: "227061be60a14cc89946a978b440d227"
},
outFields: ["USER_IsRes"]
});
const map = new Map({
basemap: "gray-vector",
layers: [layer]
});
const view = new MapView({
map: map,
container: "viewDiv",
center: [-98, 40],
zoom: 4
});
const resNodes = document.querySelectorAll(`.res-item`);
const resElement = document.getElementById("res-filter");
// click event handler for res choices
resElement.addEventListener("click", filterByres);
// User clicked on Winter, Spring, Summer or Fall
// set an attribute filter on flood warnings layer view
// to display the warnings issued in that res
function filterByres(event) {
const selectedres = event.target.getAttribute("data-res");
floodLayerView.filter = {
where: "USER_IsRes = '" + selectedres + "'",
};
}
view.whenLayerView(layer).then(function(layerView) {
// flash flood warnings layer loaded
// get a reference to the flood warnings layerview
floodLayerView = layerView;
// set up UI items
resElement.style.visibility = "visible";
const resExpand = new Expand({
view: view,
content: resElement,
expandIconClass: "esri-icon-filter",
group: "top-left"
});
//clear the filters when user closes the expand widget
resExpand.watch("expanded", function() {
if (!resExpand.expanded) {
floodLayerView.filter = null;
}
});
view.ui.add(resExpand, "top-left");
view.ui.add("titleDiv", "top-right");
});
});
</script>
</head>
<body>
<div id="res-filter" class="esri-widget">
<div class="res-item visible-res" data-res="TRUE">True</div>
<div class="res-item visible-res" data-res="False">False</div>
</div>
<div id="viewDiv"></div>
<div id="titleDiv" class="esri-widget">
<div id="titleText">Flash Floods by res</div>
<div>Flash Flood Warnings (2002 - 2012)</div>
</div>
</body>
</html>
But, how do I incorporate the filter (preferably client side since they say it's faster) into the app? Once the user has either a keyword or category selected I want there to be a way to filter with either Residential or Business. In the end, the selection methods should more or less mirror this page: Will County EEC Mobile Site
... View more
06-30-2020
02:28 PM
|
0
|
3
|
2416
|
|
POST
|
Hi Xander Bakker, Thanks for the reply! I have the feature layer view as the fc variable. Here's the script as I ran it last. Here's the view: https://willcountygis.maps.arcgis.com/home/item.html?id=227061be60a14cc89946a978b440d227 Edit 8:57am: I made sure all the groups are in your list, and they are. #-------------------------------------------------------------------------------
# Name: categories.py
# Purpose:
#
# Author: xbakker
#
# Created: 24/06/2020
#-------------------------------------------------------------------------------
def main():
import arcpy
# configuration
fc = r'https://services.arcgis.com/fGsbyIOAuxHnF97m/arcgis/rest/services/Recycling_Locations/FeatureServer/0' # point to your datasource
fld_kw = "USER_Categ" # your input field
fld_res = "Keyword" # your output string field
with arcpy.da.UpdateCursor(fc, (fld_kw, fld_res)) as curs:
for row in curs:
keyword_txt = row[0]
finalgroup = GetPredominantGroup(keyword_txt)
row[1] = finalgroup
curs.updateRow(row)
def GetPredominantGroup(keyword_txt):
sep = ";"
keywords = keyword_txt.split(sep)
dct_groups = {}
for keyword in keywords:
group = GetGroup(keyword)
if not group is None:
if group in dct_groups:
dct_groups[group] += 1
else:
dct_groups[group] = 1
cntmax = 0
finalgroup = None
for group, cnt in dct_groups.items():
if cnt > cntmax:
finalgroup = group
cntmax = cnt
return finalgroup
def GetGroup(keyword):
groups = {'Appliance Recycling': 'Air Conditioner;Appliance;Refrigerator;Dishwasher;Dryer;Oven;Stove;Washer;Water Heater',
'Asbestos Info / Removal Service': 'Asbestos',
'Automobile & Boat Reuse Recycling': 'Airplane; Automobile;Boat;Car;Recreation Vehicle;RV;Truck',
'Awards & Recognition': 'Awards (Eco-Award)',
'Batteries': 'Lead-Acid Batteries;Single Use AA, AAA, C, D, 9-Volt;Batteries - Rechargeable, BackUp;Lead-Acid Batteries;Rechargebale;Disposable Batteries;Rechargeable;Automotive Batteries;Boat Batteries;Lithium Batteries;Button Batteries',
'Bicycle Reuse Donation': 'Bicycles',
'Book Recycling': 'Books - Hardcover Recycling;Books - Softcover Recycling',
'Cellular Telephone Reuse & Recycling': 'Cell Phone - Retail Drop-Off;Cell Phone - Electronic Drop Off',
'Clean - Up Services': 'Clean-Up of Properties;',
'Clothing, Linens & Shoe Reuse & Recycling-Drop-Off Locations': 'Clothing;Gym Shoes / Sneakers / HighTops;Linens / Blankets / Tableclothes / Towels;Textile / Fabrics / Drapes / Curtains;Shoes / Boots;Purse or Handbag',
'Commercial Hazardous Waste': 'Hazardous Waste Services;Chemical Business Waste',
'Composting Facilities/Landscape Waste transfer Stations': 'Composting Facilities/Landscape Waste transfer Stations;Landscape Material Recycling',
'Computer Reuse & Recycling': 'Business Electronic Devices',
'Construction & Demolition Recycling': 'Asphalt;Brick;Building Construction & Demolition Debris;Carpet;Carpet Padding;Concrete;Dirt;Drywall;Gravel;Padding;Roofing Materials;Shingles;Soil;Stone;Vinyl Siding;Windows;Wood-Untreated;Pallets',
'Cooking Oil/Grease Recycling & Trap Service': 'Cooking Oil;Grease Recycling;Grease Trap Services',
'Crayon Recycling': 'Crayons',
'Curbside Recycling': 'Aerosol Cans (empty) Curbside;Aluminum Can Curbside;Aluminum Foil Curbside;Cardboard & Chipboard Curbside;Curbside Recycling;Glass Bottles & Jars Curbside;Juice Boxes/Drink Pouches Curbside;Paper (magazines, phone bks, etc) Curbside;Plastic #1 (PET) & #2 (HDPE) Containers;Plastic #3, #4, #5, #7, Containers Curbside;Six-Pack Rings Curbside;Tin / Steel Cans (soup,cofffee, etc) Curbside',
'Demolition Material Recycling & Disposal': 'Construction Material Reuse;Demolition Material Reuse / Recycling',
'Disposable Batteries': 'Batteries - Single Use AA, AAA, C, D, 9-Volt',
'Donation': 'Books - Hardcover;Computer Reuse/Donation;Couch;Sofa;Toys',
'Drum & Cylinder Disposal or Recycling': 'Cylinders;Drums',
'Dry Cleaners (Green)': 'Dry Cleaning',
'Electronics': 'Adding Machines;Answering Machines;Calculators;Cameras;Cassettes;CB\'s/Two-way radios;CD Players / Laser Disc Players;CD ROM Drives;CDs, DVDs;Cell Phone - Electronic Drop-Off;Computer Recycling;Computer Recycling Drop-Off;Copy Machine;Cords & Cables;Digital Clocks;DVD Machine;Electronic Mice;Electronics;Fax Machines;Floppy Disks;Hand Held Games;Hard Drives;Joysticks/Game controls;Keyboards;Microwaves;Modems;Monitors;Pagers;Palm Organizers;Paper shredders;Portable Radio; Postage Machines;Printers;Scanner Machines;Speakers/Stereo Systems;String Lights / Holiday String Lights;Sump Pump;Tape Drives;Telephone;Televisions;Thermometers (digital);Typewriters/Word Processors;UPS Battery Backups;VCR Machine;VHS Tapes;Video Game Players; Zip Drives',
'Eye Glass Reuse': 'Eye Glasses',
'Fire Extinguisher Refilling or Recycling': 'Fire Extinguishers',
'Fluorescent Lights': 'CFLs;Compact Fluorescent Light Bulbs;Fluorescent Lights',
'Food Donation': 'Food Donation',
'Furniture & Office Equipment ': 'Book Cases;Cubical Walls;Desks;File Cabinets;Furniture & Office Equipment;Office Chairs',
'Geothermal Energy': 'Geothermal',
'Gift Cards': 'Gift Cards (merchant plastic money card)',
'Green Energy Supplier': 'Energy Supplier',
'Grocery Bag': 'Grocery Bags',
'Heating Oil Tank Removal': 'Heating Oil Tank Removal',
'Household Hazardous Waste (HHW)': 'Aerosol Products;Antifreeze;Automotive Batteries;Automotive Fluid;Boat Batteries;Button Batteries;Cleaning Chemicals;Compact Fluorescent Light Bulbs - HHW Drop-Off;Drain Cleaners;Driveway Sealer;Fertilizers;Fluorescent Light Bulbs;Gasoline-Oil Mix;Hazardous Household Materials;HHW;Household Chemicals;Lawn & garden chemicals;Lithium Batteries;Medication (old or unwanted);Mercury / Mercury Products;Motor Oil;Nail Polish Remover;Oil Filters;Oil-based Paint / Stain / Varnish;Old Gasoline;Paint Thinners;Pesticides;Pool Chemicals;Rechargeable Batteries;Solvents;Thermometers (glass);Used Oil;Medication (old or unwanted);Thermometers (glass);Cough Medicine;Inhalers;Medicated Shampoo;Ointment / Medicated Ointment;Over-the-Counter Medication;Pills, Pharmaceuticals, Medication;Prescription Medication;Sunscreen;Vitamins',
'Landfill & Transfer Stations': 'Landfills & Transfer Stations;Beverage Carrier Straps;Six-Pack Rings;Plastic #1, PET;Plastic #2, HDPE;Plastic #3, PVC;Plastic #4, LDPE;Plastic #5, PP;Plastic #7, Other Container;Aerosol Cans (empty) Drop-Off;Aluminum Can Recycling Drop-Off ;Aluminum Foil Recycling Drop-Off;Glass Bottles and Jars Drop-Off;Juice Boxes / Drink Pouches Drop-Off;Tin / Steel Cans (soup, coffee, etc) Drop-Off;',
'Latex Paint': 'Latex Paint',
'Lead-base Paint Concerns': 'Lead Paint',
'Manure': 'Manure',
'Matress Recycling': 'Matress & Box Springs',
'Medical Equipment (durable)': 'Canes;Crutches;Portable Toliets;Shower Chairs;Wheelchairs',
'Medication Drop-Off': 'Cough Medicine;Inhalers;Medicated Shampoo;Ointment / Medicated Ointment;Over-the-Counter Medication;Pills, Pharmaceuticals,Medication;Prescription Medication;Sunscreen;Vitamins',
'Metal Recycling': 'Scrap Metal;Aluminum / Aluminum Can Scrap;Brass;Copper;Iron;Steel Scrap;',
'Motor Oil - Bulk': 'Motor Oil in Buk Drums',
'Motor Oil Recycling (DIY)': 'Motor Oil - DIY',
'Packaging Materials': 'Packing Peanut ;Styrofoam Peanuts;Cardboard Boxes',
'Pallet Reuse or Recycling': 'Pallets',
'Paper Recycling': 'Cardboard;Chipboard;Colored Paper;Construction Paper;Junk Mail;Magazines;Newspaper;Office Paper;Paper Recycling;Shredding Services;Clored Paper',
'Plastic Carrier Strap Recycling': 'Beverage Carrier Straps;Six-Pack Rings',
'Plastic Container Recycling': 'Plastic #1, PET;Plastic #2, HDPE;Plastic #3 PVC;Plastic #4, LDPE;Plastic #5, PP;Plastic #7, Other Container',
'Pop-Tab Recycling': 'Pop-Tab',
'Printer/Toner Cartridge & Ribbon Recycling': 'Inkjets (Ribbons);Printer/Toner Cartridges',
'Propane Tank Disposal or Recycling': 'Propane Tanks',
'Rechargeable Battery': 'Batteries - Rechargeable, BackUp, Lead-Acid;Rechargeable',
'Recycling and Waste Collection Companies': 'Recycling Collection Company;Garbage Collection Company;Waste Collection Company',
'Repair Services': 'Sharpening Services',
'Reuse & Resale Shops': 'Reuse/Resale',
'Smoke Detectors ': 'Smoke Detectors ',
'Solar Energy': 'Solar Energy',
'Styrofoam or Polystyrene Recycling': 'Plastic #6, PS, Polystyrene;Styrofoam',
'Tire Recycling': 'Tire',
'Water Conservation': 'Rain Barrels;Rain Garden',
'Wind Energy': 'Small Wind'}
for group, keywords in groups.items():
if keywords.find(keyword) > -1:
return group
return None
if __name__ == '__main__':
main()
... View more
06-30-2020
06:48 AM
|
0
|
1
|
1811
|
|
POST
|
Hi, Xander Bakker So if you have two groups with the same amount of counts, it may return a different group. Sorry to drag you back into this. I haven't been able to get all the fields. Is the reason 10 fields are missing related to this? This returns 52 of the 62 groups of the finalgroups.csv. fld_kw = "USER_Keywo" # your input field
fld_res = "Keyword" # your output string field
#missing fields
Composting Facilities/Landscape Waste transfer Stations
Disposable Batteries
Latex Paint
Matress Recycling
Medical Equipment (durable)
Medication Drop-Off
Motor Oil - Bulk
Pallet Reuse or Recycling
Plastic Carrier Strap Recycling
Plastic Container Recycling
Reuse & Resale Shops
This returns only 16 fields fld_kw = "USER_Categ" # your input field
fld_res = "Keyword" # your output string field
... View more
06-29-2020
11:26 AM
|
0
|
3
|
1811
|
|
POST
|
Hi Robert, Thanks, that did a nice job of making the selections more readable: But, I was also wondering how I can get two drop-downs to display. There is this one, Category, and then I would also like to be able to select by Keyword (USER_Keywo field). Here's the feature layer view for reference: https://willcountygis.maps.arcgis.com/home/item.html?id=227061be60a14cc89946a978b440d227&view=table#data Would I have to duplicate all the query blocks of the script for the USER_Keywo field to do this?
... View more
06-25-2020
09:14 AM
|
0
|
1
|
2562
|
|
POST
|
Brilliant. Thank you very much. I'll have to dig deeper tomorrow to see if all the data is represented. I have 62 categories in the finalgroups.csv. And, like you said, there are only 52 here.
... View more
06-24-2020
02:23 PM
|
1
|
0
|
2530
|
|
POST
|
So you created a "Category" field and did a field calculation? I ran your code in the Expression Builder.
... View more
06-24-2020
02:00 PM
|
0
|
2
|
2530
|
|
POST
|
I want to create a webmap that is based off of this data-set, for example: Will County EEC Mobile Site I'm not familiar enough with querying to be able to recreate the querying. My data-set has multiple categories and multiple keywords. I geocoded the spreadsheet, so now I have a point for each field. Like the example, I would like to have a orderly drop down for the category field and the keyword field. Currently, I can query features by the category field, but as you can see it is very impractical being that there are too many choices. How can I create my dropdown to look like the above? My current code (taken from sample 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;
}
#infoDiv {
background-color: white;
color: black;
padding: 6px;
width: 400px;
}
#results {
font-weight: bolder;
padding-top: 10px;
}
.slider {
width: 100%;
height: 60px;
}
#drop-downs {
padding-bottom: 15px;
}
</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 wellTypeSelect = document.getElementById("category");
// oil and gas wells
var wellsLayer = new FeatureLayer({
portalItem: {
// autocasts as new PortalItem()
id: "f76b85e6c5314a0c96539d704fe92452"
},
outFields: ["*"],
visible: false
});
// GraphicsLayer for displaying results
var resultsLayer = new GraphicsLayer();
var map = new Map({
basemap: "dark-gray",
layers: [wellsLayer, resultsLayer]
});
var view = new MapView({
container: "viewDiv",
map: map,
center: [-87.95, 41.47],
zoom: 10
});
view.ui.add("infoDiv", "top-left");
// query all features from the wells layer
view
.when(function() {
return wellsLayer.when(function() {
var query = wellsLayer.createQuery();
return wellsLayer.queryFeatures(query);
});
})
.then(getValues)
.then(getUniqueValues)
.then(addToSelect)
// return an array of all the values in the
// STATUS2 field of the wells layer
function getValues(response) {
var features = response.features;
var values = features.map(function(feature) {
return feature.attributes.USER_Categ;
});
return values;
}
// return an array of unique values in
// the STATUS2 field of the wells layer
function getUniqueValues(values) {
var uniqueValues = [];
values.forEach(function(item, i) {
if (
(uniqueValues.length < 1 || uniqueValues.indexOf(item) === -1) &&
item !== ""
) {
uniqueValues.push(item);
}
});
return uniqueValues;
}
// Add the unique values to the wells type
// select element. This will allow the user
// to filter wells by type.
function addToSelect(values) {
values.sort();
values.forEach(function(value) {
var option = document.createElement("option");
option.text = value;
wellTypeSelect.add(option);
});
return setWellsDefinitionExpression(wellTypeSelect.value);
}
// set the definition expression on the wells
// layer to reflect the selection of the user
function setWellsDefinitionExpression(newValue) {
wellsLayer.definitionExpression = "USER_Categ = '" + newValue + "'";
if (!wellsLayer.visible) {
wellsLayer.visible = true;
}
return queryForWellGeometries();
}
// Get all the geometries of the wells layer
// the createQuery() method creates a query
// object that respects the definitionExpression
// of the layer
function queryForWellGeometries() {
var wellsQuery = wellsLayer.createQuery();
return wellsLayer.queryFeatures(wellsQuery).then(function(response) {
wellsGeometries = response.features.map(function(feature) {
return feature.geometry;
});
return wellsGeometries;
});
}
// set a new definitionExpression on the wells layer
wellTypeSelect.addEventListener("change", function() {
var type = event.target.value;
setWellsDefinitionExpression(type);
});
});</script>
</head>
<body>
<div id="viewDiv"></div>
<div id="infoDiv" class="esri-widget">
<div id="drop-downs">
Select Category:
<select id="category" class="esri-widget"></select>
</div>
<div id="results" class="esri-widget"></div>
</div>
</body>
</html>
... View more
06-24-2020
01:31 PM
|
0
|
3
|
2653
|
|
POST
|
I avoided mentioning my ultimate goal here because it's too broad for the problem at hand, but I guess I will anyway. The reason I need these in groups is because I'm ultimately creating an app from the data with two drop-downs that query by feature layer type-- one for category and one for keyword. Here's where I'm at: The original data has too many categories to be practical. This is the reason I want to condense the data into groups seen in the finalgroups.csv.
... View more
06-24-2020
08:42 AM
|
0
|
4
|
2530
|
|
POST
|
Xander Bakker, I wouldn't worry about those keywords. I must've left them out when re-doing the finalgroups.csv. I'll come back for those later. Thanks for the code! But, I'm a little confused as to what I'm supposed to use in the Expression Builder in Pro. Am I to use the whole thing or just certain bits?
... View more
06-24-2020
08:07 AM
|
0
|
5
|
6859
|
|
POST
|
Xander Bakker, So, the main question remains, what are the final groups and what rules do you want to apply to assign a value to a group? The final groups are in the zip folder: https://webapp.willcountyillinois.com/Requests/Recycle.zip I cleaned the two fields up from the feature layer and saved them in the new CSV (finalgroups.csv in zip folder). As for a rule, can the groups be created using the Keywords? After all that, I might as well create a whole new feature layer (this data was given to me-- the reason why it wasn't too organized for GIS). But, I would still like to know how to group these programmatically.
... View more
06-23-2020
02:13 PM
|
0
|
6
|
4068
|
| 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 |
Online
|
| Date Last Visited |
12 hours ago
|