Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8540337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:34:29+00:00 2026-06-11T11:34:29+00:00

I have a shapefile (showing different sediment classes in the northsea) read in with

  • 0

I have a shapefile (showing different sediment classes in the northsea) read in with readOGR(). It has a
lot of ” what should be” holes in many polygons, but using rasterize() does eliminate all the holes since they are not marked as TRUE in their hole-slots. Used rasterize(...,fun='first') with no success. Nevertheless, QGIS shows the holes all nicely. Also, over() correctly evaluates the field values, e.g., in a hole, probably taking advantage of the slot “plot order” which is why I came up with something like:

for (i in 1:ncell(raster)){
    coo<-xyFromCell(raster,i,spatial=T)
    col<-colFromX(ra,coo@coords[1,1])
    row<-rowFromY(ra,coo@coords[1,2])
    proj4string(coo)<-proj4string(shape)
    n<-over(coo,shape)
    raster[col,row]<-n$Prime_FOLK
}

to bypass rasterize, but it will take 50days to be done.

So here’ my question:

Has anyone experienced something similar and found a workaround for it?

(I would have liked include example data, but dput()fails on SpatialPolygons?!?)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T11:34:30+00:00Added an answer on June 11, 2026 at 11:34 am

    Yes. I have the same problem with not getting the holes to rasterize properly, because they are not specified correctly. For the shape files I’ve been using, the first polygon is always the main polygon and the second through the last are the holes. If this isn’t the case for you this may not work for your situation. Here is the code I wrote to change all the non-first polygons into holes=T:

    ## poly.dat is the SpatialPolygonsDataFrame
    
    fix.holes<-function(poly.dat){
      n.poly.all<-numeric()
      for (k in 1:nrow(poly.dat@data)){
        n.poly.all[k]<-length(poly.dat@polygons[[k]]@Polygons)
      }
      has.hole<-which(n.poly.all>1)
      n.poly<-n.poly.all[has.hole]
    
      for (k in 1:length(has.hole)){
        for (m in 2:n.poly[k]){
          poly.dat@polygons[[has.hole[k]]]@Polygons[[m]]@hole<-T
        }
      }
      return(poly.dat)
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a shapefile with regions with polygons, and can successfully use PlotOnStaticMap like
I have a shapefile with 50+ different polygonal shapes (representing 50+ different regions) and
I have a shapefile which is the national boundary line of Chile. If possible,
i have 3 shapefile ready in a map file, and rendering it on mapserver.
I have a huge shapefile of 36.000 non-overlapping polygones (city boundaries). I want to
I am trying to read a binary file and parse the bytes I have
I have a Shapefile map of Maryland separated by zipcode. What I'd like to
I have code that makes a shapefile but the number of fields is dependent
I have a Python dictionary that I generated from an arcgis shapefile. The dictionary
i have the following two tables:- GeoShapes GeoShapeId INT IDENTITY Name VARCHAR(100) ShapeFile GEOGRAPHY

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.