2

I am working with shapefiles for UK police force boundaries published by the police, defined in WGS84. Some of the boundary shapefiles are invalid (due to self-intersections of the boundary). When I reproject the shapefiles to the British National Grid (OSGB 1936), they are valid.

I would like to understand why this is the case. Is this simply a case of the police using projected shapefiles and uploading WGS84 shapefiles without checking for validity? In other words, is this simply an artefact of reprojecting? Or does it indicate that the original projection definition of the shapefiles is not correct?

R code to reproduce this problem is below: The force boundaries can be downloaded here: https://data.police.uk/data/boundaries/force_kmls.zip

The invalid shapefiles are "derbyshire.kml" and "greater-manchester.kml".

library(rgeos)
library(rgdal)

# read in shapefile
derby <- readOGR("../force_kmls/derbyshire.kml")
# show object
summary(derby)
Object of class SpatialPolygonsDataFrame
Coordinates:
    min       max
x -2.034083 -1.166476
y 52.696521 53.540456
Is projected: FALSE 
proj4string :
[+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0]
Data attributes:
Name Description
:1   :1         

# check for validity of polygon
rgeos::gIsValid(derby)
[1] FALSE
Warning message:
In RGEOSUnaryPredFunc(spgeom, byid, "rgeos_isvalid") :
Self-intersection at or near point -1.31360199 53.164194000000002


# reproject derby
derby_proj <- spTransform(derby, CRS("+init=epsg:27700"))
summary(derby_proj)

Object of class SpatialPolygonsDataFrame
Coordinates:
   min      max
x 397829.5 455677.1
y 311055.2 404875.1
Is projected: TRUE 
proj4string :
[+init=epsg:27700 +proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +datum=OSGB36 +units=m +no_defs +ellps=airy +towgs84=446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894]
Data attributes:
Name Description
:1   :1         

# check for validity of polygon
rgeos::gIsValid(derby_proj)
[1] TRUE
  • 2
    KML files are not shapefiles – Ian Turton Dec 4 '17 at 17:30
  • If you zoom in on the error you can see its a tiny overshoot in a line. Its 10cm long - on the ground. – Spacedman Dec 5 '17 at 8:40
1

QGis feels that both the files are valid in either projection. So it may be a tolerance issue in R.

0

It would indicate that the geometry was originally created in OSGB 1936 and re-projected at some point to WGS84, probably during packaging for export/download.

  • Is it possible mathematically for two line segments that don't intersect in one projection to intersect in another projection? I can only see it happening for rather complex projections that distort in very non-linear ways, but there might be a simple example between lat-long and a transverse mercator.... – Spacedman Dec 5 '17 at 8:42
  • Yes. Think about a relatively long line that is defined by 2 points and is straight in CRS1. In CRS2, it shouldn't be straight. Because it doesn't have enough vertices to correctly display the feature, topology can be messed up. – mkennedy Dec 7 '17 at 4:25

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.