Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9037425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:14:35+00:00 2026-06-16T09:14:35+00:00

here is the first topojson question on so. I am having problems rendering a

  • 0

here is the first topojson question on so. I am having problems rendering a map (NYC boroughs) and can’t figure out why. The code below is just a copy of this example with a different topojson file. I have uploaded the file here. Below are also the details about how I created the file. Right now, I am just getting chaotic lines. Probably, the reason is the topojson file but I don’t know what’s wrong.

ps: I was unable to tag this as topojson because the tag has not been used before

TopoJSON file

1) Download shapefile from here

(Under “Borough & Community Districts” the file “Boroughs” (left), ArcView Shapefile)

2) Simplify shapefile with QGis

3) Convert to TopoJSON with

ogr2ogr -f geoJSON nybb-geo.json nybb.shp
topojson -o nybb.json nybb-geo.json

HTML/JS Code

<!DOCTYPE html>
<meta charset="utf-8">
<style>

.boundary {
  fill: none;
  stroke: #000;
  stroke-width: .5px;
}

</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/topojson.v0.min.js"></script>
<script>

var width = 960,
    height = 500;

var path = d3.geo.path();

var svg = d3.select("body").append("svg")
    .attr("width", width)
    .attr("height", height);

d3.json("/geo/nybb.json", function(error, topology) {
  svg.append("path")
      .datum(topojson.object(topology, topology.objects['nybb-geo'].geometries[0]))
      .attr("d", path)
      .attr("class", "boundary");
});

</script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T09:14:36+00:00Added an answer on June 16, 2026 at 9:14 am

    As also suggested by user 10579’s comment, I was able to solve the problem by re-projecting the shapefile to NAD83 (EPSG 4269). After creating the topojson file from the reprojected shapefile, d3.js shows the map with

    var projection = d3.geo.albers();
    var path = d3.geo.path().projection(projection);
    

    The second problem I encountered was related to the correct center, scale, and translate values. With the code above nyc will just be a small dot with a lot of white space. Finding the correct center, scale, and translate values can be a little tedious. In the end, I added the code below, which allows you to drag and drop the map around and scroll to change the scale parameter. The values are displayed after each change so that it’s easy to put the map in the right location and just adopt the last parameters from the console output.

      svg.call(d3.behavior.zoom()
              .translate(projection.translate())
              .scale(projection.scale())
              .on("zoom", redraw));
    
      function redraw() {
          if (d3.event) {
            projection
              .translate(d3.event.translate)
              .scale(d3.event.scale);
          }
          map.datum(topojson.object(topology, topology.objects.nyct2010))
            .attr("d", path)
            .attr("class", "boundary");
          console.log("Current scale:" + projection.scale())
          console.log("Current translate:" + projection.translate())
          console.log("Current rotate:" + projection.rotate())
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

my first question here! I have a problem with a piece of code that
First Question in here :) (AS3) First off, how do I access a variable
This is my first here in Stackoverflow. So I just want to ask question
Here is the first part of my controller code: public class ControlMController : Controller
Don't know if maybe this question belongs on serverfault, but I'll try here first.
This is not a traditional scale-up or scale-out question. Please bear with me, here
I'm going to bang out a couple of questions here...first, with NuGet is it
Good day, I have like 2 question here: First a background information. from the
Borderline ServerFault question, but figured I'd try here first since I've had luck with
First here's what I'm using and trying to do: the minimal setup for this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.