Saturday, May 17, 2025
News PouroverAI
Visit PourOver.AI
No Result
View All Result
  • Home
  • AI Tech
  • Business
  • Blockchain
  • Data Science & ML
  • Cloud & Programming
  • Automation
  • Front-Tech
  • Marketing
  • Home
  • AI Tech
  • Business
  • Blockchain
  • Data Science & ML
  • Cloud & Programming
  • Automation
  • Front-Tech
  • Marketing
News PouroverAI
No Result
View All Result

Plotting Golf Courses in R with Google Earth | by Adam Beaudet | May, 2024

May 6, 2024
in AI Technology
Reading Time: 4 mins read
0 0
A A
0
Share on FacebookShare on Twitter


After completing the mapping of our hole or course, the next step is to export all the hard work into a KML file. To do this, simply click on the three vertical dots on the left side of the screen where your project is located. This project works best with geoJSON data, which can be easily converted from the KML file in the following steps. Now, it’s time to move to R.

To prepare for plotting, we will need the following packages: sf (for working with geospatial data), tidyverse (for data cleaning and plotting), stringr (for string matching), and geojsonsf (for converting from KML to geoJSON). The first step is to read the KML file using the st_read() function from sf.

# load libraries
library(sf)
library(tidyverse)
library(stringr)
library(geojsonsf)

kml_df <- st_read(“/Users/adambeaudet/Downloads/erin_hills.kml”)

Excellent! By now, we should have our golf course KML data in R. The data frame should consist of 2 columns: Name (project name, or course name in this case), and geometry (a list of all individual points forming the polygons we traced). As mentioned earlier, let’s convert our KML data to geoJSON and extract the course name and hole numbers.

# convert from KML to geoJSON
geojson_df <- st_as_sf(kml_df, “POLYGON”)

# extracting course name and hole number from polygon name# assuming “course_hole_element” naming convention is used for polygonsgeojson_df$course_name <- str_match(geojson_df$Name, “^(.+)_hole”)[,2] geojson_df$hole_num <- gsub(“.*_hole_(\\\\d+)_.*”, “\\\\1”, geojson_df$Name)

To ensure our maps point due north, we need to project them in a way that preserves direction. This can be achieved using the st_transform() function.

# define a CRS for so map always points due north
crs <- “+proj=lcc +lat_1=33 +lat_2=45 +lat_0=39 +lon_0=-96 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs”

# transform data to CRSgeojson_df <- st_transform(geojson_df, crs)

We’re almost ready to plot, but first, we need to specify how each polygon should be colored in ggplot2. Below is the color palette used in my project, but feel free to customize it.

Additionally, we can calculate the centroids of our polygons with the st_centroid() function in this step to overlay the hole number on each green.

Image by the author

