Skip to content

Instantly share code, notes, and snippets.

@chilijung
Last active August 29, 2015 14:04
Show Gist options
  • Save chilijung/f85dcf428596eabaabee to your computer and use it in GitHub Desktop.
Save chilijung/f85dcf428596eabaabee to your computer and use it in GitHub Desktop.
shp to geojson

map testing

shapefiles to geojson

ogr2ogr -f geoJSON kc.json kc.shp

shapefiles info

ogrinfo tl_2010_20_tract10.shp tl_2010_20_tract10
# SCRIPT

# sudo apt-get install npm gdal-bin
# sudo npm install -g mapshaper

# convert shp to geojson & big5 to utf8
mapshaper -p 0.01 --auto-snap -f geojson --encoding big5 -o json/102_05_21_twd97.geo.json 全國村里界圖102.05.21_修正屬性表ID_TWD97/102_05_21台澎金馬修正村里屬性資料_TWD97.shp

# convert geojson polygons from EPSG:3826 to EPSG:4326
ogr2ogr -t_srs EPSG:4326 -s_srs EPSG:3826 -f "GeoJSON" -lco ENCODING=UTF-8 json/102_05_21_4326.geo.json json/102_05_21_twd97.geo.json

# convert geojson to topojson
mapshaper -p 0.01 --auto-snap -f topojson --encoding utf8 -o json/102_05_21_4326.topo.json json/102_05_21_4326.geo.json

epsg 3826: http://spatialreference.org/ref/epsg/twd97-tm2-zone-121/

epgs 4326: http://spatialreference.org/ref/epsg/wgs-84/

tutorial: https://g0v.hackpad.com/GIS-YAuGma5fg7W

read more: http://vallandingham.me/shapefile_to_geojson.html

sample data from: http://www.nlsc.gov.tw/websites/make_page.aspx?la=1&le=2&li=11&sno=136&le2=3&li2=135

