mongoose-geojson-schema icon indicating copy to clipboard operation
mongoose-geojson-schema copied to clipboard

Failing to validate a GeometryCollection inside a Feature

Open pandres95 opened this issue 6 years ago • 4 comments

I'm trying to add the following object to mongoose

{
    "name": "Edificio Roberto Franco",
    "key": "Gb",
    "address": {
        "line1": "Cra. 1 # 18A - 12",
        "city": "Santa Fe",
        "state": "Bogotá DC",
        "country": "Colombia",
        "geolocation": {
            "coordinates": [
                -74.06639482,
                4.601515
            ],
            "type": "Point"
        }
    },
    "polygon": {
        "type": "Feature",
        "geometry": {
            "type": "GeometryCollection",
            "geometries": [
                {
                    "type": "Polygon",
                    "coordinates": [
                        [
                            [
                                -74.065899,
                                4.601595,
                                0
                            ],
                            [
                                -74.066125,
                                4.601672,
                                0
                            ],
                            [
                                -74.066135,
                                4.601643,
                                0
                            ],
                            [
                                -74.066159,
                                4.601566,
                                0
                            ],
                            [
                                -74.066158,
                                4.601566,
                                0
                            ],
                            [
                                -74.065986,
                                4.601464,
                                0
                            ],
                            [
                                -74.065942,
                                4.601531,
                                0
                            ],
                            [
                                -74.065928,
                                4.601532,
                                0
                            ],
                            [
                                -74.065928,
                                4.601552,
                                0
                            ],
                            [
                                -74.065899,
                                4.601595,
                                0
                            ]
                        ]
                    ]
                },
                {
                    "type": "Polygon",
                    "coordinates": [
                        [
                            [
                                -74.065993,
                                4.601765,
                                0
                            ],
                            [
                                -74.066032,
                                4.601641,
                                0
                            ],
                            [
                                -74.065899,
                                4.601595,
                                0
                            ],
                            [
                                -74.065854,
                                4.601661,
                                0
                            ],
                            [
                                -74.065993,
                                4.601765,
                                0
                            ]
                        ]
                    ]
                }
            ]
        },
        "properties": {
            "styleUrl": "#poly-FFEA00-1200-76",
            "styleHash": "-26c96a1f",
            "styleMapHash": {
                "normal": "#poly-FFEA00-1200-76-normal",
                "highlight": "#poly-FFEA00-1200-76-highlight"
            },
            "description": "FID   30    <br>   OBJECTID_1   31    <br>   BLOQUE   Gb    <br>   FOTO   c:\\proyectos\\sigcampus\\graficos\\imagenes\\bloques\\Gb.jpg    <br>   AREA   556,780195    <br>   PERIMETER   137,657    <br>   HECTARES   0,056    <br>   Sotanos       <br>   Shape_Leng   137,657271    <br>   Tratamient   reestructuración    <br>   mov_reduci   Completa    <br>   AREA_ÚTIL   2686    <br>   FID_sala_s   0    <br>   Name       <br>   FID_Bloque   0    <br>   USO       <br>   Oport_2048       <br>   existente       <br>   Estrategia       <br>   tipo       <br>   FID_bloq_1   0    <br>   BLOQUE_1       <br>   FOTO_1       <br>   AREA_1   0    <br>   PERIMETE_1   0    <br>   HECTARES_1   0    <br>   Sotanos_1       <br>   TIPO_1       <br>   Demolicion       <br>   Shape_Le_1   0    <br>   Shape_Ar_1   0    <br>   FID_Bloq_2   0    <br>   BLOQUE_12       <br>   FOTO_12       <br>   AREA_12   0    <br>   PERIMETE_2   0    <br>   HECTARES_2   0    <br>   Sotanos_12       <br>   Shape_Le_2   0    <br>   Shape_Ar_2   0    <br>   BLOQUE_PRO       <br>   Nombre       <br>   bloque_id       <br>   Estado       <br>   FID_Bloq_3   0    <br>   OBJECTID_2   0    <br>   BLOQUE__13       <br>   FOTO_12_13       <br>   AREA_12_13   0    <br>   PERIMETE_3   0    <br>   HECTARES_3   0    <br>   Sotanos_13       <br>   Shape_Le_3   0    <br>   Shape_Ar_3   0    <br>   Tratamie_1       <br>   mov_redu_1       <br>   USO_1       <br>   Oport_2049       <br>   existent_1       <br>   Estrateg_1       <br>   tipo_12       <br>   Shape_Le_4   137,657201",
            "stroke": "#ffea00",
            "stroke-opacity": 1,
            "stroke-width": 1.2,
            "fill": "#ffea00",
            "fill-opacity": 0.2980392156862745
        }
    },
    "entrypoints": {
        "type": "FeatureCollection",
        "features": [
            {
                "type": "Feature",
                "geometry": {
                    "type": "Point",
                    "coordinates": [
                        -74.065987,
                        4.60144,
                        0
                    ]
                },
                "properties": {
                    "name": "Conexión B - Gb",
                    "styleUrl": "#icon-1739-BDBDBD-labelson",
                    "styleHash": "-312153aa",
                    "icon": "http://www.gstatic.com/mapspro/images/stock/503-wht-blank_maps.png",
                    "description": "Conexión B - Gb    <br>       <br>   FID   266    <br>   NOMBRE   Conexión B - Gb    <br>   PISO   0    <br>   BLOQUE   TRANS    <br>   AREA   21,078034    <br>   CONCENTRAC   0    <br>   CAP   0"
                }
            }
        ]
    }
}

