Shp2json produces GeoJSON with constraint and coordinates not in (-180,180) range

I'm doing @mbostock command line mapping tutorial 1. Here's what I did:

1) Download the zip file

wget https://www.arb.ca.gov/ei/gislib/gislib.htm/ca_air_basins.zip

(from Air Resources Board of Directors website )

2) Manually unzip by clicking the .zip

file (the command unzip

does not work because the downloaded file did not have a "signature under the central directory")

2) Convert shapefile to GeoJSON shp2json CaAirBasin.shp -o ca.json

3) Make a GeoJSON projection using California Albers (listed in the file CaAirBasin.prj

):

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), which is much larger than ca.json

(6.3M). In the census shapefiles used in the tutorial, the file size increases from 10 to 14 M.

Update : It seems that the problem is with the step shp2json

instead of the step geoProject

. Looking at CaAirBasin.shp.xml,

, there are two sets of restrictions: bounding

and lbounding.

. In my case lbounding

and coordinate values ​​that are in the 100,000s range are used as opposed to (-180, 180) in the tutorial, projection failure.

Which is a good next step - is there an alternative shp2json

that will work for my case? OR how can I translate my bounding / coordinates to the appropriate (-180,180)?

Thank.

+3


source to share


1 answer


Your shapefile is already being projected. By running it through d3.geoConicEqualArea, you project it twice; d3.geoConicEqualArea expects WGS84 (longitude and latitude in degrees) as input, but you give it the projected coordinates.

You can tell that your shapefile is being projected by viewing the PRJ file, or by viewing the geometry coordinates generated by shp2json: the first point is [-298228.39936644124, 437516.87775637675], which is outside the expected range of [Β± 180 Β°, Β± 90 Β°] in longitude and latitude.

Instead of redesigning your geometry to a new projection, the simplest thing is to just use the projection you already made. All you have to do is translate and scale to fit your desired 960x960 screen size, you can use d3.geoIdentity for this.



geoproject 'd3.geoIdentity().reflectY(true).fitSize([960, 960], d)' < ca.json > ca-albers.json

      

The identity.reflectY setting will also fix the vertical orientation of the geometry: the GIS convention is that + y points up, but the Canvas and SVG convention that + y points down.

+6


source







All Articles