0

My goal is using the over() function in sp to determine which in which polygon a point exists. I have this error ( Error: unexpected '>' in ">" ) on using:

over(ptsUTM, hex_grid)

where class( ptsUTM ) = "SpatialPoints" and class( hex_grid ) = "SpatialPolygons". Both have the same @proj4string =

CRS arguments: +proj=utm +zone=14 +datum=WGS84 +units=km +no_defs +ellps=WGS84

The ptsUTM variable was created following the material in rDGAL, Tiff Files, and WorldFile, with these additions:

rr2[rr2<minDbzValue]  <- NA
pol <- rasterToPolygons(rr2, fun=function(x){ x >= minDbzValue } )
pol2                = spTransform( pol, "+proj=utm +zone=14 +datum=WGS84 +units=km" )
ptsUTM              = SpatialPoints( pol2 )
ptsUTM              = hex_grid@proj4string

and hex_grid was created following the material at Fishnets and Honeycomb: Square vs. Hexagonal Spatial Grids

Community
  • 1
  • 1
Benjamin Levy
  • 333
  • 6
  • 19
  • Hi, can you clarify what the last two instructions are supposed to do ? ( `ptsUTM = SpatialPoints( pol2 )` and `ptsUTM = hex_grid@proj4string`) Seems that first you are trying to transform polygons to points, and then you overwrite the result with a proj4string. In particular the last instruction seems to replace ptsUTM with a character string: therefore `over` can not work (unless I'm missing something) – lbusett Feb 21 '17 at 23:21
  • Sure. It's hard without providing all the code: rr2 is a raster object ;rasterToPolygons turns rr2 into a SpatialPolygonsDataFrame object, pol. Then, spTransform adds the the CRS projection information to make pol2 (interim). I used SpatialPoints to transform pol2 to a SpatialPoints object (ptsUTM) and add the projection information with the same CRS projection as hex_grid (is an object of SpatialPolygons). – Benjamin Levy Feb 22 '17 at 00:17
  • 1
    Ok, but my issue is that if you execute `ptsUTM = hex_grid@proj4string` as it's written, it seems to me that you are overwriting the variable, not assigning the crs to it. Did you check the class of `ptsUTM` before the call to `over` – lbusett Feb 22 '17 at 11:28
  • Mi scuzi, Lorenzo. My mistake. I became overwhelmed by information. Thanks. – Benjamin Levy Feb 22 '17 at 14:15
  • No worries. Glad it helped. – lbusett Feb 22 '17 at 18:36

0 Answers0