Alter GeoJSON output to be one feature

exportgeojson

I'm using MapBox, and in sending it the data to highlight part of a map, e.g. Alaska, it expects a single feature with a single multi polygon of lat/long points. Here is an example of the format expected by the software that is submitting the data to MapBox: two different regions combined within one feature:

{
"type": "Feature",
"id": "91",
"properties": {
"name": "SCal and Hawaii",
"id": "91",
"type": "domestic",
"color": "#F9C74F"
},
"geometry": {
"type": "MultiPolygon",
"coordinates": [
[[[-114.6306,33.4442],[-114.7055,33.4039],[-114.6973,33.3546],[-114.7302,33.3041],[-114.7206,33.2858],[-114.6808,33.2754],[-114.6698,33.2582],[-114.6904,33.2467],[-114.6794,33.172],[-114.7083,33.0904],[-114.6918,33.0858],[-114.6629,33.0328],[-114.6451,33.0501],[-114.6286,33.0305],[-114.5888,33.0282],[-114.575,33.0351],[-114.5174,33.0328],[-114.4913,32.9718],[-114.4775,32.9764],[-114.4844,32.9372],[-114.4679,32.8427],[-114.5091,32.8161],[-114.5311,32.785],-114.5284,32.7573],[-114.5641,32.7503],[-114.6162,32.7353],[-114.6986,32.748],[-114.722,32.7191],[-115.1944,32.6868],[-117.3395,32.5121],[-117.4823,32.7838],[-117.5977,33.0501],[-117.6814,33.2341],[-117.6013,33.4372],[-117.4915,33.5105],[-117.2388,33.4372],[-114.6306,33.4442]]],
[[[-154.6284,19.5158],[-154.8235,19.8894],[-155.0391,20.1849],[-155.5952,20.391],[-155.793,20.8614],[-156.1858,21.0948],[-156.6595,21.3597],[-157.1182,21.4748],[-157.5247,21.5515],[-157.8186,21.8832],[-159.218,22.3386],[-159.7508,22.3374],[-160.1422,22.1493],[-160.3922,21.8857],[-160.3249,21.6025],[-159.9939,21.7276],[-159.4295,21.6932],[-158.1784,21.1037],[-157.4629,20.8152],[-157.2171,20.6803],[-156.8285,20.3408],[-156.5456,20.2931],[-156.1418,20.1643],[-156.2393,19.9308],[-156.1432,19.2826],[-156.1212,18.9881],[-155.712,18.71],[-155.3673,18.8829],[-154.8839,19.2048],[-154.6271,19.5158]]]]}}

what I get in the GeoJson export from QGIS for Alaska is a collection of features. I'm pasting the start of it because its format is repetitive from that point on, and it's more data than is allowed here.

"type": "FeatureCollection",
"name": "alaska4",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [
{ "type": "Feature", "properties": { "cat": 1 }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ -156.452403749605935, 71.388095837243625 ], [ -156.447705761247761, 71.389377625073266 ], [ -156.361490245287172, 71.366171267346502 ], [ -156.452403749605935, 71.388095837243625 ] ] ] ] } },
{ "type": "Feature", "properties": { "cat": 2 }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ -155.676222906567148, 71.251142597169078 ], [ -155.644971284798913, 71.245182333108119 ], [ -155.696795236784965, 71.246404534101174 ], [ -155.676222906567148, 71.251142597169078 ] ] ] ] } },
{ "type": "Feature", "properties": { "cat": 3 }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ -155.539178411002098, 71.238970483605016 ], [ -155.443426155083614, 71.214015484758292 ], [ -155.575022513505246, 71.237000697138939 ], [ -155.539178411002098, 71.238970483605016 ] ] ] ] } },
{ "type": "Feature", "properties": { "cat": 4 }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ -155.599298707914528, 71.009191434693349 ], [ -155.614639169800938, 70.995398137578647 ], [ -155.61601991665728, 71.021019646604472 ], [ -155.599298707914528, 71.009191434693349 ] ] ] ] } },
{ "type": "Feature", "properties": { "cat": 5 }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ -158.980032486957356, 70.890571869063933 ], [ -159.105458208671905, 70.883756730141684 ], [ -158.809066338853484, 70.914524356418355 ], [ -158.980032486957356, 70.890571869063933 ] ] ] ] } },

Is there any way to generate the export so that it's one feature with multi polygons?

Best Answer

You can use the Collect Geometries tool to put all the features into a single MultiPolygon type: feature. Then export again as a Geojson and you should get the desired results that you depicted above.

enter image description here