NYRegionIdentifier/README.md

4.9 KiB

Project Name: RegionIdentifier Git Repository: https://git.nickhepler.cloud/nick/RegionIdentifier.git

RegionIdentifier

Overview

The RegionIdentifier project is a Python function that helps identify an economic region based on the county name provided as input. It is particularly useful in geospatial analyses where counties are used to categorize regions within a specific area, like New York State. The function takes the name of a county and returns the corresponding economic region based on a predefined list of counties associated with each region.

This project is designed for use with ArcGIS Pro, where it can be incorporated into field calculations for geographic information systems (GIS) tasks. The function uses a dictionary to map counties to their respective regions, and based on the county input, it identifies the region the county belongs to.


Function: get_region_by_county

The function get_region_by_county(county_name) takes a string representing the name of a county and returns the corresponding economic region. The function performs case-insensitive comparisons to ensure robustness against different input formats.

Arguments:

  • county_name (str): The name of the county to be checked.

Returns:

  • A string representing the region name, such as "Western New York" or "Capital District".
  • If the county does not belong to any predefined region, the function returns "County not found in any region."

Example Usage

# Example usage of the get_region_by_county function

county = "Monroe"
region = get_region_by_county(county)
print(f"The county {county} belongs to the {region} region.")

Output:

The county Monroe belongs to the Finger Lakes region.

Regions and Counties Mapping

The following regions and their corresponding counties are predefined in the function:

  • 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: 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, Bronx, Queens, Kings, Richmond
  • Long Island: Nassau, Suffolk

How to Calculate a Field in ArcGIS Pro Using Python

To use the get_region_by_county function for calculating a field in ArcGIS Pro, follow these steps:

Step 1: Prepare Your Data

Make sure your dataset contains a field with county names. For this example, we'll assume there is a field called County_Name that contains the county name for each feature.

Step 2: Open the Field Calculator

  1. In ArcGIS Pro, open your project and the relevant map or scene.
  2. Right-click the layer that contains the data you want to update.
  3. Click on Attribute Table to view the features.
  4. Right-click the header of the field where you want to store the region names (e.g., Region).
  5. Select Field Calculator to open the calculation dialog.

Step 3: Enter the Python Expression

In the Field Calculator dialog, do the following:

  1. Ensure that the Parser is set to Python.

  2. In the Expression box, type the following code:

    get_region_by_county(!County_Name!)
    
    • The exclamation marks (!County_Name!) reference the County_Name field in your dataset.
    • The function get_region_by_county will be applied to each row to calculate the corresponding region.

Step 4: Implement the Python Code

To ensure the function is available in the field calculator, follow these steps:

  1. In the Field Calculator, click the Show Code Block checkbox.
  2. In the Pre-Logic Script Code box, paste the function definition for get_region_by_county:

Step 5: Apply the Calculation

  • Click OK in the Field Calculator to run the function. The Region field will be populated with the corresponding region for each feature based on the County_Name field.

Installation

  1. Clone this repository to your local machine:

    git clone https://git.nickhepler.cloud/nick/RegionIdentifier.git
    
  2. Ensure that Python is installed on your system (Python 3.x recommended).

  3. The function get_region_by_county does not have external dependencies but is designed to be used within ArcGIS Pro's Python environment for field calculations.


License

This project is licensed under the GPL License - see the LICENSE file for details.