Skip to content

Instantly share code, notes, and snippets.

Forked from wsvekla/
Last active Dec 11, 2015
What would you like to do?
Mouseover Philadelphia Streets to See Citywide Extent (Simplified Geometry)

Mouseover streets in this D3.js-driven visualization that allows users to visualize the citywide extent of a given street. The City of Philadelphia Streets Department maintains and distributes geospatial data representing and describing the city's street network. The data along with more information is availabe at Open Data Philly. Street location and name data is stored in a CartoDB table. A merge by attribute operation, street name in this case, achieved improvements over the previous file size that approached 3MB.

Download size can be further reduced by using PostGIS functions ST_Simplify or ST_SimplifyPreserveTopology. Without significant loss of detail, file size is about 185KB (from ~600KB) at simplication level 0.0007.

<!DOCTYPE html>
<meta charset="utf-8">
.streets {
fill: none;
stroke: #aaa;
stroke-width: .5px;
stroke-linecap: round;
.streets:hover {
stroke: #f00;
stroke-width: 3px;
text {
font-family: sans-serif;
font-size: 50px;
<script src=""></script>
<script src=""></script>
var width = 960,
height = 500;
var projection = d3.geo.mercator()
.center([-75.12, 40])
var path = d3.geo.path()
var svg ="body").append("svg")
.attr("width", width)
.attr("height", height);
var text = svg.append("text")
.attr("y", height/10)
.attr("text-anchor", "left")
.text("mouseover streets");
d3.json(" name, ST_SimplifyPreserveTopology(the_geom,0.0007) as the_geom FROM streets", function(error, geojson) {
.attr("class", "streets")
.attr("id", function(d){return;})
.attr("d", path)
.on("mouseover", function(){text.text(;})
.on("mouseout", function(){text.text("");});
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This comment has been minimized.

Copy link

@wsvekla wsvekla commented Jan 30, 2013

you select the_geom as well as the_geom_webmercator which gets simplified. how do you know if the path function is reading the_geom or the simplified the_geom_webmercator?

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