3

I have location data points for colonies (csv file). I have a shapefile that I need to duplicate and georeference to each colony. Is there a way to do this in r?

EDIT: I want to create a copy of the existing KUD shapefile for each colony location. I do not want to create a unique KUD for each colony.

Picture shows the shapefile (green) that I am trying to replicate for each colony and have the center of the shapefile georeferenced to on the colony. Arrows show the change I want to make in the location of the shapefile.

enter image description here

Picture shows the data table of the colonies. They are imported as a csv file and I need to create a copy of the shapefile for each colony data point located at the same lat/lon.

enter image description here

17
  • 1
    Welcome to GISse! Could you click "edit" and update your question with more details? What does KUD mean? What format are your data in (fields, etc)
    – Simbamangu
    Mar 7, 2019 at 1:03
  • 2
    Not sure what you mean by creating a KUD for each data point - a KUD is created from multiple points? Do you need a KUD for each tag in the CSV (i.e. from multiple points associated with a given ID)?
    – Simbamangu
    Mar 7, 2019 at 6:38
  • 1
    Are you planning to generate a unique KUD for each colony location? Or do you want to create a copy of the existing KUD shapefile for each colony location? The second option should be simple to implement, but it doesn't sound correct. Wouldn't the kernal utilization density be unique for each colony? Please edit your question to clarify.
    – csk
    Mar 7, 2019 at 16:58
  • 1
    So you want to create some identical copies of this KUD shapefile? That's the only sense I can make of your question at this point. What's the KUD shapefile called? Where do you want the copies put?
    – Spacedman
    Mar 7, 2019 at 20:50
  • 1
    That doesnt make sense. Shapefiles aren't "centred" around anything, they store the geometry of a set of features. Do you really mean you are trying to draw maps centred at each point? Or you want to create a new set of shapefiles that are cropped from your KUD shapefile? If so, how far round each of the points do you want it?
    – Spacedman
    Mar 7, 2019 at 21:07

1 Answer 1

1

The geometry of spatial objects in the sf (simple features) package can be treated like matrices - and thus added / subtracted easily, and it's noted in the comments that you can treat this as a simple XY translation.

Create a basic polygon:

kud <- st_as_sf(data.frame(name = "poly1", 
   wkt = "Polygon ((1 1, 1 2, 2 2, 2 1, 1 1))"), 
   wkt = "wkt", crs = 4326)

Find the centroid

kud.cent <- st_centroid(kud)

Create a copy of the polygon then subtract the centroid's coords from the polygon's to get a polygon centred around 0,0

kud.0 <- kud
kud.0$wkt <- kud.0$wkt - kud.cent$wkt

To centre the polygon on a new point, just add that point to the '0' polygon:

pt1 <- st_as_sf(data.frame(name = "colony1", wkt = "POINT(3 1)"), wkt = "wkt", crs = 4326)
kud.1 <- kud.0
kud.1$name <- pt1$name # assign the name to the new poly
kud.1$wkt <- kud.1$wkt + pt1$wkt

For your CSV file, you could probably use:

colony <- read.csv("yourfile")
colony <- st_as_sf(colony, coords = c("Lon", "Lat"))
kud.1 <- kud.0
kud.1$wkt <- kud.1$wkt - colony$wkt[1]

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.