Spatial Mapping Question

Hi,

New to the forum. What is the best way to create spatial maps? Is python better or R? What is the typical code you use to make them?

Thanks

2 Likes

I find for base maps that R is great to use with the library(maps) function. You can take a look at some code used for generating an R map from these posts: Visualization: Geospatial & Other and Introduction to Analyzing Spatial Movement.
Python also offers nice images as well. Here is a quick example with some code if you’d like to try it:

import matplotlib.pyplot as plt
import numpy as np
from PIL import Image

# Load the saved image
img = Image.open("western_new_york_map.png")

# Convert the image to RGB mode
img_rgb = img.convert('RGB')

# Get image dimensions
width, height = img.size

# Generate random points
num_points = 10
x_coords = np.random.randint(0, width, num_points)
y_coords = np.random.randint(0, height, num_points)

# Create the plot
plt.figure(figsize=(12, 8))
plt.imshow(img_rgb)

# Plot the random points
plt.scatter(x_coords, y_coords, c='red', s=50)

# Add labels to the points
for i, (x, y) in enumerate(zip(x_coords, y_coords)):
    plt.annotate(f'Point {i+1}', (x, y), xytext=(5, 5), textcoords='offset points')

plt.title("Map of New York State with Random Points")
plt.axis('off')
plt.tight_layout()
plt.show()

print("Map with random points has been generated.")
2 Likes