Skip to content

Instantly share code, notes, and snippets.

@johnjreiser
Last active February 5, 2023 20:14
Show Gist options
  • Save johnjreiser/57394932506541f772e0b6d53c56565a to your computer and use it in GitHub Desktop.
Save johnjreiser/57394932506541f772e0b6d53c56565a to your computer and use it in GitHub Desktop.
New Jersey counties in TopoJSON
Display the source blob
Display the rendered blob
Raw
{
"type": "Topology",
"objects": {
"nj": {
"type": "GeometryCollection",
"geometries": [
{
"type": "Polygon",
"arcs": [
[
0,
1,
2,
3
]
],
"properties": {
"id": "34037"
}
},
{
"type": "Polygon",
"arcs": [
[
4,
5,
-1,
6,
7
]
],
"properties": {
"id": "34031"
}
},
{
"type": "Polygon",
"arcs": [
[
8,
9,
-8,
10
]
],
"properties": {
"id": "34003"
}
},
{
"type": "Polygon",
"arcs": [
[
11,
12,
13,
-3
]
],
"properties": {
"id": "34041"
}
},
{
"type": "Polygon",
"arcs": [
[
14,
15,
16,
17,
-12,
-2,
-6
]
],
"properties": {
"id": "34027"
}
},
{
"type": "Polygon",
"arcs": [
[
-5,
-10,
18,
19,
20,
-15
]
],
"properties": {
"id": "34013"
}
},
{
"type": "Polygon",
"arcs": [
[
21,
-19,
-9
]
],
"properties": {
"id": "34017"
}
},
{
"type": "Polygon",
"arcs": [
[
22,
23,
24,
-13,
-18
]
],
"properties": {
"id": "34019"
}
},
{
"type": "Polygon",
"arcs": [
[
25,
26,
27,
-23,
-17
]
],
"properties": {
"id": "34035"
}
},
{
"type": "Polygon",
"arcs": [
[
28,
29,
-26,
-16,
-21
]
],
"properties": {
"id": "34039"
}
},
{
"type": "Polygon",
"arcs": [
[
30,
31,
32,
-27,
-30
]
],
"properties": {
"id": "34023"
}
},
{
"type": "Polygon",
"arcs": [
[
33,
34,
35,
-32,
36
]
],
"properties": {
"id": "34025"
}
},
{
"type": "Polygon",
"arcs": [
[
-33,
-36,
37,
38,
-24,
-28
]
],
"properties": {
"id": "34021"
}
},
{
"type": "Polygon",
"arcs": [
[
-35,
39,
40,
41,
42,
43,
-38
]
],
"properties": {
"id": "34005"
}
},
{
"type": "MultiPolygon",
"arcs": [
[
[
44,
-40,
-34
]
]
],
"properties": {
"id": "34029"
}
},
{
"type": "MultiPolygon",
"arcs": [
[
[
45,
46,
47,
-43
]
]
],
"properties": {
"id": "34007"
}
},
{
"type": "MultiPolygon",
"arcs": [
[
[
48,
49,
50,
51,
-47
]
]
],
"properties": {
"id": "34015"
}
},
{
"type": "MultiPolygon",
"arcs": [
[
[
52,
53,
-51
]
]
],
"properties": {
"id": "34033"
}
},
{
"type": "MultiPolygon",
"arcs": [
[
[
54,
55,
56,
-49,
-46,
-42
]
]
],
"properties": {
"id": "34001"
}
},
{
"type": "MultiPolygon",
"arcs": [
[
[
-53,
-50,
-57,
57,
58
]
]
],
"properties": {
"id": "34011"
}
},
{
"type": "MultiPolygon",
"arcs": [
[
[
59,
-58,
-56
]
]
],
"properties": {
"id": "34009"
}
}
]
}
},
"arcs": [
[
[
-74.3653027,
41.2005412
],
[
-74.5027715,
41.0859674
]
],
[
[
-74.5027715,
41.0859674
],
[
-74.6524437,
40.9219222
],
[
-74.7680179,
40.9118775
]
],
[
[
-74.7680179,
40.9118775
],
[
-74.966863,
41.0944543
]
],
[
[
-74.966863,
41.0944543
],
[
-74.9916289,
41.092252
],
[
-74.8383674,
41.2772998
],
[
-74.7005398,
41.354488
],
[
-74.3653027,
41.2005412
]
],
[
[
-74.1302061,
40.8199714
],
[
-74.2719819,
40.8973745
]
],
[
[
-74.2719819,
40.8973745
],
[
-74.3093102,
40.9984122
],
[
-74.5027715,
41.0859674
]
],
[
[
-74.3653027,
41.2005412
],
[
-74.2314233,
41.143872
],
[
-74.213118,
41.1345793
]
],
[
[
-74.213118,
41.1345793
],
[
-74.2723409,
41.0182867
],
[
-74.1406149,
40.9661832
],
[
-74.1302061,
40.8199714
]
],
[
[
-73.9927374,
40.8008489
],
[
-74.1474345,
40.7863996
]
],
[
[
-74.1474345,
40.7863996
],
[
-74.1302061,
40.8199714
]
],
[
[
-74.213118,
41.1345793
],
[
-73.9033647,
40.9985196
],
[
-73.9927374,
40.8008489
]
],
[
[
-74.7680179,
40.9118775
],
[
-74.8896939,
40.7877962
]
],
[
[
-74.8896939,
40.7877962
],
[
-74.9686576,
40.7105005
],
[
-75.1897562,
40.5917906
]
],
[
[
-75.1897562,
40.5917906
],
[
-75.1969347,
40.6084959
],
[
-75.1725277,
40.7779663
],
[
-75.0501339,
40.8705171
],
[
-75.1204834,
40.9682781
],
[
-74.966863,
41.0944543
]
],
[
[
-74.2719819,
40.8973745
],
[
-74.330128,
40.9086009
],
[
-74.3717634,
40.7392379
]
],
[
[
-74.3717634,
40.7392379
],
[
-74.4607771,
40.6741355
]
],
[
[
-74.4607771,
40.6741355
],
[
-74.5558925,
40.7579844
],
[
-74.7249468,
40.7191486
]
],
[
[
-74.7249468,
40.7191486
],
[
-74.8896939,
40.7877962
]
],
[
[
-74.1474345,
40.7863996
],
[
-74.1176437,
40.7346184
]
],
[
[
-74.1176437,
40.7346184
],
[
-74.159997,
40.6869196
]
],
[
[
-74.159997,
40.6869196
],
[
-74.3717634,
40.7392379
]
],
[
[
-73.9927374,
40.8008489
],
[
-74.0684708,
40.6637148
],
[
-74.1438453,
40.6434643
],
[
-74.1176437,
40.7346184
]
],
[
[
-74.7249468,
40.7191486
],
[
-74.7131022,
40.5840019
],
[
-74.7755554,
40.5034296
],
[
-74.748277,
40.4240928
]
],
[
[
-74.748277,
40.4240928
],
[
-74.8563137,
40.3466897
],
[
-74.942815,
40.3416942
]
],
[
[
-74.942815,
40.3416942
],
[
-75.0619784,
40.4220516
],
[
-75.0677213,
40.5412986
],
[
-75.1897562,
40.5917906
]
],
[
[
-74.4607771,
40.6741355
],
[
-74.4629307,
40.5988273
]
],
[
[
-74.4629307,
40.5988273
],
[
-74.5264606,
40.5563388
],
[
-74.4593414,
40.4909141
],
[
-74.6194225,
40.3742991
]
],
[
[
-74.6194225,
40.3742991
],
[
-74.748277,
40.4240928
]
],
[
[
-74.159997,
40.6869196
],
[
-74.2080931,
40.5953895
]
],
[
[
-74.2080931,
40.5953895
],
[
-74.4629307,
40.5988273
]
],
[
[
-74.2080931,
40.5953895
],
[
-74.2741355,
40.4886581
],
[
-74.222809,
40.4511114
]
],
[
[
-74.222809,
40.4511114
],
[
-74.39294,
40.2803518
],
[
-74.4841073,
40.2532258
]
],
[
[
-74.4841073,
40.2532258
],
[
-74.621576,
40.3242368
],
[
-74.6194225,
40.3742991
]
],
[
[
-74.096467,
40.1236118
],
[
-74.2447035,
40.1182403
],
[
-74.2662391,
40.1687323
],
[
-74.4069382,
40.1723312
],
[
-74.5530211,
40.0790822
]
],
[
[
-74.5530211,
40.0790822
],
[
-74.587837,
40.1381685
]
],
[
[
-74.587837,
40.1381685
],
[
-74.4841073,
40.2532258
]
],
[
[
-74.222809,
40.4511114
],
[
-74.0013516,
40.4113086
],
[
-73.9758678,
40.3052755
],
[
-74.0347317,
40.1034687
],
[
-74.096467,
40.1236118
]
],
[
[
-74.587837,
40.1381685
],
[
-74.7242289,
40.1473001
]
],
[
[
-74.7242289,
40.1473001
],
[
-74.942815,
40.3416942
]
],
[
[
-74.5530211,
40.0790822
],
[
-74.3904276,
39.7744114
],
[
-74.4144756,
39.5609486
]
],
[
[
-74.4144756,
39.5609486
],
[
-74.417347,
39.5572959
]
],
[
[
-74.417347,
39.5572959
],
[
-74.6592633,
39.6311002
],
[
-74.7364324,
39.7298818
]
],
[
[
-74.7364324,
39.7298818
],
[
-74.9029741,
39.7910093
],
[
-74.9320472,
39.887535
],
[
-75.054441,
39.9906675
]
],
[
[
-75.054441,
39.9906675
],
[
-75.059107,
39.9932458
],
[
-74.9740415,
40.0485184
],
[
-74.7242289,
40.1473001
]
],
[
[
-74.096467,
40.1236118
],
[
-74.0322192,
40.101159
],
[
-74.0892885,
39.8112061
],
[
-74.1057991,
39.9308829
],
[
-74.1973253,
39.7447608
],
[
-74.1603559,
39.7037764
],
[
-74.3416136,
39.5654606
],
[
-74.4144756,
39.5609486
]
],
[
[
-74.7364324,
39.7298818
],
[
-74.8771315,
39.6082176
]
],
[
[
-74.8771315,
39.6082176
],
[
-75.0239323,
39.7304727
],
[
-75.132328,
39.8843658
]
],
[
[
-75.132328,
39.8843658
],
[
-75.054441,
39.9906675
]
],
[
[
-74.8771315,
39.6082176
],
[
-74.9851682,
39.5148075
]
],
[
[
-74.9851682,
39.5148075
],
[
-75.0619784,
39.5685761
]
],
[
[
-75.0619784,
39.5685761
],
[
-75.200165,
39.6670354
],
[
-75.326507,
39.6909923
],
[
-75.4273653,
39.7845636
]
],
[
[
-75.4273653,
39.7845636
],
[
-75.132328,
39.8843658
]
],
[
[
-75.0619784,
39.5685761
],
[
-75.0838729,
39.4576549
],
[
-75.2396469,
39.559176
],
[
-75.4169564,
39.3876107
]
],
[
[
-75.4169564,
39.3876107
],
[
-75.5425806,
39.4965444
],
[
-75.5382735,
39.4969204
],
[
-75.5565787,
39.6066599
],
[
-75.5594501,
39.629811
],
[
-75.4273653,
39.7845636
]
],
[
[
-74.417347,
39.5572959
],
[
-74.4094507,
39.3644059
],
[
-74.655674,
39.2891513
]
],
[
[
-74.655674,
39.2891513
],
[
-74.8609798,
39.32369
]
],
[
[
-74.8609798,
39.32369
],
[
-74.8559548,
39.4245665
],
[
-74.9851682,
39.5148075
]
],
[
[
-74.8609798,
39.32369
],
[
-74.9148187,
39.1774244
]
],
[
[
-74.9148187,
39.1774244
],
[
-75.1707331,
39.2350605
],
[
-75.36563,
39.3450148
],
[
-75.4072654,
39.3818095
],
[
-75.4130083,
39.3841729
],
[
-75.4169564,
39.3876107
]
],
[
[
-74.655674,
39.2891513
],
[
-74.6309081,
39.2521955
],
[
-74.7863231,
39.0004876
],
[
-74.8642101,
38.9400584
],
[
-74.971529,
38.939951
],
[
-74.9008206,
39.0914806
],
[
-74.9148187,
39.1774244
]
]
],
"bbox": [
-75.5594501,
38.939951,
-73.9033647,
41.354488
]
}
#!/bin/bash
# get us topojson file
curl -o us.topojson https://gist.githubusercontent.com/cmdoptesc/4714c586f69425043ae3/raw/d534aba169207548a8a3d670c9c2cc719ff05c47/us.json
# extract NJ counties to GeoJSON
ogr2ogr -f GeoJSON nj.geojson us.topojson counties -where "id like '34%'" -lco COORDINATE_PRECISION=7
# install topojson-server (if not already installed)
npm install topojson-server
# convert the GeoJSON to TopoJSON
npx geo2topo nj.geojson > nj.topojson
# make pretty if desired (using https://stedolan.github.io/jq/)
jq . nj.topojson > nj.topojson.pretty
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment