Search code examples
topojson

Valid Topojson and https://mapshaper.org/


All 3 cases validate in jsonlint, but only the first one is displayed in mapshaper.

I do not understand why case 2 and 3 are not displayed .

So how can I set up this correct using '-' in the arcs ref for a property ?

  1. Displays OK in https://mapshaper.org/
    {"type":"Topology", "crs":{"type":"name","properties":{"name":"EPSG:25832"}},"objects":{"collection": { "type": "GeometryCollection", "geometries":[
    { "type": "MultiPolygon", "arcs": [[[0,1]]],"properties":{"id":9005309}}]}},"arcs": 
    [
    [[565546,7786890.97],[565545.69,7786859.81]],
    [[565545.69,7786859.81],[565545.06,7786876.95],[565546,7786890.97]]]
    }
  1. Does not displays in https://mapshaper.org/

    {"type":"Topology", "crs":{"type":"name","properties":{"name":"EPSG:25832"}},"objects":{"collection": { "type": "GeometryCollection", "geometries":[
    { "type": "MultiPolygon", "arcs": [[[-0,-1]]],"properties":{"id":9005309}}]}},"arcs":
    [
    [[565545.69,7786859.81],[565546,7786890.97]],
    [[565546,7786890.97],[565545.06,7786876.95],[565545.69,7786859.81]]
    ]
    }
  1. Does not displays in https://mapshaper.org/
    {"type":"Topology", "crs":{"type":"name","properties":{"name":"EPSG:25832"}},"objects":{"collection": { "type": "GeometryCollection", "geometries":[
    { "type": "MultiPolygon", "arcs": [[[-0,1]]],"properties":{"id":9005309}}]}},"arcs": 
    [
    [[565545.69,7786859.81],[565546,7786890.97]],
    [[565545.69,7786859.81],[565545.06,7786876.95],[565546,7786890.97]]]
    }

Solution

  • You have the wrong index for negative (/reversed) arcs:

    Each arc must be referenced by numeric zero-based index into the containing topology’s arcs array. For example, 0 refers to the first arc, 1 refers to the second arc, and so on.

    A negative arc index indicates that the arc at the ones’ complement of the index must be reversed to reconstruct the geometry: -1 refers to the reversed first arc, -2 refers to the reversed second arc, and so on. In JavaScript, you can negate a negative arc index i using the bitwise NOT operator, ~i. (docs)

    Instead of -0 you should be using -1. So your 2nd topojson example should draw as follows:

    {"type":"Topology", 
            "crs":{"type":"name","properties": {"name":"EPSG:25832"}},
            "objects":{
            "collection": { "type": "GeometryCollection", 
                 "geometries":[
                       { "type": "MultiPolygon", 
                         "arcs": [[[-1,-2]]],
                         "properties":{"id":9005309}}]}},
            "arcs":[
                  [[565545.69,7786859.81],[565546,7786890.97]],
                  [[565546,7786890.97],[565545.06,7786876.95],[565545.69,7786859.81]]
            ]
    }