shp2json | convert shapefile zip archives to streaming GeoJSON
kandi X-RAY | shp2json Summary
kandi X-RAY | shp2json Summary
Convert shapefile zip archives to streaming GeoJSON using [gdal] and [JSONStream] Uses the [gdal native addon] for node.js. No compilation required on most platforms as pre-compiled binaries will be downloaded automatically when you run npm install shp2json.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Create a Stream from an svg file
- write the next feature
- gets the next layer in the map
shp2json Key Features
shp2json Examples and Code Snippets
Community Discussions
Trending Discussions on shp2json
QUESTION
I am having trouble mapping Nebraska school districts in D3 (v4). (See bl.ock here.) I can map Nebraska counties no problem, but the same code modified for school districts--and pointing to a school district TopoJSON file--gives me a blank page.
Here's how I created the JSON, based on Mike Bostock's excellent instructions :
...ANSWER
Answered 2019-Mar-05 at 16:29The issue is you haven't finished setting your projection parameters. You have rotate the map, which is how you should center a conic projection along the x axis. But you haven't centered the map on the y axis, it is centered on the equator. You
For a conical projection, you can do this one of three ways:
- Center the map on a central latitude :
projection.center([0,y])
You don't need to use .center with an x value because the map is already centered on the x by rotation, rotation and centering are cumulative
- Rotate the map to a central latitude and longitude:
projection.rotate([-x,-y])
On a conical projection the rotation on the meridian does not warp the map (generally), we rotate by the negative as we move the earth under us. This option does slightly distort the map relative to the other options - this may be preferrable.
- Use the projection translation to center the map
The easiest way is to translate the result while automatically scaling (though you can do this manually too) with projection.fitSize
or projection.fitExtent
. These methods modify projection.scale and projection.translate. As with centering with .center, you need to keep your rotation - otherwise you'll get an odd tilt to the map.
These methods set translate and scale to appropriate values so that your map area contains the desired features:
QUESTION
So, I've been following this tutorial https://bl.ocks.org/mbostock/4060606. Just copying and pasting his code directly allows me to see this functionality in action. However, I would like to do the same thing but at the state scale rather than the whole country. So I went to the census bureau's website and downloaded a shapefile for the counties of Missoui, but I'm having difficulty recreating Mike's TopoJSON file. In fact, I've been at this for days, messing around with TopoJSON, but all of the examples I've found use the deprecated topojson
command line tools. Since that doesn't exist anymore, I've been forced to figure out for myself how to generate in the same TopoJSON format, but with no luck. I simply cannot get a Shapefile into the same TopoJSON format that Mike uses in this tutorial.
So here is how I've been doing it. I'm getting my Shapefile from this website https://www.census.gov/geo/maps-data/data/cbf/cbf_counties.html and going to the Census 2000 tab (because I don't know how else to get only the counties for Missouri from this website) then selecting and downloading Missouri. I then unzip the downloaded file, then move the .shp
and .dbf
files to a separate folder. Then I run this command to produce the GeoJSON file:
ANSWER
Answered 2017-Dec-07 at 06:51There are a couple potential challenges in replicating this map for a single state and it appears you have run into a few of them. You will need to deviate from the example more than you have.
First, the geographic data your are downloading is composed of latitude longitude pairs - the geographic data the example uses is a pre-projected topojson that is sized to fit in a 960x600 Cartesian plane. You will need to either pre-project your data as well (similar to command line cartography part 1) or project your data on the fly within your block using a geoPath and a geoProjection. Mike does use a geoProjection in his block, a null geoProjection, the default geoProjection for a geoPath. The null projection simply takes coordinates in the json and uses them as svg coordinates with no transform.
Projection issues are probably the most common cause of seeing neither features nor errors. Since you didn't specify a projection, the features are likely rendered off screen. As the continental US sits in the western hemisphere, longitude values are negative - the US will be drawn to the left of the origin, ie off the screen, since you are using a null projection.
The second potential issue for you is that your data has different attributes than the example:
I thought that my TopoJSON file would have attributes like the 'id' attribute that contains the FIPS codes for the counties
The feature attributes of your topojson:
QUESTION
I am doing @mbostock's tutorial on Command Line Cartography 1. Here is what I've done:
1) Download the zip file
wget https://www.arb.ca.gov/ei/gislib/gislib.htm/ca_air_basins.zip
(from California Air Resources Board site)
2) Manually unzip by clicking .zip
file (unzip
command did not work because downloaded file didn't have 'End-of-central-directory signature')
2) Convert a shapefile to GeoJSON
shp2json CaAirBasin.shp -o ca.json
3) Make a GeoJSON projection using California Albers (specified in CaAirBasin.prj
file):
geoproject 'd3.geoConicEqualArea().parallels([34, 40.5]).rotate([120, 0]).fitSize([960, 960], d)' < ca.json > ca-albers.json
Result:
I get ca-albers.json
(223M) that is much bigger than ca.json
(6.3M). In the census tract shapefile used in the tutorial, the file size increases from 10 to 14 M.
Update:
It seems that problem is with shp2json
step instead of geoProject
step. Looking at CaAirBasin.shp.xml,
there are two sets of bounding,bounding
and lbounding.
In my case,lbounding
and coordinate values that are in 100,000s range is used as opposed to (-180, 180) in the tutorial, making projection fail.
What is a good next step - is there an alternative to shp2json
that will work for my case? OR how can I translate my bounding/coordinates to appropriate (-180,180) ones?
Thank you.
...ANSWER
Answered 2017-Apr-14 at 20:40Your shapefile is already projected. By passing it through d3.geoConicEqualArea, you are projecting it twice; d3.geoConicEqualArea expects WGS84 (longitude and latitude in degrees) as input, but you’re giving it projected coordinates.
You can tell that your shapefile is projected by looking at the PRJ file, or by looking at the coordinates of the geometry generated by shp2json: the first point is [-298228.39936644124, 437516.87775637675], which is well outside the expected range of [±180°, ±90°] for longitude and latitude.
Rather than re-projecting your geometry to a new projection, the easiest thing to do is to just use the projection it’s already in. All you need to do is to translate and scale to fit the desired display size of 960×960. You can use d3.geoIdentity for this.
QUESTION
I'm trying to follow the tutorial Mike Bostock did for Command Line Cartography (which is a great help). Right after installing shapefile and running the shp2json step [shp2json cb_2014_06_tract_500k.shp -o ca.json] I get this error message: “error: Decoder not present. Did you forget to include encoding-indexes.js first?” an error message which originates from the text-encoding package from NPM.
In trying to diagnoise the problem, I figured I should manually install text-encoding as it's in the shp2json dependency list but, didn't appear to be loading. I also reinstalled node to downgrade from 7.3.0 to 6.9.2 and a number of other things (my hacking around looking for a solution for a few hours) but, am stuck. Is this just a matter of updating a package.json?
I’m using Windows7, the env variables is set I believe correctly to \Users\myAccount\AppData\Roaming\npm. I’ve installed all packages globally as well. Thanks for any insight.
...ANSWER
Answered 2017-Jan-02 at 03:01I had the same problem when running the "#prepublish" script here. Then I noticed that Mike's shapefile repo has this information in the README:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install shp2json
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page