developmentseed / dirty-reprojectors

Make quick and dirty projections to use in your web maps instead of Web Mercator
https://www.developmentseed.org/dirty-reprojectors-app/
MIT License
120 stars 10 forks source link

Albers US- merged geometries and border box in output #13

Open brambow opened 6 years ago

brambow commented 6 years ago

Apologies in advance for a use question rather than code issue:

I'm trying to get an Albers US projection of the US States to upload to Mapbox, but the output of the cli tool seems to merge state geometries together as well as adding a bounding box (which also appears to be a part of each feature's geometry).

Original Dataset (EPSG: 4326) image

Dirty Reprojection Output: image

Looks great, but the feature geometries are all merged together as well as with the border boxes, so individual attributes for a state can't really be queried. Is there a way to prevent this and/or to prevent these border boxes from being created?

Image below: I tried selecting a single state. image

brambow commented 6 years ago

I think this had something to do with the input geojson, or at least how this tool was reading it. I verified it was valid geojson via geojson.io; however, I tried with another source of the same data and got a slightly different result.

In the end, I used mapshaper to export a copy of the original source geojson, and running it through that seemed to fix the issues. No more border box and all the features are individual geometries. Still curious though.

dereklieu commented 6 years ago

Hm that is strange. For reference, where are you sourcing this input geojson?

brambow commented 6 years ago

It was from a client, so I don't know for certain. My guess would be it's from the US Census Bureau. I can provide it (stripped of attributes) if needed.

To test, I downloaded data from the Census Bureau myself (states_5m.shp), converted to geojson, and ran it through the CLI. The first time I did that, it worked better, but several states were missing from the output. I just tried it again, and am getting the same error as Issue #11, but the input geojson checks out in geojson.io and qgis.

I'm going to keep playing around with this to see if I can consistently reproduce the issue, but running the original geojson I got from my client through mapshaper (without any manipulation) seemed to fix things.

If it helps, i'm using Node 8.11.1, but also tried on 6.11

brambow commented 6 years ago

When I used the geojson I create from data downloaded from the census, the tool spits out the error from Issue #11; however, an output dataset is created. It seems that one of the state geometries stops the tool from completing the write process though - the JSON ends up incomplete/invalid, but if I add a ']}' to the end of what is written, I can add it to qgis/geojson.io and see that some of the states didn't write: image

Maybe there's an issue parsing Multipolygon geometries? I haven't had any issues reprojecting points.

brambow commented 6 years ago

I figured out the issue above (not the original issue though - which I'm chalking up to something wrong with the dataset I got from my client).

When you download States from the Census Bureau, they include territories (guam, puerto rico, american samoa, etc.). Since I was dirty projecting to Albers US, those territories aren't supported. That was causing the TypeError: Cannot read property 'type' of null found in Issue 11. Removing the extra 5 territories from the input geojson fixed that error.

dereklieu commented 6 years ago

Ah that makes a lot of sense. Thanks for looking into this. I'll add a note about this in the README.

jfrankl commented 4 years ago

I'm running into the issue described in the original post. Curiously, when I use the state file from the dirty-reprojector repo, it works great. When I import that same file into MapShaper, export as GeoJSON, and then use it, I get the error.

The two GeoJSON files, when loaded in geojson.io, look identical. But after running dirty-reproject, only one looks as expected. I am getting this same error from other polygon layers exported from MapShaper, as well.

Command I am running: cat [input] | dirty-reproject --forward albersUsa > [output]

jfrankl commented 4 years ago

Here's another example that might be useful. I drew a single rectangle in geojson.io. simple-polygon.geojson.zip

image

When I upload this on the Dirty Reprojectors website, I expect to receive a single polygon that has been reprojected. Instead, I receive many LineStrings. projected-geometry.geojson.zip

Any projection—AlbersUS and others—seems to run into this same issue.

image

cedricsam commented 4 years ago

Regarding the original border-box problem, I also experienced it and I think it's ultimately something to do with the GeoJSON standard used.

At first, I thought it was my input file (was originally using a 2016 census counties shapefile, and then 2019, but it wasn't that) or the dirty-reprojectors version (tried the one in npm and the one here on GitHub just updated today with the the Albers for U.S. territories (https://github.com/developmentseed/dirty-reprojectors/commit/fc7c8d51dd03419773ef36618c6dba95d1735b0c), but wasn't that either). Then I remembered I just happened to have upgraded my mapshaper from v0.4.139 to the latest (v0.5.11) while generating a new batch of geojsons to upload to Mapbox.

It turns out that switching back to my old v0.4 mapshaper eliminated the problem. And then I pinpointed the change in mapshaper that would end up producing these dirty-reprojected with the border-box to mapshaper@0.5.6, when RFC 7946-compliant GeoJSONs became default with mapshaper.

Story short, by using the suggested -o gj2008 flag in the latest mapshaper worked for me. If you aren't using mapshaper, then maybe just try using a GeoJSON that isn't RFC 7946?

jfrankl commented 4 years ago

Thanks @cedricsam. I tried this out with mapshaper and -o gj2008 worked for me too.

erichsen69 commented 3 years ago

this is the solution. thank you. my workflow: (1) mapshaper shapefile to geojson (use '-o gj2008' as export option) (2) dirty-reproject in node.js to convert said geojson to AlbersUS (3) upload to mapbox as tileset

type states.json | dirty-reproject --forward albersUsa > states_abersUS.geojson

https://i.imgur.com/FFrGjkf.png