import { MongooseModule, } from "../../helpers"; import { GeoMultiPolygon, GeoPoint, GeoPolygon, } from "../../types/geojson"; export function GeoPointSchema(mongoose: MongooseModule) { const { Schema } = mongoose; const s = new Schema({ type: { type: String, required: true, enum: ["Point"], default: "Point", }, coordinates: { type: [Number], required: true, default: [], }, }, { _id: false, id: false, }); return s; } export function GeoPolygonSchema(mongoose: MongooseModule) { const { Schema } = mongoose; const s = new Schema({ type: { type: String, enum: ["Polygon"], default: "Polygon", required: true }, coordinates: { // Array of arrays of arrays of arrays of arrays of numbers of number[][][] // Polygon already supports multiple areas (rings) type: [[[Number]]], required: true }, }, { _id: false, id: false, }); return s; } // https://www.geopostcodes.com/blog/geojson-multipolygon/ export function GeoMultiPolygonSchema(mongoose: MongooseModule) { const { Schema } = mongoose; const s = new Schema({ type: { type: String, enum: ["MultiPolygon"], default: "MultiPolygon", required: true }, coordinates: { type: [[[[Number]]]], // Array of arrays of arrays of arrays of arrays of numbers number[][][][] required: true }, }, { _id: false, id: false, }); return s; }