Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Make a map of all the geodata in Auckland's recommended Unitary Plan
# Fun with Unitary Plan data -- all the things!
# Setup
rm(list = ls())
library(maptools)
crs_nztm = CRS("+proj=tmerc +lat_0=0 +lon_0=173 +k=0.9996 +x_0=1600000 +y_0=10000000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs")
# Map config
line_width = 1
point_size = 0.25
line_colour = rgb(0, 0, 0, alpha = 1)
fill_colour = rgb(0, 0, 0, alpha = 0)
akl_bbox = matrix(c(1705000, 1828000, 5873000, 6010000),
nrow = 2,
ncol = 2,
dimnames = list(c("x", "y"), c("min", "max")),
byrow = TRUE)
central_bbox = matrix(c(1744413, 1775331, 5900750, 5933401),
nrow = 2,
ncol = 2,
dimnames = list(c("x", "y"), c("min", "max")),
byrow = TRUE)
map_width = 6400
# Set up a plot
plotSetup = function(file_name, bbox) {
map_aspect = (bbox["y", "max"] - bbox["y", "min"]) /
(bbox["x", "max"] - bbox["x", "min"])
map_height = round(map_width * map_aspect)
png(file_name, width = map_width, height = map_height)
par(mar = c(0, 0, 0, 0))
plot(0, 0,
type = "n",
axes = FALSE,
xlab = NA,
ylab = NA,
xlim = bbox["x", ],
ylim = bbox["y", ])
}
# Plot a layer
plotLayer = function(x) {
l = readShapeSpatial(x, proj4string = crs_nztm)
print(class(l))
if (class(l) == "SpatialPolygonsDataFrame") {
plot(l,
col = fill_colour,
border = line_colour,
lwd = line_width,
add = TRUE)
} else if (class(l) == "SpatialLinesDataFrame") {
lines(l,
col = line_colour,
lwd = line_width)
} else if (class(l) == "SpatialPointsDataFrame") {
plot(l,
pch = 16,
col = line_colour,
cex = point_size,
add = TRUE)
}
}
# Set up the map
plotSetup("outputs/rup_central.png", bbox = central_bbox)
# Base zones
plotLayer("RUP_SHP_20160803/MASTER_RUP_BaseZone.shp")
# Other layers
plotLayer("RUP_SHP_20160803/MASTER_RUP_AircraftNoiseOverlay.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_AirportApproachSurfaceOverlay.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_AirspaceRestrictionDesignations.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_ArterialRoad.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_AucklandMuseumViewshaftContoursOverlay.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_AucklandMuseumViewshaftOverlay.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_BuildingFrontageControl.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_BusinessParkZoneOfficeControl.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_CableProtectionAreasControl.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_CentreFringeOfficeControl.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_CityCentrePortNoiseOverlay.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_CoastalInundationControl.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_Designation.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_DilworthTerraceHousesViewshaftContoursOverlay.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_DilworthTerraceHousesViewshaftOverlay.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_EmergencyManagementAreaControl.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_HeightVariationControl.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_HighNaturalCharacterOverlay.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_HighUseAquiferManagementAreasOverlay.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_HighUseStreamManagementAreaOverlay.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_HistoricHeritageExtentOfPlaceOverlay.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_HistoricHeritagePlaceOverlay.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_IdentifiedGrowthCorridorOverlay.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_IndicativeCoastline.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_LakeManagementAreaOverlay.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_LevelCrossingsWithSightlineControl.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_LocallySignificantVolcanicViewshafts.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_LocalPublicViewsOverlay.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_MacroinvertebrateCommunityIndex.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_NationalGridCorridorOverlay.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_NaturalStreamManagementAreasOverlay.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_NotableTreesOverlay.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_OutstandingNaturalCharacterOverlay.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_OutstandingNaturalFeaturesOverlay.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_OutstandingNaturalLandscapeOverlay.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_ParkingVariationControl.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_Precincts.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_QualitySensitiveAquiferManagementAreasOverlay.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_QuarryBufferAreaOverlay.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_RegionallySignificantVolcanicViewShaftsAndHeightSensitiveAreasOverlay.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_RidgelineProtectionOverlay.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_RuralUrbanBoundary.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_SignificantEcologicalAreasOverlay.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_SitesAndPlacesOfSignificanceToManaWhenuaOverlay.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_SpecialCharacterOverlay.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_StormwaterManagementAreaControl.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_SubdivisionVariationControl.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_SurfBreaks.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_VehicleAccessRestrictionControl.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_WaitakereRangesHeritageAreaOverlay.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_WaterSupplyManagementAreaOverlay.shp")
plotLayer("RUP_SHP_20160803/MASTER_RUP_WetlandManagementAreasOverlay.shp")
dev.off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment