• Stars
    star
    199
  • Rank 196,105 (Top 4 %)
  • Language
    JavaScript
  • License
    GNU General Publi...
  • Created almost 8 years ago
  • Updated almost 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Morphing geojson polygons into rectangles

d3.geo2rect

Morphing geojson polygons into rectangles

DemoClip

The package has two modules: compute (function) and draw (class). For using this one needs to include the d3 and turf.js library.

compute

Compute for morphing a geojson into rectangles we need to clean the geojson first. All MultiPolygons will be transformed into Polygons (largest polygon will be used). Holes will be removed. The original data is stored in .geometry.ocoordinates. Afterwards a second set of coordinates is being generated representing a rectangle. The rectangle has the bounding box 0,0|1,1 so its easy to transform. In addition each coordinate has its centroid in the geo-space stored within. The rectangle coordinates are stored in .geometry.qcoordinates.

d3.json('./data/de.geojson', function(err, data){
  var geojson = geo2rect.compute(data);
});

draw

Draw takes care of drawing the data received from the compute function.

Simply create a new draw instance:

var g2r = new geo2rect.draw();

Send the configs:

var config = {
  width : 700,
  height : 700,
  padding : 70,
  projection : d3.geoMercator(),
  duration : 1000,
  key:function(d){return d.properties.Kurz; },
  grid : {
    SH:{x:1,y:0},
    HB:{x:0,y:1},
    HH:{x:1,y:1},
    MV:{x:2,y:1},
    NI:{x:0,y:2},
    BB:{x:1,y:2},
    BE:{x:2,y:2},
    NW:{x:0,y:3},
    ST:{x:1,y:3},
    SN:{x:2,y:3},
    RP:{x:0,y:4},
    HE:{x:1,y:4},
    TH:{x:2,y:4},
    SL:{x:0,y:5},
    BW:{x:1,y:5},
    BY:{x:2,y:5}
  }
};
g2r.config = config;

Please note, that this script does not compute the grid layout. See nmap and nmap-squared for examples of how to do this automatically.

Then send the computed data from the compute function:

g2r.data = geojson;

An d3 svg object:

g2r.svg = svg.append('g');

And then draw the whole thing:

g2r.draw();

You can simply switch the mode by calling:

g2r.toggle();

The current mode can be checked via:

g2r.mode

To update and draw again, simply call the draw function again:

g2r.draw();

Examples

In the examples folder you find three examples for the states of Germany and the US as well as London boroughs.

Live examples can be found here:

Germany US London Italy

More Repositories

1

d3.sketchy

A tool to create sketchy backgrounds, shapes and lines
JavaScript
242
star
2

THREE.geojson

Convert a geoJSON to a 3D mesh structure
JavaScript
40
star
3

OfflineMaps

Offline Maps for Mobile (Leaflet, PhoneGap)
Objective-C
26
star
4

capitals-of-the-world

OSM powered tool for extracting and visualizing road and building data for all capitals of the world
HTML
20
star
5

nmap.js

javascript implementation of nmap (Neighborhood Preservation Space-filling Algorithm)
JavaScript
17
star
6

twitter-scraper

Realtime Scraper for Twitter based on the Twitter API
PHP
17
star
7

d3.layout.odmap

d3 layout for od-maps
JavaScript
16
star
8

dem-playground

Downloading, Processing and Visualization of Digital Elevation Model (DEM) Data
JavaScript
14
star
9

HeatTiles

A new approach for developing realtime heatmaps for mobile devices
PHP
12
star
10

nmap-squared.js

Extension to the nmap algorithm to derive at an equal-sized treemap within a rectangle
JavaScript
10
star
11

svelte-maps

Example for integrating various mapping frameworks
Svelte
9
star
12

d3.mountains

Generative Mountains
JavaScript
8
star
13

ThirtyDayMapChallenge2020

30 day map challenge 2020
HTML
8
star
14

serpentine-organizer

reorganize geojson lines into rectangle filling serpentines
JavaScript
6
star
15

Cinder-VJ_Boilerplate

A Music Visualization Boilerplate using the Cinder Library
C++
6
star
16

geolife-to-geojson

PhD #01 - Transform GeoLife's plt files into GeoJson
JavaScript
5
star
17

d3.deviation-ellipse

Calculating and drawing a standard deviation ellipse for two dimensional data
JavaScript
4
star
18

MentalMaps

Creating mental maps from georeferenced activity data
HTML
4
star
19

vis-survey

PHP Survey Tool
PHP
3
star
20

ThingsVis

Gantt Chart Visualization for the Things ToDo App
PostScript
3
star
21

BerlinRefined

Accessible Data Portal
3
star
22

d3.elasticlists

D3 Elastic Lists Filter-Interface
JavaScript
3
star
23

tutorials

Some of my coding tutorials
HTML
2
star
24

location-classification

PhD #03 - Location analysis, classification and prediction
Python
2
star
25

BerlinRefinedAssets

Tools and Assets for the BerlinRefined Data Portal
HTML
2
star
26

dnb-visualization

Visualizing the German National Library (DNB) Data
PHP
2
star
27

obs

Introduction and templates for Open Broadcaster Software (Studio)
2
star
28

projectionMapper

Java Framework for 3D projection mapping (primarily build for processing)
Java
2
star
29

d3.zoom

Zoom and pan functionality in a responsive bar chart
HTML
1
star
30

color-the-world

Generative Design Approach for color the world based on flag colors
HTML
1
star
31

geojson2svg

Node.js script for converting geojson files to svg using d3 and jsdom
1
star
32

d3.playbar

An interface for timeseries data visualizations
JavaScript
1
star
33

d3.tools

Adding some useful mini functions for d3 projects
JavaScript
1
star
34

watercolor-geojson

Turn GeoJSONs into watercolor maps
1
star
35

d3.cluster

A collection of cluster techniques combined in one library
1
star
36

qgis-generative-markers

Moving the marker rendering onto an external nodejs server
JavaScript
1
star
37

d3.isochrone2prism

Visual Explanation of Hägerstrand's time-space prisms
JavaScript
1
star
38

jQuery.LineWrap

jQuery Plugin to create nice LineWrappers.
JavaScript
1
star
39

typescript-boilerplate

This is optimised for my workflow with sublime text 3 on mac
TypeScript
1
star
40

HeatTile-Stream

Using the HeatTile approach for a progressive data streaming and visualization technique
JavaScript
1
star
41

d3.spinner

Loading Spinner for d3 projects
JavaScript
1
star
42

generative_marker

Generative Marker (Cluster)
JavaScript
1
star
43

electron-boilerplate

Basic electron functionalities
JavaScript
1
star
44

TUIO.touch.js

Implementing TUIO interactions into javascript
HTML
1
star
45

qgis-introduction

Tutorial-Seite für eine QGIS-Einführung
1
star
46

muc23-human-ai-demo

Demonstration of two use case implementations of human-ai collaboration interfaces for organising meta data
Svelte
1
star
47

jquery.mobile.leaflet

Plugin / Widget for initializing leaflet maps in a jQuery Mobile Application
JavaScript
1
star