Skip to content

Commit a55c99a

Browse files
committed
finish typing shapefile, could still type shapefile/dbf and shapefile/shp
1 parent 5dacb45 commit a55c99a

16 files changed

+2906
-25
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules/
22
dist/
3-
shp/
3+
shp/
4+
generated/

Makefile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,20 @@
22
# -> upload as to mapbox
33
# -> calculate bounds.json
44
# Make sure to remove intermediate shp, geojson files. Just need bounds.json and geojson with digits
5-
all: shp/POA_2011_AUST.shp
5+
all: generated/postal_boundaries_mapbox.geojson
66

77
clean:
8-
rm -rf -- shp
8+
rm -rf -- shp generated
99

1010
shp/POA_2011_AUST.shp:
1111
unzip originals/2011_POA_shape.zip -d $(dir $@)
1212
touch $@
1313

14+
# TODO(yuri): Generalise TypeScript compilation?
15+
process_for_mapbox.js: src/process_for_mapbox.ts
16+
tsc --outDir $(dir $@) $<
17+
chmod +x $@
18+
19+
generated/postal_boundaries_mapbox.geojson: process_for_mapbox.js shp/POA_2011_AUST.shp
20+
mkdir -p $(dir $@)
21+
node process_for_mapbox.js shp/POA_2011_AUST.shp > $@

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
"rollup": "^0.33.0",
3131
"rollup-plugin-commonjs": "^3.1.0",
3232
"rollup-plugin-node-resolve": "^1.7.1",
33-
"turf-extent": "^1.0.4"
33+
"tslint": "^3.14.0",
34+
"turf-extent": "^1.0.4",
35+
"typescript": "^2.0.0"
3436
}
3537
}

process_for_mapbox.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/// <reference path="../typings/index.d.ts"/>
2+
"use strict";
3+
var shapefile = require("shapefile");
4+
shapefile.read(process.argv[2], function (error, postalGeoJSON) {
5+
postalGeoJSON.features.forEach(function (feature) {
6+
var postcode = feature.properties.POA_CODE.slice(3);
7+
var digits = {
8+
digit_one: +postcode.slice(0, 1),
9+
digit_two: +postcode.slice(1, 2),
10+
digit_three: +postcode.slice(2, 3),
11+
digit_four: +postcode.slice(3, 4),
12+
postcode: postcode
13+
};
14+
for (var key in digits) {
15+
feature.properties[key] = digits[key];
16+
}
17+
});
18+
process.stdout.write(JSON.stringify(postalGeoJSON));
19+
});

process_for_mapbox_filters.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/process_for_mapbox.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/// <reference path="../typings/index.d.ts"/>
2+
"use strict";
3+
var shapefile = require("shapefile");
4+
shapefile.read(process.argv[2], function (error, postalGeoJSON) {
5+
postalGeoJSON.features.forEach(function (feature) {
6+
var postcode = feature.properties.POA_CODE.slice(3);
7+
var digits = {
8+
digit_one: +postcode.slice(0, 1),
9+
digit_two: +postcode.slice(1, 2),
10+
digit_three: +postcode.slice(2, 3),
11+
digit_four: +postcode.slice(3, 4),
12+
postcode: postcode
13+
};
14+
for (var key in digits) {
15+
feature.properties[key] = digits[key];
16+
}
17+
});
18+
process.stdout.write(JSON.stringify(postalGeoJSON));
19+
});

src/process_for_mapbox.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/// <reference path="../typings/index.d.ts"/>
2+
3+
import * as fs from "fs";
4+
import * as shapefile from "shapefile";
5+
6+
shapefile.read(process.argv[2], (error, postalGeoJSON) => {
7+
postalGeoJSON.features.forEach(function (feature) {
8+
let postcode = feature.properties.POA_CODE.slice(3);
9+
10+
let digits = {
11+
digit_one: +postcode.slice(0, 1),
12+
digit_two: +postcode.slice(1, 2),
13+
digit_three: +postcode.slice(2, 3),
14+
digit_four: +postcode.slice(3, 4),
15+
postcode: postcode,
16+
};
17+
18+
for (let key in digits) {
19+
feature.properties[key] = (<any>digits)[key];
20+
}
21+
});
22+
23+
process.stdout.write(JSON.stringify(postalGeoJSON));
24+
});

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
"files": [
1111
"typings/index.d.ts"
1212
]
13-
}
13+
}

