CODE: Where are these Taxi Drivers bringing their passengers to in New York?
- danielwu779
- Oct 6, 2024
- 3 min read
Taxi drivers have mastered every twist and turn of a NYC alleyway. However, I wanted to know where these Taxi Drivers are bringing their passengers.
On the NYC Open Data site, there are several datasets. These are named "Green Taxi, Yellow Taxi, and FHV" datasets. On each of these datasets there are two variables named "PUlocationid" and "DOlocationid". These are listed from 1-256 (for example, #1 is Newark Airport).
We can actually infer where these taxi drivers are bringing their customers by tabulating
the "nature" of a certain location. By "nature," I mean: is this location a "commercial" zone? Or is it a "residential" zone? Or a "manufacturing" zone
To do this, we first need to download the GeoSpatial taxi data from the NYC Taxi Zone Open Data source. The website is as follows: https://data.cityofnewyork.us/Transportation/NYC-Taxi-Zones/d3c5-ddgc
(I downloaded it as a Shapefile, as I am using the Google Earth Engine)
Next, we need to download the "Zoning-Classifications" data from the New York City data portal. I used the "NYC GIS Zoning Features" feature on the "BYTES OF BIG APPLE" NYC Open Data website. https://www.nyc.gov/site/planning/data-maps/open-data.page
(I downloaded this through the direct download, which gave me a Shapefile and other relevant files) Then, I imported them both into the Google Earth Engine. This is relatively simple to do. After that, I had to recreate each zoning color on the Google Earth Engine. I made red a commercial zone, blue a manufacturing zone, and green a residential zone. This is the code (the projects name must be your own project name)
// Load the zoningzones dataset from the correct path
var zoningzones = ee.FeatureCollection("projects/YOURNAME/assets/NAMEOFASSETFILE");
// Filter by ZONEDIST (assuming 'ZONEDIST' is the column name)
// Commercial zones (start with "C")
var commercialZones = zoningzones.filter(ee.Filter.stringStartsWith('ZONEDIST', 'C'));
// Manufacturing zones (start with "M")
var manufacturingZones = zoningzones.filter(ee.Filter.stringStartsWith('ZONEDIST', 'M'));
// Residential zones (start with "R")
var residentialZones = zoningzones.filter(ee.Filter.stringStartsWith('ZONEDIST', 'R'));
// Add each zone type with a different color
Map.addLayer(commercialZones, {color: 'red'}, 'Commercial Zones'); // Red for commercial
Map.addLayer(manufacturingZones, {color: 'blue'}, 'Manufacturing Zones'); // Blue for manufacturing
Map.addLayer(residentialZones, {color: 'green'}, 'Residential Zones'); // Green for residential
// Center the map on New York City
Map.setCenter(-74.006, 40.7128, 10);
Next, we must also load in the "Taxi Map Data." We must overlay the "Taxi Map Data" on top of the "Zone Color Data." The code to do this is as follow:
// Load the zoningzones and taxizones datasets
var zoningzones = ee.FeatureCollection("projects/YOURNAME/assets/FILENAME");
var taxizones = ee.FeatureCollection("projects/YOURNAME/assets/FILENAME");
// Filter by ZONEDIST (assuming 'ZONEDIST' is the column name)
// Commercial zones (start with "C")
var commercialZones = zoningzones.filter(ee.Filter.stringStartsWith('ZONEDIST', 'C'));
// Manufacturing zones (start with "M")
var manufacturingZones = zoningzones.filter(ee.Filter.stringStartsWith('ZONEDIST', 'M'));
// Residential zones (start with "R")
var residentialZones = zoningzones.filter(ee.Filter.stringStartsWith('ZONEDIST', 'R'));
// Add each zone type with a different color
Map.addLayer(commercialZones, {color: 'red'}, 'Commercial Zones'); // Red for commercial
Map.addLayer(manufacturingZones, {color: 'blue'}, 'Manufacturing Zones'); // Blue for manufacturing
Map.addLayer(residentialZones, {color: 'green'}, 'Residential Zones'); // Green for residential
// Add the taxi zones with transparent fill and yellow borders
Map.addLayer(taxizones, {color: 'yellow', fillColor: '00000000', width: 2}, 'Taxi Zones');
// Center the map on New York City
Map.setCenter(-74.006, 40.7128, 10);
Great! Now we start the calculations.
In my project, since I am only interested if the zone is a residential zone or not, I will treat the manufacturing areas and commercial areas as one entity. Therefore, I will need to calculate the percentage of the area of each Taxi zone which is comprised of residential zone. The code to do that is:
// Load the zoningzones and taxizones datasets from the correct paths
var zoningzones = ee.FeatureCollection("projects/ee-YOURNAME/assets/YOURFILE");
var taxizones = ee.FeatureCollection("projects/ee-YOURNAME/assets/YOURFILE"); // Correct path
// Filter residential zones (start with "R")
var residentialZones = zoningzones.filter(ee.Filter.stringStartsWith('ZONEDIST', 'R'));
// Function to calculate the percentage of residential area in each taxi zone
var residentialPercentage = taxizones.map(function(taxiZone) {
// Calculate the total area of the taxi zone
var totalArea = taxiZone.geometry().area(); // in square meters
// Calculate the residential area within the taxi zone
var residentialInZone = residentialZones.filterBounds(taxiZone.geometry());
var residentialClipped = residentialInZone.geometry().intersection(taxiZone.geometry(), ee.ErrorMargin(1));
var residentialArea = residentialClipped.area(); // in square meters
// Calculate the percentage of the taxi zone that is residential
var percentage = residentialArea.divide(totalArea).multiply(100); // Percentage of residential area
// Return the taxi zone with the percentage as a new property
return taxiZone.set('residential_percentage', percentage);
});
// Print the result to see the residential percentage for each taxi zone
print(residentialPercentage);
And there you have it! Please shoot me a message if you want the results.
Comments