Multi Polygon to Polygon

29 views
Skip to first unread message

PBS

unread,
Nov 20, 2017, 4:51:33 PM11/20/17
to mongodb-user
Hi,
 I have GeoJson data in the collection loaded as feature with documents mix of type Polygon and MultiPolygon. I want to convert all the MultiPolygon to Polygon geometry. 
Please find below sample structure:
MultiPolygon:
{"_id":"tmpolygon","geometry":{"coordinates":[[[[-71.761012,44.407034],[-71.756092,44.406401],[-71.761012,44.407034]]],[[[-68.960075,44.100967],[-68.938785,44.123521],[-68.960075,44.100967]]]],"type":"MultiPolygon"},"properties":{"CODE":"xxx","LABEL":"yyy","NAME":"abc"},"type":"Feature"}

Polygon:
{"_id":"tpolygon","geometry":{"coordinates":[[[-85.945558,41.04287],[-85.926331,41.042594],[-85.945558,41.04287]]],"type":"Polygon"},"properties":{"CODE":"xxxx","LABEL":"yyyy","NAME":"ABC"},"type":"Feature"}

Is there any way using mongo query I can convert multipolygon to polygon? Appreciate in advance for any help.

Wan Bachtiar

unread,
Nov 28, 2017, 11:48:47 PM11/28/17
to mongodb-user

Is there any way using mongo query I can convert multipolygon to polygon?

Hi,

You can utilise update() to update the documents; filtering the MultiPolygon and updating them into Polygon.

Note that in order to convert GeoJSON MultiPolygon to Polygon you may have to remove some data (polygon coordinates). You would have to come up with a logic on which polygon(s) information to keep/discard.

Regards,
Wan.

Reply all
Reply to author
Forward
0 new messages