|
|
|
"""TreesPlantingSitesDataset |
|
|
|
Automatically generated by Colaboratory. |
|
|
|
Original file is located at |
|
https://colab.research.google.com/drive/1Hvt3Y131OjTl7oGQGS55S_v7-aYu1Yj8 |
|
""" |
|
|
|
from datasets import DatasetBuilder, DownloadManager, DatasetInfo, SplitGenerator, Split |
|
from datasets.features import Features, Value, ClassLabel |
|
import pandas as pd |
|
import geopandas as gpd |
|
import matplotlib.pyplot as plt |
|
|
|
class TreesPlantingSitesDataset(DatasetBuilder): |
|
VERSION = "1.0.0" |
|
|
|
def _info(self): |
|
|
|
return DatasetInfo( |
|
description="This dataset contains information about tree planting sites from CSV and GeoJSON files.", |
|
features=Features({ |
|
"OBJECTID": Value("int32"), |
|
"streetaddress": Value("string"), |
|
"city": Value("string"), |
|
"zipcode": Value("int32"), |
|
"facilityid": Value("int32"), |
|
"neighborhood": Value("string"), |
|
"plantingwidth": Value("string"), |
|
"plantingcondition": Value("string"), |
|
"matureheight": Value("string"), |
|
"GlobalID": Value("string"), |
|
"created_user": Value("string"), |
|
"created_date": Value("string"), |
|
"last_edited_user": Value("string"), |
|
"last_edited_date": Value("string"), |
|
"geometry": Value("string") |
|
}), |
|
supervised_keys=None, |
|
homepage="https://github.com/AuraMa111?tab=repositories", |
|
citation="Citation for the dataset", |
|
) |
|
|
|
def _split_generators(self, dl_manager: DownloadManager): |
|
|
|
urls_to_download = { |
|
"csv": "https://drive.google.com/uc?export=download&id=18HmgMbtbntWsvAySoZr4nV1KNu-i7GCy", |
|
"geojson": "https://drive.google.com/uc?export=download&id=1jpFVanNGy7L5tVO-Z_nltbBXKvrcAoDo" |
|
} |
|
downloaded_files = dl_manager.download_and_extract(urls_to_download) |
|
|
|
return [ |
|
SplitGenerator(name=Split.TRAIN, gen_kwargs={ |
|
"csv_path": downloaded_files["csv"], |
|
"geojson_path": downloaded_files["geojson"] |
|
}), |
|
|
|
] |
|
|
|
def _generate_examples(self, csv_path, geojson_path): |
|
|
|
csv_data = pd.read_csv(csv_path) |
|
geojson_data = gpd.read_file(geojson_path) |
|
|
|
|
|
gdf = geojson_data.merge(csv_data, on='OBJECTID') |
|
columns_to_extract = [ |
|
"OBJECTID", "streetaddress", "city", "zipcode", "facilityid", "present", |
|
"neighborhood", "plantingwidth", "plantingcondition", "underpowerlines", |
|
"matureheight", "GlobalID", "created_user", "created_date", |
|
"last_edited_user", "last_edited_date", "geometry" |
|
] |
|
|
|
|
|
extracted_gdf = gdf[columns_to_extract] |
|
|
|
number_of_planting_sites = gdf['present'].value_counts() |
|
print("Number of planting sites:", number_of_planting_sites) |
|
|
|
|
|
neighborhood_analysis = gdf.groupby('neighborhood').size() |
|
print("Distribution by neighborhood:", neighborhood_analysis) |
|
|
|
|
|
gdf.plot(marker='*', color='green', markersize=5) |
|
plt.title('TreesPlantingSitesDataset') |
|
plt.show() |
|
|
|
|
|
for id_, row in extracted_gdf.iterrows(): |
|
yield id_, { |
|
"OBJECTID": row["OBJECTID"], |
|
"streetaddress": row["streetaddress"], |
|
"city": row["city"], |
|
"zipcode": row["zipcode"], |
|
"facilityid": row["facilityid"], |
|
"neighborhood": row["neighborhood"], |
|
"plantingwidth": row["plantingwidth"], |
|
"plantingcondition": row["plantingcondition"], |
|
"matureheight": row["matureheight"], |
|
"GlobalID": row["GlobalID"], |
|
"created_user": row["created_user"], |
|
"created_date": row["created_date"], |
|
"last_edited_user": row["last_edited_user"], |
|
"last_edited_date": row["last_edited_date"], |
|
"geometry": row["geometry"].wkt if row["geometry"] else None |
|
} |