0

I am trying to create a ppp object from a sf object in R.

I am using the population-weighted centroids in Minnesota from 2020 census data. You can find the data here: https://www2.census.gov/geo/docs/reference/cenpop2020/blkgrp/CenPop2020_Mean_BG27.txt

library(spatstat)
library(sp)
library(sf)
library(maptools)
library(dplyr)

# pathing
setwd("My folder location")

# read data
centroids <- read.csv("./block_group_weighted_centroids.txt")

# convert to sf object
sf_df <- centroids %>%
  as.data.frame() %>%
  select(LONGITUDE, LATITUDE) %>% 
  st_as_sf(coords=c("LONGITUDE","LATITUDE"), crs=4326) %>%
  as_Spatial()

# create a ppp
sf_ppp <- as.ppp(sf_df) # This line results in an error

The error message: Error in as.ppp.SpatialPointsDataFrame(sf_df) : Only projected coordinates may be converted to spatstat class objects

How can I make sure I am using the planar projected coordinates?

1 Answer 1

0

You need to transform your points from lat-long degrees to a planar projected coordinate system appropriate for your data region.

For Minnesota I imagine there's some sort of state-designated coordinate system, or you can use the UTM zone appropriate for Minnesota's longitude.

The sf function st_transform will do this once you've got your lat-long data.

Note you don't need as_Spatial since spatstat will convert sf objects to ppp objects. You probably don't need as.data.frame either, since read.csv will return a data frame.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.