geojson_df <- geojson_df %>%mutate(color = case_when(grepl(“_tee$”, Name) ~ “#57B740”,grepl(“_bunker$”, Name) ~ “#EDE6D3”,grepl(“_water$”, Name) ~ “#2243b6”,grepl(“_fairway$”, Name) ~ “#57B740”,grepl(“_green$”, Name) ~ “#86D14A”,grepl(“_hazard$”, Name) ~ “#094d1d”)) %>%mutate(centroid = st_centroid(geometry))

We are now ready to plot. We can utilize geom_sf(), geom_text(), and even geom_point() for more advanced plotting options. Typically, I remove gridlines, axis labels, and the legend for a cleaner appearance.

ggplot() +geom_sf(data = geojson_df, aes(fill = color), color = “black”) +geom_text(data = filter(geojson_df, grepl(“_green”, Name)),aes(x = st_coordinates(centroid)[, 1],y = st_coordinates(centroid)[, 2],label = hole_num),size = 3, color = “black”, fontface = “bold”, hjust = 0.5, vjust = 0.5) +scale_fill_identity() +theme_minimal() +theme(axis.title.x = element_blank(),axis.title.y = element_blank(),axis.text.x = element_blank(),axis.text.y = element_blank(),plot.title = element_text(size = 16),panel.grid.major = element_blank(),panel.grid.minor = element_blank()) +theme(legend.position = “none”) +labs(title = ‘Erin Hills | Hartford, WI’)

And there you have it — a golf course plotted in R, what a concept!

To view other courses I have plotted at the time of writing this article, you can visit my Shiny app: https://abodesy14.shinyapps.io/golfMapsR/

If you followed along, had fun, or are intrigued, feel free to try mapping your favorite courses and create a Pull Request for the golfMapsR repository that I maintain: https://github.com/abodesy14/golfMapsR With some combined effort, we can create a nice little database of plottable golf courses around the world!



Source link

Tags: AdamBeaudetCoursesEarthGolfGooglePlotting
Previous Post

Gen AI Helps Developers Automate Writing Coding

Next Post

Build Scalable Data Pipelines: Proven Best Practices for Snowflake

Related Posts

How insurance companies can use synthetic data to fight bias
AI Technology

How insurance companies can use synthetic data to fight bias

June 10, 2024
From Low-Level to High-Level Tasks: Scaling Fine-Tuning with the ANDROIDCONTROL Dataset
AI Technology

From Low-Level to High-Level Tasks: Scaling Fine-Tuning with the ANDROIDCONTROL Dataset

June 10, 2024
Decoding Decoder-Only Transformers: Insights from Google DeepMind’s Paper
AI Technology

Decoding Decoder-Only Transformers: Insights from Google DeepMind’s Paper

June 9, 2024
How Game Theory Can Make AI More Reliable
AI Technology

How Game Theory Can Make AI More Reliable

June 9, 2024
Buffer of Thoughts (BoT): A Novel Thought-Augmented Reasoning AI Approach for Enhancing Accuracy, Efficiency, and Robustness of LLMs
AI Technology

Buffer of Thoughts (BoT): A Novel Thought-Augmented Reasoning AI Approach for Enhancing Accuracy, Efficiency, and Robustness of LLMs

June 9, 2024
Deciphering Doubt: Navigating Uncertainty in LLM Responses
AI Technology

Deciphering Doubt: Navigating Uncertainty in LLM Responses

June 9, 2024
Next Post
Build Scalable Data Pipelines: Proven Best Practices for Snowflake

Build Scalable Data Pipelines: Proven Best Practices for Snowflake

Warren Buffett Gets a Discount on This Outstanding Value Stock. Here’s How You Can Too.

Warren Buffett Gets a Discount on This Outstanding Value Stock. Here's How You Can Too.

Hotel SEO Strategy – A Comprehensive Guide

Hotel SEO Strategy – A Comprehensive Guide

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • Trending
  • Comments
  • Latest
Is C.AI Down? Here Is What To Do Now

Is C.AI Down? Here Is What To Do Now

January 10, 2024
Porfo: Revolutionizing the Crypto Wallet Landscape

Porfo: Revolutionizing the Crypto Wallet Landscape

October 9, 2023
23 Plagiarism Facts and Statistics to Analyze Latest Trends

23 Plagiarism Facts and Statistics to Analyze Latest Trends

June 4, 2024
A Complete Guide to BERT with Code | by Bradney Smith | May, 2024

A Complete Guide to BERT with Code | by Bradney Smith | May, 2024

May 19, 2024
Part 1: ABAP RESTful Application Programming Model (RAP) – Introduction

Part 1: ABAP RESTful Application Programming Model (RAP) – Introduction

November 20, 2023
Saginaw HMI Enclosures and Suspension Arm Systems from AutomationDirect – Library.Automationdirect.com

Saginaw HMI Enclosures and Suspension Arm Systems from AutomationDirect – Library.Automationdirect.com

December 6, 2023
Can You Guess What Percentage Of Their Wealth The Rich Keep In Cash?

Can You Guess What Percentage Of Their Wealth The Rich Keep In Cash?

June 10, 2024
AI Compared: Which Assistant Is the Best?

AI Compared: Which Assistant Is the Best?

June 10, 2024
How insurance companies can use synthetic data to fight bias

How insurance companies can use synthetic data to fight bias

June 10, 2024
5 SLA metrics you should be monitoring

5 SLA metrics you should be monitoring

June 10, 2024
From Low-Level to High-Level Tasks: Scaling Fine-Tuning with the ANDROIDCONTROL Dataset

From Low-Level to High-Level Tasks: Scaling Fine-Tuning with the ANDROIDCONTROL Dataset

June 10, 2024
UGRO Capital: Targeting to hit milestone of Rs 20,000 cr loan book in 8-10 quarters: Shachindra Nath

UGRO Capital: Targeting to hit milestone of Rs 20,000 cr loan book in 8-10 quarters: Shachindra Nath

June 10, 2024
Facebook Twitter LinkedIn Pinterest RSS
News PouroverAI

The latest news and updates about the AI Technology and Latest Tech Updates around the world... PouroverAI keeps you in the loop.

CATEGORIES

  • AI Technology
  • Automation
  • Blockchain
  • Business
  • Cloud & Programming
  • Data Science & ML
  • Digital Marketing
  • Front-Tech
  • Uncategorized

SITEMAP

  • Disclaimer
  • Privacy Policy
  • DMCA
  • Cookie Privacy Policy
  • Terms and Conditions
  • Contact us

Copyright © 2023 PouroverAI News.
PouroverAI News

No Result
View All Result
  • Home
  • AI Tech
  • Business
  • Blockchain
  • Data Science & ML
  • Cloud & Programming
  • Automation
  • Front-Tech
  • Marketing

Copyright © 2023 PouroverAI News.
PouroverAI News

Welcome Back!

Login to your account below

Forgotten Password? Sign Up

Create New Account!

Fill the forms bellow to register

All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In