sunnuntai 19. huhtikuuta 2015

KML to GeoJSON to TopoJSON on Mac OS X

These introductions help you to convert a KML file to TopoJSON which allows you to reduce filesize.

Converting KML to TopoJSON

# Get KML (File -> Download -> KML)

# Install node via ports or brew (if not yet available)
port install npm
brew install node.js

# Install togeojson (might need admin privilidges)
npm install -g togeojson

# Rename file to data.kml
cd Downloads
mv Kuntarajat\ 2015.kml data.kml

# Convert KML to GeoJson with togeojson
togeojson data.kml > data.json

# Install topojson (might need admin privilidges)
npm install -g topojson

# Convert GeoJson to TopoJson
topojson data.json -o data.tjson -p Name

# Simplify if needed
topojson data.json -o data.tjson --simplify-proportion=0.5 -p Name

# Use tools to determinate appropriate simplify value

Implementation guidelines

# Get TopoJSON library

# In your implementation define a map
var map = new google.maps.Map($('.map_container')[0], {
    center:new google.maps.LatLng(60.25, 24.87),

# Attach polygons to the map
$.getJSON('data.tjson', function (data) {,;

# Define polygon styles (feature) {
  return {

# Attach listeners'mouseover', function (event) {, {
});'mouseout', function (event) {;

Ei kommentteja:

Lähetä kommentti