Skip to content

About

No description, website, or topics provided.

Resources

Contributing

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

ย 

History

48 Commits

Folders and files

Repository files navigation

Geospatial Patterns

A Python tool for analyzing spatial patterns and proximity relationships of geographic entities using OpenStreetMap data. This project helps identify clusters, proximity networks, and spatial distributions of points of interest (POIs) in any given area.

๐ŸŽฏ Features

  • Entity Extraction: Retrieve geographic entities from OpenStreetMap based on custom tags
  • Spatial Analysis: Analyze proximity relationships between entities using BallTree algorithm
  • Visualization: Generate pie charts and proximity network visualizations
  • Configurable Parameters: Customize search areas, entity types, walking distances, and more
  • Brand Distribution: Count and analyze brand/entity distributions in a given area

๐Ÿ“‹ Use Cases

  • Retail Analysis: Analyze convenience store distributions and competitive proximity
  • Urban Planning: Study spatial patterns of amenities, facilities, or services
  • Market Research: Identify clusters and gaps in service coverage
  • Accessibility Studies: Measure walking-distance relationships between locations

๐Ÿš€ Getting Started

Prerequisites

  • Python 3.8 or higher
  • pip package manager

Installation

  1. Clone the repository:
git clone https://github.com/MarlinZH/Geospatial_Patterns.git
cd Geospatial_Patterns
  1. Install required dependencies:
pip install -r requirements.txt

Quick Start

Run the example analysis:

python main.py

This will analyze convenience stores in Shinjuku, Tokyo and generate:

  • Entity count by brand
  • Pie chart visualization
  • Proximity network (stores within 2-minute walking distance)

๐Ÿ“– Usage

Basic Usage

from geospatial_analysis import GeospatialAnalyzer

# Initialize analyzer
analyzer = GeospatialAnalyzer(
    area="Shinjuku, Tokyo",
    tags={"shop": "convenience"},
    walking_radius_meters=168  # ~2 minute walk
)

# Get entity counts
counts = analyzer.get_entity_counts()

# Get proximity relationships
proximity = analyzer.analyze_proximity()

# Generate visualizations
analyzer.visualize_distribution()

Advanced Usage

Analyze Different Entity Types

# Analyze restaurants
analyzer = GeospatialAnalyzer(
    area="Manhattan, New York",
    tags={"amenity": "restaurant"}
)

# Analyze cafes
analyzer = GeospatialAnalyzer(
    area="Paris, France",
    tags={"amenity": "cafe"}
)

# Analyze pharmacies
analyzer = GeospatialAnalyzer(
    area="London, UK",
    tags={"amenity": "pharmacy"}
)

Custom Walking Distance

# 5-minute walking radius (~420 meters at average walking speed)
analyzer = GeospatialAnalyzer(
    area="Downtown Seattle",
    tags={"shop": "supermarket"},
    walking_radius_meters=420
)

Export Results

# Get entity list as DataFrame
entities_df = analyzer.get_entities_list()
entities_df.to_csv("entities.csv", index=False)

# Get proximity network
proximity_df = analyzer.analyze_proximity()
proximity_df.to_csv("proximity_network.csv", index=False)

๐Ÿ”ง Configuration

Parameters

Parameter Type Description Default
area str Location name (searchable on OSM) Required
tags dict OSM tag filters (e.g., {"shop": "convenience"}) Required
walking_radius_meters int/float Proximity radius in meters 168
output_verbose bool Print detailed outputs False
leaf_size int BallTree leaf size for optimization 15

Common OSM Tags

Shops:

  • {"shop": "convenience"} - Convenience stores
  • {"shop": "supermarket"} - Supermarkets
  • {"shop": "bakery"} - Bakeries
  • {"shop": "clothes"} - Clothing stores

Amenities:

  • {"amenity": "restaurant"} - Restaurants
  • {"amenity": "cafe"} - Cafes
  • {"amenity": "bank"} - Banks
  • {"amenity": "pharmacy"} - Pharmacies
  • {"amenity": "hospital"} - Hospitals

Transportation:

  • {"public_transport": "station"} - Transit stations
  • {"amenity": "parking"} - Parking facilities

For more tags, visit the OSM Tag Wiki.

๐Ÿ“Š Output Examples

Entity Count Output

Brand
7-Eleven        45
FamilyMart      38
Lawson          32
NewDays          5
Name: count, dtype: int64

Proximity Network Output

   indices
0  [FamilyMart, Lawson]
1  [7-Eleven, NewDays, FamilyMart]
2  [7-Eleven]
...

๐Ÿ—๏ธ Project Structure

Geospatial_Patterns/
โ”œโ”€โ”€ main.py                 # Main script with example usage
โ”œโ”€โ”€ geospatial_analysis.py  # Core analysis class
โ”œโ”€โ”€ example_configs.py      # Pre-configured examples
โ”œโ”€โ”€ requirements.txt        # Python dependencies
โ”œโ”€โ”€ README.md              # This file
โ”œโ”€โ”€ CONTRIBUTING.md        # Contribution guidelines
โ”œโ”€โ”€ LICENSE                # MIT License
โ”œโ”€โ”€ AI_ASSISTANT_PROMPT.md # AI assistant usage guide
โ”œโ”€โ”€ .gitignore             # Git ignore rules
โ””โ”€โ”€ cache/                 # OSM data cache (gitignored)

๐Ÿ› ๏ธ Technical Details

Algorithms

  • Geocoding: Uses OSMnx to convert location names to geographic boundaries
  • Spatial Queries: Retrieves entities using OpenStreetMap Overpass API
  • Proximity Search: Implements BallTree with Haversine metric for efficient nearest-neighbor search
  • Coordinate System: Uses WGS84 (EPSG:4326) for geographic coordinates

Walking Distance Calculation

The default walking radius of 168 meters represents approximately a 2-minute walk, assuming:

  • Average walking speed: 1.4 m/s (5 km/h)
  • Calculation: 1.4 m/s ร— 120 seconds = 168 meters

To customize: walking_radius_meters = speed_m_per_s ร— time_seconds

๐Ÿค– Working with AI Assistants

Need help with this project? Check out AI_ASSISTANT_PROMPT.md for ready-to-use prompts that give AI assistants the context they need to help you effectively.

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

See CONTRIBUTING.md for detailed guidelines.

Development Setup

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

๐Ÿ“ License

This project is open source and available under the MIT License.

๐Ÿ™ Acknowledgments

๐Ÿ“ง Contact

Project Link: https://github.com/MarlinZH/Geospatial_Patterns

๐Ÿ› Known Issues

  • Entity extraction relies on brand:en tag availability in OSM data
  • Large areas or dense urban regions may have slow query times
  • Requires internet connection for OSM data retrieval

๐Ÿ”ฎ Future Enhancements

  • Add interactive map visualizations with Folium
  • Support for batch processing multiple areas
  • Time-series analysis of entity changes
  • Heat map generation for entity density
  • CLI interface with argument parsing
  • Web API for programmatic access
  • Support for custom distance metrics
  • Export to GeoJSON format

Note: This tool uses OpenStreetMap data. Please review the OSM Copyright and License for data usage terms.

About

No description, website, or topics provided.

Resources

Contributing

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages