mbloch / mapshaper

Tools for editing Shapefile, GeoJSON, TopoJSON and CSV files
http://mapshaper.org
Other
3.74k stars 532 forks source link

Questions about dissolve2 #581

Closed eric-g-97477 closed 1 year ago

eric-g-97477 commented 1 year ago

Let's say I have the following data:

(test.geo.json)

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [-170, 45],
            [-160, 45],
            [-160, 30],
            [-170, 30],
            [-170, 45]
          ]
        ]
      },
      "properties": {
        "JOIN": "a"
      }
    },
    {
      "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [-150, 45],
            [-140, 45],
            [-140, 30],
            [-150, 30],
            [-150, 45]
          ]
        ]
      },
      "properties": {
         "JOIN": "a"
      }
    },
    {
      "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [-130, 45],
            [-120, 45],
            [-120, 30],
            [-130, 30],
            [-130, 45]
          ]
        ]
      },
      "properties": {
         "JOIN": "c"
      }
    }
  ]
}

Is it possible to merge a & b by creating an enclosing polygon? i.e. the a & b features would disappear and be replaced by:

    {
      "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [-170, 45],
            [-140, 45],
            [-140, 30],
            [-170, 30],
            [-170, 45]
          ]
        ]
      },
      "properties": {
         "id": "???"
      }
    },

I thought this is what gap-fill-area might be able to do, but even with large values, it does not.

mbloch commented 1 year ago

The -dissolve2 gap-fill-area= option is designed to fill in gaps between adjacent rings that are fully bounded by the rings -- in other words, holes between two adjacent rings. In your example, the gap between the two rings is open, not bounded. Mapshaper can convert a polygon feature into a bounding rectangle using the -rectangles command, but it doesn't sound like this is what you want to do.