Skip to content
Prev 21549 / 29559 Next

Error message when dissolving polygons

In your subsequent message, you claim that by setting LL to UTM, you 
resolve the problem. This is wrong, as I'll show below. You have not said 
what you mean by "dissolve" either, the help pages of both 
maptools::unionSpatialPolygons and equivalently rgeos::gUnaryUnion show 
exactly what to do, but I don't think that this is what you actually mean.
On Mon, 25 Aug 2014, frankma wrote:

            
The files at this source are:

"The shapefiles are available in the Irish Grid Reference System (TM65 / 
Irish Grid - EPSG Projection 29902)"

so are projected, but not UTM.
Neither of maptools nor gpclib are needed. The gpclib package should 
never, ever be used - use polyclip instead, or rgeos if your objects 
inherit sp classes.
Good!
Not needed.
Here you are setting the projection (coordinate reference system, CRS) to 
AEA when in all probability the input was as the data source says. All the 
proj4string= argument does is to insert the given CRS into the object; it 
says - I know that this is correct; it does not project, because that 
needs a from CRS and a to CRS.
The example in maptools uses readShapePoly() to avoid depending on rgdal, 
but only rgdal should be used in real work (rgdal reads the prj file in 
shapefiles to set the CRS directly); the maptools functions will probably 
be disabled shortly tooblige users to make the right choices:
OGR data source with driver: ESRI Shapefile
Source: ".", layer: "Census2011_Admin_Counties_generalised20m"
with 34 features and 20 fields
Feature type: wkbPolygon with 2 dimensions
[1] "+proj=tmerc +lat_0=53.5 +lon_0=-8 +k=1.000035 +x_0=200000 +y_0=250000 
+datum=ire65 +units=m +no_defs +ellps=mod_airy 
+towgs84=482.530,-130.596,564.557,-1.042,-0.214,-0.631,8.15"
rgeos version: 0.3-6, (SVN revision 450)
  GEOS runtime version: 3.4.2-CAPI-1.8.2 r3921
  Polygon checking: TRUE
gives the entity areas in square metres; note that the actual areas will 
depend on the degree of line generalisation.

With this file, which may not be the one you are using, you may also need 
to use the encoding="latin1" argument in readOGR() to get from D\xfan 
Laoghaire-Rathdown to D?n Laoghaire-Rathdown.
You've set the CRS to AEA on reading, so this is a no-op.
But you set the CRS to AEA, which is neither UTM not LL - this is simply 
wrong.
As I said before, the coordinates in the data object are already 
projected. By your setting the PolySet to UTM, you get some numbers out 
(effectively the same as by doing it properly, because PBSmapping then 
calculates planar areas in the metric of the coordinates, rather than 
projecting on the fly from LL to UTM and then grapping planar areas). But 
it is certainly not UTM.

Which leaves the muddle about what you mean by dissolving; I can guess 
that you need to define the longitude thresholds as polygons in the same 
projection as the polygons, intersect the two using
rgeos::gIntersection(..., byid=TRUE), take rgeos::gArea(..., byid=TRUE) of 
the output, and pick apart the row.names() of the output object to see how 
many square metres of each county belongs to each longitude threshold.

Hope this clarifies,

Roger