How ravi-rayv/urban-land-use-analysis works
Purpose and execution model
A Python 3.8+ batch pipeline that gathers location/keyword-targeted Twitter/X posts, writes tabular output, then converts the collected social signals into geospatial visualizations for urban land-use interpretation. It is script-driven rather than a service:
• Collection entry point: src/tweet_collector.py
• Visualization entry point: src/geo_visualizer.py
Configuration boundary
Repository-root settings separate environment-specific inputs from processing logic:
• config.py supplies Twitter credentials, shapefile location, and output CSV path.
• constants.py defines geographic search radii and keyword vocabulary.
These are the primary controls for query scope, authentication, and local input/output locations.
Tweet collection stage
src/tweet_collector.py is the upstream acquisition component. It combines configured locations and keywords into Twitter/X API searches, supports multiple authentication approaches (Bearer token, X-API-Key, direct token fallback), and processes results in batches to limit memory use. Its durable handoff is a CSV containing query metadata, date, author, text, engagement counts, URL, and errors.
• Sources: src/tweet_collector.py, config.py, constants.py
• External dependency: Twitter/X API and its token/rate-limit behavior.
Tabular data handoff
The CSV is the architectural boundary between remote collection and local spatial analysis. Collector output is configured through config.py; the visualizer consumes that data independently, enabling visualization reruns without API access.
• Paths: src/tweet_collector.py, src/geo_visualizer.py, config.py
Geospatial processing and map generation
src/geo_visualizer.py loads collected tweet records, extracts/uses geographic positions and engagement-related measures, and produces map artifacts. It supports density, interpolation, aggregation, territory, clustering, temporal, sentiment, keyword, and composite views, including KDE, contours, hexbin, raster, Voronoi, IDW, and hotspot representations.
• Core path: src/geo_visualizer.py
• Output boundary: PNG maps under the configured output area.
Geographic reference boundary
A city boundary shapefile is an optional local geospatial dependency. When supplied, it is overlaid on generated maps; when absent, visualization uses the tweet-data extent. This keeps analysis runnable with only collected data while allowing authoritative municipal/context boundaries.
• Configuration: config.py
• Consumer: src/geo_visualizer.py
Shared support and runtime
src/utils.py holds cross-cutting utilities used by pipeline scripts. The runtime is local Python with dependencies installed from requirements.txt; material libraries are expected to cover HTTP/API access, tabular processing, GIS/shapefile handling, numerical spatial analysis, and plotting.
• Paths: src/utils.py, requirements.txt, src/__init__.py
Main entry points: tweet_collector.py Tweet Collector · geo_visualizer.py Geo Visualizer · config.py Settings · requirements.txt Dependencies
Components 12
Configuration & Runtime
- Settings · Credentials and local input/output locations.
config.py - Search Constants · Geographic radii and keyword vocabulary.
constants.py - Dependencies · Local runtime libraries for API, data, GIS, and plotting.
requirements.txt - Shared Utilities
src/utils.py - Source Package
src/__init__.py
Tweet Collection
- Tweet Collector · Builds and executes location/keyword Twitter searches in batches.
src/tweet_collector.py - Twitter/X API · Remote post source with token and rate-limit behavior.
Geospatial Analysis
- Geo Visualizer · Generates spatial and thematic map views from collected records.
src/geo_visualizer.py - Spatial Analysis · Applies density, interpolation, aggregation, clustering, temporal, sentiment, and keyword methods.
src/geo_visualizer.py - City Boundary Shapefile · Optional reference overlay; tweet extent is used when absent.
- PNG Map Artifacts · Generated maps in the configured output area.
Other components
- Collected Tweets CSV · Posts, query metadata, engagement, URLs, and errors.
Connections 15
- Dependencies → Tweet Collector: provides runtime libraries
- Dependencies → Geo Visualizer: provides runtime libraries
- Settings → Tweet Collector: credentials and CSV location
- Search Constants → Tweet Collector: locations, radii, keywords
- Shared Utilities → Tweet Collector: shared support
- Shared Utilities → Geo Visualizer: shared support
- Tweet Collector → Twitter/X API: authenticated searches
- Twitter/X API → Tweet Collector: posts and API limits
- Tweet Collector → Collected Tweets CSV: writes batch results
- Settings → Collected Tweets CSV: configures output path
- Collected Tweets CSV → Geo Visualizer: independent local input
- Settings → Geo Visualizer: shapefile and output locations
- Geo Visualizer → Spatial Analysis: loads records and derives measures
- City Boundary Shapefile → Spatial Analysis: optional boundary overlay
- Spatial Analysis → PNG Map Artifacts: renders map views