decodeGeometry<T extends Geometry?> method

T? decodeGeometry<T extends Geometry?>()

Decode feature geometry data

By default geometry doesn't decoded So you must call this method on-demand if you need it!

Properties that was decoded through this method:

  • feature.geometryType
  • feature.geometry

You must explicit cast Geometry type after got returned data:

 var geometry = feature.decodeGeometry();
 var coordinates = (geometry as GeometryPoint).coordinates;

Implementation

T? decodeGeometry<T extends Geometry?>() {
  if (this.geometry != null) {
    return this.geometry as T?;
  }
  this.decodeProperties();

  switch (this.type) {
    case VectorTileGeomType.POINT:
      List<List<int>> coords = this.decodePoint();

      if (coords.length <= 1) {
        this.geometry = Geometry.Point(
            coordinates: coords[0]
                .map((intVal) => intVal.toDouble())
                .toList(growable: false));
        this.geometryType = GeometryType.Point;
        break;
      }

      this.geometry = Geometry.MultiPoint(
          coordinates:
              coords.map((coord) => coord.map((intVal) => intVal.toDouble()))
                  as List<List<double>>);
      this.geometryType = GeometryType.MultiPoint;
      break;
    case VectorTileGeomType.LINESTRING:
      List<List<List<int>>> coords = this.decodeLineString();

      if (coords.length <= 1) {
        this.geometry = Geometry.LineString(
            coordinates: coords[0]
                .map(
                  (point) => point
                      .map((intVal) => intVal.toDouble())
                      .toList(growable: false),
                )
                .toList(growable: false));
        this.geometryType = GeometryType.LineString;
        break;
      }

      this.geometry = Geometry.MultiLineString(
          coordinates: coords
              .map((line) => line
                  .map(
                    (point) => point
                        .map((intVal) => intVal.toDouble())
                        .toList(growable: false),
                  )
                  .toList(growable: false))
              .toList(growable: false));
      this.geometryType = GeometryType.MultiLineString;
      break;
    case VectorTileGeomType.POLYGON:
      List<List<List<List<int>>>> coords = this.decodePolygon();

      if (coords.length <= 1) {
        this.geometry = Geometry.Polygon(
            coordinates: coords[0]
                .map((ring) => ring
                    .map(
                      (point) => point
                          .map((intVal) => intVal.toDouble())
                          .toList(growable: false),
                    )
                    .toList(growable: false))
                .toList(growable: false));
        this.geometryType = GeometryType.Polygon;
        break;
      }

      this.geometry = Geometry.MultiPolygon(
          coordinates: coords
              .map((polygon) => polygon
                  .map((ring) => ring
                      .map(
                        (point) => point
                            .map((intVal) => intVal.toDouble())
                            .toList(growable: false),
                      )
                      .toList(growable: false))
                  .toList(growable: false))
              .toList(growable: false));
      this.geometryType = GeometryType.MultiPolygon;
      break;
    default:
      print('only implement point type');
  }

  return this.geometry as T?;
}