This is the Schema:

{
    name: {
        type: String,
        required: true
    },
    key: {
        type: String,
        required: true
    },
    address: {
        type: Schema.Types.Mixed,
        ref: 'Address',
        required: true
    },
    polygon: {
        type: Schema.Types.Feature,
        required: true
    },
    innerNodes: Schema.Types.FeatureCollection,
    entrypoints: {
        type: Schema.Types.FeatureCollection,
        required: true
    }
}

And I'm getting the following error:

2018-04-11T18:18:36-0500 <error> migrate.js:422 (require.then.then.catch.e) { ValidationError: Building validation failed: polygon: Cast to Feature failed for value "{ type: 'Feature',
  geometry: 
   { type: 'GeometryCollection',
     geometries: [ [Object], [Object] ] },
  properties: 
   { styleUrl: '#poly-FFEA00-1200-76',
     styleHash: '-26c96a1f',
     styleMapHash: 
      { normal: '#poly-FFEA00-1200-76-normal',
        highlight: '#poly-FFEA00-1200-76-highlight' },
     description: 'FID 30',
     stroke: '#ffea00',
     'stroke-opacity': 1,
     'stroke-width': 1.2,
     fill: '#ffea00',
     'fill-opacity': 0.2980392156862745 } }" at path "polygon"
    at ValidationError.inspect (/Users/pa.dorado/Documents/Development/AgentOwl/api/node_modules/mongoose/lib/error/validation.js:57:23)
    at formatValue (util.js:430:38)
    at Object.inspect (util.js:324:10)
    at Object.exports.format (/Users/pa.dorado/Documents/Development/AgentOwl/api/node_modules/tracer/lib/utils.js:22:22)
    at logMain (/Users/pa.dorado/Documents/Development/AgentOwl/api/node_modules/tracer/lib/console.js:49:25)
    at Object._self.(anonymous function) [as error] (/Users/pa.dorado/Documents/Development/AgentOwl/api/node_modules/tracer/lib/console.js:140:12)
    at require.then.then.catch.e (/Users/pa.dorado/Documents/Development/AgentOwl/api/scripts/database/migrate.js:422:9)
    at <anonymous>:null:null
    at process._tickCallback (internal/process/next_tick.js:188:7)

  errors: 
   { polygon: 
      { CastError: Cast to Feature failed for value "{ type: 'Feature',
  geometry: 
   { type: 'GeometryCollection',
     geometries: [ [Object], [Object] ] },
  properties: 
   { styleUrl: '#poly-FFEA00-1200-76',
     styleHash: '-26c96a1f',
     styleMapHash: 
      { normal: '#poly-FFEA00-1200-76-normal',
        highlight: '#poly-FFEA00-1200-76-highlight' },
     description: 'FID 30',
     stroke: '#ffea00',
     'stroke-opacity': 1,
     'stroke-width': 1.2,
     fill: '#ffea00',
     'fill-opacity': 0.2980392156862745 } }" at path "polygon"
    at new CastError (/Users/pa.dorado/Documents/Development/AgentOwl/api/node_modules/mongoose/lib/error/cast.js:27:11)
    at model.$set (/Users/pa.dorado/Documents/Development/AgentOwl/api/node_modules/mongoose/lib/document.js:773:7)
    at model._handleIndex (/Users/pa.dorado/Documents/Development/AgentOwl/api/node_modules/mongoose/lib/document.js:594:14)
    at model.$set (/Users/pa.dorado/Documents/Development/AgentOwl/api/node_modules/mongoose/lib/document.js:554:24)
    at model.Document (/Users/pa.dorado/Documents/Development/AgentOwl/api/node_modules/mongoose/lib/document.js:83:12)
    at model.Model (/Users/pa.dorado/Documents/Development/AgentOwl/api/node_modules/mongoose/lib/model.js:56:12)
    at new model (/Users/pa.dorado/Documents/Development/AgentOwl/api/node_modules/mongoose/lib/model.js:3921:13)
    at /Users/pa.dorado/Documents/Development/AgentOwl/api/node_modules/mongoose/lib/model.js:2062:22
    at /Users/pa.dorado/Documents/Development/AgentOwl/api/node_modules/mongoose/node_modules/async/internal/parallel.js:27:9
    at eachOfArrayLike (/Users/pa.dorado/Documents/Development/AgentOwl/api/node_modules/mongoose/node_modules/async/eachOf.js:57:9)
    at exports.default (/Users/pa.dorado/Documents/Development/AgentOwl/api/node_modules/mongoose/node_modules/async/eachOf.js:9:5)
    at _parallel (/Users/pa.dorado/Documents/Development/AgentOwl/api/node_modules/mongoose/node_modules/async/internal/parallel.js:26:5)
    at parallelLimit (/Users/pa.dorado/Documents/Development/AgentOwl/api/node_modules/mongoose/node_modules/async/parallel.js:85:26)
    at /Users/pa.dorado/Documents/Development/AgentOwl/api/node_modules/mongoose/lib/model.js:2078:5
    at new Promise (<anonymous>:null:null)
    at Function.create (/Users/pa.dorado/Documents/Development/AgentOwl/api/node_modules/mongoose/lib/model.js:2033:17)
    at Function.Schema.statics.insert (/Users/pa.dorado/Documents/Development/AgentOwl/api/plugins/crud_mongoose.js:34:39)
    at BoolJSComponent.insert (/Users/pa.dorado/Documents/Development/AgentOwl/api/plugins/crud_dao.js:25:27)
    at MigrationHistory.0.15.0 (/Users/pa.dorado/Documents/Development/AgentOwl/api/scripts/database/migrate.js:18:32)
    at <anonymous>:null:null
    at process._tickCallback (internal/process/next_tick.js:188:7)

        message: 'Cast to Feature failed for value "{ type: \'Feature\',\n  geometry: \n   { type: \'GeometryCollection\',\n     geometries: [ [Object], [Object] ] },\n  properties: \n   { styleUrl: \'#poly-FFEA00-1200-76\',\n     styleHash: \'-26c96a1f\',\n     styleMapHash: \n      { normal: \'#poly-FFEA00-1200-76-normal\',\n        highlight: \'#poly-FFEA00-1200-76-highlight\' },\n     description: \'FID 30\',\n     stroke: \'#ffea00\',\n     \'stroke-opacity\': 1,\n     \'stroke-width\': 1.2,\n     fill: \'#ffea00\',\n     \'fill-opacity\': 0.2980392156862745 } }" at path "polygon"',
        name: 'CastError',
        stringValue: '"{ type: \'Feature\',\n  geometry: \n   { type: \'GeometryCollection\',\n     geometries: [ [Object], [Object] ] },\n  properties: \n   { styleUrl: \'#poly-FFEA00-1200-76\',\n     styleHash: \'-26c96a1f\',\n     styleMapHash: \n      { normal: \'#poly-FFEA00-1200-76-normal\',\n        highlight: \'#poly-FFEA00-1200-76-highlight\' },\n     description: \'FID 30\',\n     stroke: \'#ffea00\',\n     \'stroke-opacity\': 1,\n     \'stroke-width\': 1.2,\n     fill: \'#ffea00\',\n     \'fill-opacity\': 0.2980392156862745 } }"',
        kind: 'Feature',
        value: [Object],
        path: 'polygon',
        reason: [Object] } },
  _message: 'Building validation failed',
  name: 'ValidationError' }

pandres95 avatar Apr 11 '18 23:04 pandres95

Please include your Mongoose version.

markstos avatar Apr 12 '18 14:04 markstos

Currently, I use 4.13.12

pandres95 avatar Apr 12 '18 18:04 pandres95

@pandres95 you're getting the error on the "polygon" node and that's the only one with backslashes (c:\\proyectos\\sigcampus\\graficos\\imagenes\\bloques\\Gb.jpg) - can you try it removing the those?

joshkopecek avatar Apr 13 '18 07:04 joshkopecek

@joshkopecek I already tried removing it. Also, I tried removing the whole object from the batch insertion, but another one which had a GeometryCollection feature failed.

pandres95 avatar Apr 13 '18 13:04 pandres95