typings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"globalDependencies": {
3+
"node": "registry:dt/node#6.0.0+20160805072842"
4+
}
5+
}

typings/globals/geojson/index.d.ts

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
// Generated by typings
2+
// Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/29708b6a46a61274d2d402d336ef60c697085b64/geojson/geojson.d.ts
3+
declare namespace GeoJSON {
4+
5+
/***
6+
* http://geojson.org/geojson-spec.html#geojson-objects
7+
*/
8+
export interface GeoJsonObject
9+
{
10+
type: string;
11+
bbox?: number[];
12+
crs?: CoordinateReferenceSystem;
13+
}
14+
15+
/***
16+
* http://geojson.org/geojson-spec.html#positions
17+
*/
18+
export type Position = number[]
19+
20+
/***
21+
* http://geojson.org/geojson-spec.html#geometry-objects
22+
*/
23+
export interface GeometryObject extends GeoJsonObject
24+
{
25+
coordinates: any
26+
}
27+
28+
/***
29+
* http://geojson.org/geojson-spec.html#point
30+
*/
31+
export interface Point extends GeometryObject
32+
{
33+
type: 'Point'
34+
coordinates: Position
35+
}
36+
37+
/***
38+
* http://geojson.org/geojson-spec.html#multipoint
39+
*/
40+
export interface MultiPoint extends GeometryObject
41+
{
42+
type: 'MultiPoint'
43+
coordinates: Position[]
44+
}
45+
46+
/***
47+
* http://geojson.org/geojson-spec.html#linestring
48+
*/
49+
export interface LineString extends GeometryObject
50+
{
51+
type: 'LineString'
52+
coordinates: Position[]
53+
}
54+
55+
/***
56+
* http://geojson.org/geojson-spec.html#multilinestring
57+
*/
58+
export interface MultiLineString extends GeometryObject
59+
{
60+
type: 'MultiLineString'
61+
coordinates: Position[][]
62+
}
63+
64+
/***
65+
* http://geojson.org/geojson-spec.html#polygon
66+
*/
67+
export interface Polygon extends GeometryObject
68+
{
69+
type: 'Polygon'
70+
coordinates: Position[][]
71+
}
72+
73+
/***
74+
* http://geojson.org/geojson-spec.html#multipolygon
75+
*/
76+
export interface MultiPolygon extends GeometryObject
77+
{
78+
type: 'MultiPolygon'
79+
coordinates: Position[][][]
80+
}
81+
82+
/***
83+
* http://geojson.org/geojson-spec.html#geometry-collection
84+
*/
85+
export interface GeometryCollection extends GeoJsonObject
86+
{
87+
type: 'GeometryCollection'
88+
geometries: GeometryObject[];
89+
}
90+
91+
/***
92+
* http://geojson.org/geojson-spec.html#feature-objects
93+
*/
94+
export interface Feature<T extends GeometryObject> extends GeoJsonObject
95+
{
96+
type: 'Feature'
97+
geometry: T;
98+
properties: any;
99+
id?: string;
100+
}
101+
102+
/***
103+
* http://geojson.org/geojson-spec.html#feature-collection-objects
104+
*/
105+
export interface FeatureCollection<T extends GeometryObject> extends GeoJsonObject
106+
{
107+
type: 'FeatureCollection'
108+
features: Feature<T>[];
109+
}
110+
111+
/***
112+
* http://geojson.org/geojson-spec.html#coordinate-reference-system-objects
113+
*/
114+
export interface CoordinateReferenceSystem
115+
{
116+
type: string;
117+
properties: any;
118+
}
119+
120+
export interface NamedCoordinateReferenceSystem extends CoordinateReferenceSystem
121+
{
122+
properties: { name: string }
123+
}
124+
125+
export interface LinkedCoordinateReferenceSystem extends CoordinateReferenceSystem
126+
{
127+
properties: { href: string; type: string }
128+
}
129+
}

typings/globals/geojson/typings.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"resolution": "main",
3+
"tree": {
4+
"src": "https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/29708b6a46a61274d2d402d336ef60c697085b64/geojson/geojson.d.ts",
5+
"raw": "registry:dt/geojson#0.0.0+20160619034323",
6+
"typings": "https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/29708b6a46a61274d2d402d336ef60c697085b64/geojson/geojson.d.ts"
7+
}
8+
}

0 commit comments

Comments
 (0)