From 40697118309c25990560aa057ba94dd8d8415475 Mon Sep 17 00:00:00 2001 From: Nick Heppler Date: Wed, 11 Dec 2024 15:23:29 -0500 Subject: [PATCH] Add How to Calculate a Field in ArcGIS Pro Using Python. --- region_identifier.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 region_identifier.py diff --git a/region_identifier.py b/region_identifier.py new file mode 100644 index 0000000..0b77196 --- /dev/null +++ b/region_identifier.py @@ -0,0 +1,26 @@ +def get_region_by_county(county_name): + # Define the dictionary of regions and their associated counties/boroughs + regions = { + "Western New York": ["Niagara", "Erie", "Chautauqua", "Cattaraugus"], + "Finger Lakes": ["Orleans", "Genesee", "Wyoming", "Monroe", "Livingston", "Wayne", "Ontario", "Yates", "Seneca"], + "Southern Tier": ["Steuben", "Schuyler", "Chemung", "Tompkins", "Tioga", "Chenango", "Broome", "Delaware"], + "Central New York": ["Cortland", "Cayuga", "Onondaga", "Oswego", "Madison"], + "North Country": ["Saint Lawrence", "St Lawrence", "St. Lawrence", "Lewis", "Jefferson", "Hamilton", "Essex", "Clinton", "Franklin"], + "Mohawk Valley": ["Oneida", "Herkimer", "Fulton", "Montgomery", "Otsego", "Schoharie"], + "Capital District": ["Albany", "Columbia", "Greene", "Warren", "Washington", "Saratoga", "Schenectady", "Rensselaer"], + "Hudson Valley": ["Sullivan", "Ulster", "Dutchess", "Orange", "Putnam", "Rockland", "Westchester"], + "New York City": ["New York", "Manhattan", "Bronx", "Queens", "Kings", "Brooklyn", "Richmond", "Staten Island"], + "Long Island": ["Nassau", "Suffolk"] + } + + # Trim any leading/trailing whitespace and convert to lowercase + county_name = county_name.strip().lower() + + # Loop through the regions and check if the county is in any region's list + for region, counties in regions.items(): + # Compare the county_name in lowercase with each county (also in lowercase) + if county_name in [county.lower() for county in counties]: + return region + + # Return a message if the county is not found + return "Error" \ No newline at end of file