NetTopologySuite / NetTopologySuite.IO.GeoJSON

GeoJSON IO module for NTS.
BSD 3-Clause "New" or "Revised" License
111 stars 46 forks source link

Expose Converters, Implement TopoJson #73

Closed juliusfriedman closed 3 years ago

juliusfriedman commented 3 years ago

See https://github.com/topojson/topojson

There is already an implementation which was using Newtonsoft @ https://github.com/Freddixx/TopoJSON.Net

Looking at the converters provided it seems that StjFeatureConverter is internal and the expected use case is to use the GeoJsonConverterFactory.

Since the GeoJsonConverterFactory supports working with Geometry and Feature and then FeatureCollection it seems like it would make sense to expose them for use from other converters which derive from the GeoJsonConverterFactory.

An example of topojson is as follows:

{
  "type": "Topology",
  "objects": {
    "example": {
      "type": "GeometryCollection",
      "geometries": [
        {
          "type": "Point",
          "properties": {
            "prop0": "value0"
          },
          "coordinates": [102, 0.5]
        },
        {
          "type": "LineString",
          "properties": {
            "prop0": "value0",
            "prop1": 0
          },
          "arcs": [0]
        },
        {
          "type": "Polygon",
          "properties": {
            "prop0": "value0",
            "prop1": {
              "this": "that"
            }
          },
          "arcs": [[-2]]
        }
      ]
    }
  },
  "arcs": [
    [[102, 0], [103, 1], [104, 0], [105, 1]],
    [[100, 0], [101, 0], [101, 1], [100, 1], [100, 0]]
  ]
}

Same example only quantized:

{
  "type": "Topology",
  "transform": {
    "scale": [0.0005000500050005, 0.00010001000100010001],
    "translate": [100, 0]
  },
  "objects": {
    "example": {
      "type": "GeometryCollection",
      "geometries": [
        {
          "type": "Point",
          "properties": {
            "prop0": "value0"
          },
          "coordinates": [4000, 5000]
        },
        {
          "type": "LineString",
          "properties": {
            "prop0": "value0",
            "prop1": 0
          },
          "arcs": [0]
        },
        {
          "type": "Polygon",
          "properties": {
            "prop0": "value0",
            "prop1": {
              "this": "that"
            }
          },
          "arcs": [[1]]
        }
      ]
    }
  },
  "arcs": [
    [[4000, 0], [1999, 9999], [2000, -9999], [2000, 9999]],
    [[0, 0], [0, 9999], [2000, 0], [0, -9999], [-2000, 0]]
  ]
}

The main types which would need support are:

Arc and CoordinateReferenceSystem which are just Features which specific properties.

The most basic definition of Arc would be something like this:


public class Arc
    {
        /// <summary>
        /// The positions.
        /// </summary>
        public List<NetTopologySuite.Geometries.Point> Positions { get; set; }

        /// <summary>
        /// Constructs an arc from a given list of positions. The must be at least two positions.
        /// </summary>
        /// <param name="positions">The positions.</param>
        public Arc(List<NetTopologySuite.Geometries.Point> positions)=> this.Positions = positions;

        /// <summary>
        /// Default constructor.
        /// </summary>
        public Arc() => Positions = new();
    }
FObermaier commented 3 years ago

See and engage with NetTopologySuite.IO.TopoJson