I have a multiPolygon shapefile of buildings in a particular city. I read it in with readOGR and and transform it to my desired planar projection with the following code:

buildings<- spTransform(buildings_data, CRS("+proj=utm +zone=45 +a=6377299.151
                                        +towgs84=295,736,257,0,0,0,0 +units=m +no_defs "))

It gives me the following output along with transforming:

There were 19 warnings (use warnings() to see them)

All the warnings are:

In Polygon(coords = crds) : less than 4 coordinates in polygon

So how do I remove these polygons with less than 4 coordinates?

  • 1
    Are you sure your data has clean geometries? This might be a repeated question Check this: gis.stackexchange.com/questions/261543/… – Ruben FV Jul 17 '19 at 11:37
  • 1
    While three points define a plane, four vertices define a polygon (the first must be repeated to close the shape). Therefore, geometries with fewer than four vertices can't be a polygon and are topologically corrupt. – Vince Jul 17 '19 at 11:51
  • @RubenFV what do you mean by clean geometries? Can you please explain a bit more? I am new to GIS. – Divyansh Jul 17 '19 at 11:53
  • @Vince yes I got to know that from other answer but can you tell me how do I remove those corrupt geometries? – Divyansh Jul 17 '19 at 11:54

Your code is correct. But you shapefile (buildings) seems to be corrupted and have some topology errors and geometry validity issues, just as here.

You need to inspect and correct your original building data. It is difficult to tell you where the problem lies without having access to it.

An option in R to further explore this is the cleangeo package.


buildings_data <- readOGR("buildings.shp")
buildings<- spTransform(buildings_data, CRS("+proj=utm +zone=45 +a=6377299.151 +b=6356098.145120132 +towgs84=295,736,257,0,0,0,0 +units=m +no_defs"))
clgeo_IsValid(buildings) # This tells you if the geometry is valid
clgeo_Clean(buildings, errors.only = NULL, strategy = "POLYGONATION",verbose = FALSE)
clgeo_IsValid(buildings) # check again...

Or you can also explore and clean the original dataset with QGIS, ArcGIS or similar and check topology and geometry issues.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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