Display the source blob
Display the rendered blob
Raw
{
"type": "FeatureCollection",
"features": [
{ "type": "Feature", "properties": { "ID": 6, "BLOCKTYPE": "96320", "BLOCKNAME": "苗栗縣立頭份鎮新興國民小學" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 120.913278385610866, 24.676250132335188 ], [ 120.913494062479685, 24.676103487782246 ], [ 120.913522077283545, 24.676140965172696 ], [ 120.91373103696499, 24.675997952293226 ], [ 120.913743209999225, 24.675988620830601 ], [ 120.913573658284804, 24.675568127692433 ], [ 120.913450322152968, 24.675208048993483 ], [ 120.913402710169137, 24.675069446208646 ], [ 120.913375113848375, 24.674991566196574 ], [ 120.913365505696319, 24.674975592375016 ], [ 120.913250795783412, 24.674645634823154 ], [ 120.913175814254558, 24.674703435209128 ], [ 120.912925557728499, 24.674900023596535 ], [ 120.912575511475623, 24.675165064706075 ], [ 120.912575993009057, 24.67516601390988 ], [ 120.912652480226313, 24.675344763010248 ], [ 120.912605652400799, 24.675382320725429 ], [ 120.912562840483545, 24.675416656590659 ], [ 120.91252080068621, 24.675450373519702 ], [ 120.912484782799069, 24.675479259943437 ], [ 120.912502115844177, 24.675522222598524 ], [ 120.912300152311616, 24.675683670090027 ], [ 120.91227264993303, 24.675698286049474 ], [ 120.912481455846688, 24.67623530530938 ], [ 120.912537332418921, 24.676469411343952 ], [ 120.912711534011436, 24.676436954953868 ], [ 120.913281702936786, 24.676352679373391 ], [ 120.913278385610866, 24.676250132335188 ] ] ] } }
,
{ "type": "Feature", "properties": { "ID": 8, "BLOCKTYPE": "96320", "BLOCKNAME": "苗栗縣立頭份鎮建國國民中學" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 120.910818658854069, 24.694033231012028 ], [ 120.910712315953319, 24.694012293338488 ], [ 120.909652385121291, 24.694631031037183 ], [ 120.908797236195397, 24.695137707211234 ], [ 120.908576607054073, 24.69527260146987 ], [ 120.908570195488906, 24.695337212669045 ], [ 120.909340379611379, 24.695899193585785 ], [ 120.909405751567277, 24.695910141581109 ], [ 120.91041898356049, 24.695329594760935 ], [ 120.911282362515692, 24.694829781476379 ], [ 120.91130081998061, 24.694767335141986 ], [ 120.910818658854069, 24.694033231012028 ] ] ] } }
,
{ "type": "Feature", "properties": { "ID": 9, "BLOCKTYPE": "96320", "BLOCKNAME": "苗栗縣立頭份鎮建國國民小學" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 120.912329204862274, 24.694422374909511 ], [ 120.912278106237679, 24.694413659404933 ], [ 120.911289153787521, 24.69498617959141 ], [ 120.912274848156898, 24.696427498931001 ], [ 120.912310837111235, 24.696435934747708 ], [ 120.913323266401846, 24.695842494692279 ], [ 120.913328074347206, 24.695812462450593 ], [ 120.912329204862274, 24.694422374909511 ] ] ] } }
,
{ "type": "Feature", "properties": { "ID": 10, "BLOCKTYPE": "96371", "BLOCKNAME": "蟠桃公園" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 120.912222572058823, 24.696487368659426 ], [ 120.911741942290618, 24.695784583825233 ], [ 120.911697081335859, 24.695769918237438 ], [ 120.910750430840622, 24.696329257793813 ], [ 120.91079426257663, 24.696387675434632 ], [ 120.910804842655907, 24.696385407381737 ], [ 120.910868704975499, 24.69643933336512 ], [ 120.910870270127518, 24.69654112252875 ], [ 120.910846146368939, 24.696550853826693 ], [ 120.910761965934924, 24.696591504470806 ], [ 120.910850485399337, 24.696790403375559 ], [ 120.910673000506563, 24.696871546602541 ], [ 120.911091476790844, 24.697176883460717 ], [ 120.912202795179525, 24.69653187059896 ], [ 120.912222572058823, 24.696487368659426 ] ] ] } }
,
{ "type": "Feature", "properties": { "ID": 11, "BLOCKTYPE": "96371", "BLOCKNAME": "上公園" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 120.910706719610346, 24.68695131859192 ], [ 120.910698864012076, 24.686950513972338 ], [ 120.910683780072574, 24.686953414064707 ], [ 120.910675880730579, 24.686958525057328 ], [ 120.910666609139341, 24.686964520050914 ], [ 120.910661064866986, 24.686970742980641 ], [ 120.910655516440457, 24.686977247604787 ], [ 120.91065207465094, 24.686984033373694 ], [ 120.910650854696499, 24.686993077653103 ], [ 120.910651743428275, 24.687002301956667 ], [ 120.910836001004327, 24.687274371991364 ], [ 120.910865935674039, 24.687290894326186 ], [ 120.910877041410984, 24.687295973272345 ], [ 120.910888197315742, 24.687297207804292 ], [ 120.910897786924025, 24.687297050977914 ], [ 120.910906806753061, 24.687294923738857 ], [ 120.910915371474758, 24.687290768371227 ], [ 120.911008869832131, 24.687214529045242 ], [ 120.911016333672677, 24.687196479573508 ], [ 120.911017920629092, 24.687182689996011 ], [ 120.911016272207576, 24.6871689183643 ], [ 120.911011155185307, 24.687155177180301 ], [ 120.911000480844081, 24.687138213048623 ], [ 120.910715290613368, 24.686952194060765 ], [ 120.910706719610346, 24.68695131859192 ] ] ] } }
,
{ "type": "Feature", "properties": { "ID": 12, "BLOCKTYPE": "96320", "BLOCKNAME": "苗栗縣立頭份鎮頭份國民小學" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 120.91386757257213, 24.689086924859268 ], [ 120.913993258677607, 24.68904367425273 ], [ 120.914076308297794, 24.688944078694959 ], [ 120.914082695623321, 24.688866947014485 ], [ 120.914088135304695, 24.688649893510906 ], [ 120.914131951189617, 24.688649047302086 ], [ 120.914133364763686, 24.688619569234589 ], [ 120.914132600191181, 24.688601819173325 ], [ 120.914132869194745, 24.688285634222893 ], [ 120.914118361987661, 24.688286086391738 ], [ 120.913986151641438, 24.688285998067848 ], [ 120.913871328368046, 24.688279377368588 ], [ 120.913717740134786, 24.688266350981149 ], [ 120.913573200375694, 24.688246998684296 ], [ 120.913502846406189, 24.688237673000195 ], [ 120.913417348281754, 24.68822388376411 ], [ 120.913324488485998, 24.688206576239175 ], [ 120.91321134926018, 24.688182783320112 ], [ 120.913084444793839, 24.688152651386499 ], [ 120.912987660025181, 24.688126679195843 ], [ 120.912917641755143, 24.688106555044005 ], [ 120.912839320198643, 24.688078475319891 ], [ 120.912753246355493, 24.68804591098321 ], [ 120.912668271356679, 24.688010633193198 ], [ 120.912562590981807, 24.687964792297926 ], [ 120.912391113025819, 24.687883583439547 ], [ 120.911974254511648, 24.687681003463702 ], [ 120.911615544607557, 24.687501571983137 ], [ 120.911600981778577, 24.687529162502432 ], [ 120.911492147259253, 24.687715070833928 ], [ 120.911477479954755, 24.687736602985595 ], [ 120.911679632625663, 24.687843528570752 ], [ 120.911665877792714, 24.687861772102632 ], [ 120.911486945802821, 24.688226570978962 ], [ 120.911746842560149, 24.688605345593537 ], [ 120.911860821150853, 24.688767861461461 ], [ 120.912264558112852, 24.688914707705901 ], [ 120.912398973167768, 24.688956730161646 ], [ 120.912628448587711, 24.689049738131235 ], [ 120.912703230817314, 24.688990003170886 ], [ 120.912825910559633, 24.689029901178326 ], [ 120.912835159405887, 24.689036789165478 ], [ 120.912936166512765, 24.689061315689614 ], [ 120.912935284115193, 24.689065471112215 ], [ 120.912934947020361, 24.689067057268367 ], [ 120.912943392559157, 24.689068107695157 ], [ 120.91299166562743, 24.689074114517652 ], [ 120.912991245918931, 24.689083671207893 ], [ 120.912993474167834, 24.689082499664387 ], [ 120.913041380411684, 24.689091650069599 ], [ 120.913040935920847, 24.689098474645395 ], [ 120.913444893375456, 24.689137093810523 ], [ 120.913759707596782, 24.689113307249706 ], [ 120.91386757257213, 24.689086924859268 ] ] ] } }
,
{ "type": "Feature", "properties": { "ID": 17, "BLOCKTYPE": "96381", "BLOCKNAME": "重光醫院" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 120.90820172217073, 24.686486336754108 ], [ 120.908097512946895, 24.686411159191369 ], [ 120.908096414941198, 24.686412674447084 ], [ 120.908072036123258, 24.686395277366227 ], [ 120.908057362708121, 24.686417815888895 ], [ 120.908055501806388, 24.686420589117891 ], [ 120.90805550217317, 24.686641604720108 ], [ 120.908086616554741, 24.686658546694531 ], [ 120.908112205296121, 24.686620242520405 ], [ 120.908139515369044, 24.686579361685627 ], [ 120.908201006991305, 24.686487313228032 ], [ 120.90820172217073, 24.686486336754108 ] ] ] } }
,
{ "type": "Feature", "properties": { "ID": 82, "BLOCKTYPE": "96381", "BLOCKNAME": "財團法人為恭紀念醫院" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 120.908173516788409, 24.687239467415846 ], [ 120.908055503046654, 24.687171304814964 ], [ 120.9080555034285, 24.687404375025757 ], [ 120.908055558963198, 24.687404296369522 ], [ 120.908160616940108, 24.687255496396855 ], [ 120.908173516788409, 24.687239467415846 ] ] ] } }
,
{ "type": "Feature", "properties": { "ID": 234, "BLOCKTYPE": "96371", "BLOCKNAME": "地標公園" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 120.912303508147815, 24.689649622951858 ], [ 120.912290273254939, 24.689647748074862 ], [ 120.912268265734369, 24.689650405920737 ], [ 120.912261326670006, 24.689652929915894 ], [ 120.91225308240449, 24.689656527569234 ], [ 120.912239509860754, 24.689665485185468 ], [ 120.912179003935307, 24.689717997133389 ], [ 120.91214076614537, 24.689751290850886 ], [ 120.912132070364677, 24.689761777169938 ], [ 120.91212771843864, 24.689767137700667 ], [ 120.912119317623251, 24.689785397945776 ], [ 120.91211240054983, 24.689810096558052 ], [ 120.912111008620585, 24.689822103981328 ], [ 120.912112032736971, 24.689830102247985 ], [ 120.912114972242122, 24.68983497227099 ], [ 120.91211871766653, 24.689840510893188 ], [ 120.912426372041693, 24.690005133101156 ], [ 120.912447129247141, 24.690009939473967 ], [ 120.912462290195862, 24.690010441284361 ], [ 120.912476102441161, 24.690009214204185 ], [ 120.912489374524128, 24.690006005900052 ], [ 120.912499397085426, 24.690000321823312 ], [ 120.912508065702212, 24.689991921108781 ], [ 120.912515422007957, 24.689983451010537 ], [ 120.912519222302294, 24.689975538622413 ], [ 120.91252084833701, 24.689967872355108 ], [ 120.912520584028201, 24.689961443730848 ], [ 120.912516743572112, 24.68995327589122 ], [ 120.912303508147815, 24.689649622951858 ] ] ] } }
,
{ "type": "Feature", "properties": { "ID": 267, "BLOCKTYPE": "96371", "BLOCKNAME": "東興河濱公園" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 120.908304092384952, 24.679710975587177 ], [ 120.909031060844185, 24.678644069869272 ], [ 120.909022506290498, 24.678637665099885 ], [ 120.909015645507239, 24.678647448123165 ], [ 120.908998661208628, 24.678661452279286 ], [ 120.908986556091222, 24.678662136547178 ], [ 120.908975207916058, 24.67866005305401 ], [ 120.908948737524156, 24.678644142773216 ], [ 120.908563651628356, 24.678295794002892 ], [ 120.908494344674153, 24.678241026648323 ], [ 120.908290647455559, 24.678106415351891 ], [ 120.908246152023665, 24.678036240096073 ], [ 120.908055516696862, 24.677839314510262 ], [ 120.908055486515153, 24.677839283332425 ], [ 120.908055489486202, 24.679420208697628 ], [ 120.908055554980081, 24.679420315985787 ], [ 120.908066087741062, 24.679437569175594 ], [ 120.908238475941545, 24.67965691100855 ], [ 120.908304092384952, 24.679710975587177 ] ] ] } }
,
{ "type": "Feature", "properties": { "ID": 268, "BLOCKTYPE": "96371", "BLOCKNAME": "忠孝公園" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 120.90941027643909, 24.693249443791046 ], [ 120.909669771558313, 24.692847575373509 ], [ 120.909418621393996, 24.692707817952019 ], [ 120.9091578131723, 24.69305134500156 ], [ 120.908879805123192, 24.692898720716219 ], [ 120.908473011979112, 24.693491394597437 ], [ 120.908562155431824, 24.693538232269432 ], [ 120.90908870667873, 24.693810635120332 ], [ 120.909312781498912, 24.693452067627614 ], [ 120.90936537897926, 24.693383882704943 ], [ 120.909358852733874, 24.69337821503234 ], [ 120.909348223883725, 24.693368983944726 ], [ 120.90933497155811, 24.693359307960495 ], [ 120.909362322621575, 24.693315165784171 ], [ 120.90941027643909, 24.693249443791046 ] ] ] } }
]
}
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View raw

(Sorry about that, but we can’t show files that are this big right now.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment