Update map generator for federal election.
This commit is contained in:
2
map-generator/dist/main.js
vendored
2
map-generator/dist/main.js
vendored
File diff suppressed because one or more lines are too long
11
map-generator/shptojson/Makefile
Normal file
11
map-generator/shptojson/Makefile
Normal file
@@ -0,0 +1,11 @@
|
||||
SHPFILE := ../../../spl-data/federal_2025/aec_data/E_VIC24_region.shp
|
||||
SHAPELIB := ../../../lib/shapelib-1.6.0
|
||||
|
||||
../federal_2025_boundaries.json: $(SHPFILE) shptojson
|
||||
LD_LIBRARY_PATH=$(SHAPELIB)/.libs ./shptojson $(SHPFILE) > $@
|
||||
|
||||
CFLAGS := -I $(SHAPELIB)
|
||||
LDFLAGS := -L $(SHAPELIB)/.libs
|
||||
|
||||
shptojson: shptojson.c
|
||||
gcc -Wall $(CFLAGS) $(LDFLAGS) -lshp $< -o $@
|
||||
142
map-generator/shptojson/shptojson.c
Normal file
142
map-generator/shptojson/shptojson.c
Normal file
@@ -0,0 +1,142 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Project: Shapelib
|
||||
* Purpose: Sample application for dumping contents of a shapefile to
|
||||
* the terminal in human readable form.
|
||||
* Author: Frank Warmerdam, warmerdam@pobox.com
|
||||
*
|
||||
******************************************************************************
|
||||
* Copyright (c) 1999, Frank Warmerdam
|
||||
*
|
||||
* SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
|
||||
******************************************************************************
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "shapefil.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int nPrecision = 15;
|
||||
int first;
|
||||
const char *divison_name;
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/* Display a usage message. */
|
||||
/* -------------------------------------------------------------------- */
|
||||
if (argc != 2)
|
||||
{
|
||||
printf("Usage: shptojson shp_file\n");
|
||||
exit(1);
|
||||
}
|
||||
/* -------------------------------------------------------------------- */
|
||||
/* Open the passed shapefile. */
|
||||
/* -------------------------------------------------------------------- */
|
||||
SHPHandle hSHP = SHPOpen(argv[1], "rb");
|
||||
DBFHandle hDBF = DBFOpen(argv[1], "rb");
|
||||
if (hSHP == NULL || hDBF == NULL)
|
||||
{
|
||||
printf("Unable to open:%s\n", argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/* Print out the file bounds. */
|
||||
/* -------------------------------------------------------------------- */
|
||||
int nEntities;
|
||||
int nShapeType;
|
||||
double adfMinBound[4];
|
||||
double adfMaxBound[4];
|
||||
SHPGetInfo(hSHP, &nEntities, &nShapeType, adfMinBound, adfMaxBound);
|
||||
|
||||
fprintf(stderr, "Shapefile Type: %s # of Shapes: %d\n\n",
|
||||
SHPTypeName(nShapeType), nEntities);
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/* Skim over the list of shapes, printing all the vertices. */
|
||||
/* -------------------------------------------------------------------- */
|
||||
printf("[\n");
|
||||
for (int i = 0; i < nEntities; i++)
|
||||
{
|
||||
SHPObject *psShape = SHPReadObject(hSHP, i);
|
||||
|
||||
if (psShape == NULL)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"Unable to read shape %d, terminating object reading.\n",
|
||||
i);
|
||||
break;
|
||||
}
|
||||
|
||||
divison_name = DBFReadStringAttribute(hDBF, i, 1);
|
||||
fprintf(stderr, "shape %s has %i parts\n", divison_name, psShape->nParts);
|
||||
|
||||
printf(" {\n");
|
||||
printf(" \"electorateId\": \"%08i\",\n", i);
|
||||
printf(" \"electorateName\": \"%s\",\n", divison_name);
|
||||
printf(" \"electorateType\": \"Division\",\n");
|
||||
printf(" \"parentElectorateName\": \"%s\",\n", divison_name);
|
||||
printf(" \"boundaryJson\": \"{\\\"type\\\": ");
|
||||
|
||||
if (psShape->nParts != 1)
|
||||
{
|
||||
printf("\\\"MultiPolygon\\\",\\\"coordinates\\\":[[[");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("\\\"Polygon\\\",\\\"coordinates\\\":[[");
|
||||
}
|
||||
|
||||
first = 1;
|
||||
for (int j = 0, iPart = 1; j < psShape->nVertices; j++)
|
||||
{
|
||||
if (iPart < psShape->nParts && psShape->panPartStart[iPart] == j)
|
||||
{
|
||||
iPart++;
|
||||
printf("]],[[");
|
||||
}
|
||||
else if (!first)
|
||||
{
|
||||
printf(",");
|
||||
}
|
||||
first = 0;
|
||||
printf("[%.*g,%.*g]", nPrecision, psShape->padfX[j],
|
||||
nPrecision, psShape->padfY[j]);
|
||||
}
|
||||
|
||||
if (i == (nEntities-1))
|
||||
{
|
||||
if (psShape->nParts != 1)
|
||||
{
|
||||
printf("]]]}\"\n }\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("]]}\"\n }\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (psShape->nParts != 1)
|
||||
{
|
||||
printf("]]]}\"\n },\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("]]}\"\n },\n");
|
||||
}
|
||||
}
|
||||
|
||||
SHPDestroyObject(psShape);
|
||||
}
|
||||
printf("]\n");
|
||||
|
||||
SHPClose(hSHP);
|
||||
DBFClose(hDBF);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
@@ -32,7 +32,7 @@ map.on('load', () => {
|
||||
|
||||
map.addImage('blue-circle', image);
|
||||
|
||||
fetch("wards_withboundaries.json")
|
||||
fetch("federal_2025_boundaries.json")
|
||||
.then(response => {
|
||||
response.json()
|
||||
.then((wardData) => {
|
||||
@@ -117,7 +117,7 @@ map.on('load', () => {
|
||||
//
|
||||
// The 2024 set of boundaries only uses 2 MultiPolygon objects (Cathedral in Murrindindi Shire Council and Island in Bass Coast Shire Council)
|
||||
// Luckily, the second polygon for both objects results in a good label placement.
|
||||
centrePoint = polylabel(featureCollection.features[0].geometry.coordinates[1], 0.000001);
|
||||
centrePoint = polylabel(featureCollection.features[0].geometry.coordinates[0], 0.000001);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user