gospodarka-przestrzenna / MongoConnector

Qgis mongodb plugin
GNU General Public License v2.0
10 stars 5 forks source link

dont support geometry type: 'MultiPolygon' #10

Open stefanocudini opened 5 years ago

stefanocudini commented 5 years ago

show me a error for an document have this STANDARD geometry type

mk45 commented 5 years ago

Strange :( but have to check it out . Can You share some example data please (few features will be enough)

stefanocudini commented 5 years ago

this geojson file isnt't open show me an error message: https://gist.github.com/stefanocudini/43c58026328ab9970ce86a4d58b71089

the document's geometry is different from all other docs in collection because this is a MultiPolygon others is Point. But in my mongodb documents having a various type of geometry in the same collection

mk45 commented 5 years ago

Nevertheless, I spot the error none of the Multi* geometries works so far as function name changed in QGIS3 ... I'll fix and push

mk45 commented 5 years ago

Should now work in version 1.2.3

stefanocudini commented 5 years ago

I'm sorry... now I recevice an error for this object... but its certainly a valid geojson: https://gist.github.com/stefanocudini/331577e40c479241e62965c7156b386b

stefanocudini commented 5 years ago

@mk45 maybe you could generate a more verbose error message to understand how to fix the data

or use a generic geojson validator library

mk45 commented 5 years ago

The geometry itself works fine. (I created a collection with only this document and works). Maybe this is related with #7 ? What is the exact message in this case?

stefanocudini commented 4 years ago

only this message: "Error: Check geometry in object zhTeJKxyqs5TAnkFW or 25zRFjyFR9omcaYA4"

db.getCollection('places').findOne({_id:'zhTeJKxyqs5TAnkFW'})
db.getCollection('places').findOne({_id:'25zRFjyFR9omcaYA4'})

result:

{
    "_id" : "zhTeJKxyqs5TAnkFW",
    "name" : "baciapiede",
    "createdAt" : 1519139797398.0,
    "userId" : "5DmiGiho77R54qmfG",
    "active" : 0,
    "indoor" : 0,
    "loc" : [ 
        46.065958, 
        11.154465
    ],
    "checkins" : [],
    "hist" : [ 
        "8xwKgCkDxTRMZ6zTa", 
        "4czFp3gZSvdCuXpcT"
    ],
    "desc" : "",
    "warn" : "",
    "websites" : [],
    "source" : {},
    "geoinfo" : {
        "loc" : [ 
            46.066, 
            11.1545
        ],
        "esp" : 198,
        "near" : "Povo",
        "naz" : "italy",
        "com" : "Trento",
        "prov" : "Trento",
        "reg" : "Trentino-Alto Adige",
        "ele" : 404
    },
    "osm" : {},
    "rank" : 0,
    "convers" : [ 
        "FoXzfo5GsHyE3ufvc"
    ],
    "geometry" : {
        "type" : "Polygon",
        "coordinates" : [ 
            [ 
                [ 
                    11.154733, 
                    46.066042
                ], 
                [ 
                    11.154256, 
                    46.06615
                ], 
                [ 
                    11.154374, 
                    46.065783
                ], 
                [ 
                    11.154436, 
                    46.065785
                ], 
                [ 
                    11.154733, 
                    46.066042
                ]
            ]
        ]
    },
    "cats" : [],
    "url" : "",
    "type" : "Feature"
}

AND OTHER DOCS:

{
    "_id" : "25zRFjyFR9omcaYA4",
    "name" : "",
    "createdAt" : 1535467285564.0,
    "userId" : "3D8ED7YWDceZyc27h",
    "active" : 0,
    "indoor" : 0,
    "loc" : [ 
        50.1755788804291, 
        30.5193328857422
    ],
    "checkins" : [],
    "hist" : [],
    "desc" : "",
    "warn" : "",
    "source" : {},
    "geoinfo" : {
        "loc" : [ 
            50.1756, 
            30.5193
        ],
        "esp" : null,
        "naz" : "Ukraine",
        "prov" : null,
        "near" : "Velyki Dmytrovychi",
        "com" : null,
        "reg" : "Kyiv City",
        "ele" : 152
    },
    "osm" : {},
    "rank" : 0,
    "convers" : [],
    "geometry" : {
        "type" : "Point",
        "coordinates" : [ 
            30.5193328857422, 
            50.1755788804291
        ]
    },
    "cats" : [],
    "url" : [],
    "type" : "Feature",
    "properties" : {}
}
mk45 commented 4 years ago

This message means that geometry type differs for those two documents. And in fact geometry.type is inconsistent. Qgis creates layer with fixed type. It can only add features with matching type (ex "Point").

To discard error I would create two separate collections one with geometry.type "Point" features and other with geometry.type "Polygon" . Then You can add two separate layers form created collections.

stefanocudini commented 4 years ago

I can't change the structure of my db/collections to adapt it to a plugin that should help me show data in qgis... I just have a standard geojson documents and this should be enough. Mongodb does not need to have an identical geometry on all the docs of the same collection..

I tell you because otherwise this excellent plugin risks becoming useless for most of the use cases :(

Like as in other similar qgis plugins you should create multiple layers at run time for each type of geometries found.

mk45 commented 4 years ago

You are right! But it is not the plugin nor Mongo limitation. Problem is in QGis which allows having layer with only one feature type ... I cannot change that.

The database is the place where data cleaning and management should be done. We have multiple tools to deal with data there (like collection cloning / Views /etc ...). That what database is for!

Probably the workaround would be to implement adding multiple layers when adding one collection? Nevertheless, I think that user expects one layer when adding one collection. Isn't he?

stefanocudini commented 4 years ago

ok... I would expect opinions from other users

HannesMas commented 4 years ago

My view: as pointed out, the limitation of only allowing one geometry type per layer is set by QGIS. I've come across this limitation before (not specifically related to MongoDB data) in which case I also used to split up the source layer into several layers (one per geometry type).

stefanocudini commented 4 years ago

same behavior is in the famous plugin QuickOSM Screenshot at 2019-08-30 15-26-33

taatuut commented 3 years ago

A possible solution direction could be to offer the option in the MongoConnecytor UI to choose which geometry to add when a collection with multiple geometry types is encountered. This should then always be checked first with an aggregation query like:

[{'$group': {'_id': '$geometry.type'}}]

Then after user makes a choice filter only those where selection applies.

Or do this automatically 'behind the screens' and add the geometry types to a group layer automatically, if multiple.

Just leaving my first thoughts here as I hope to dive into this, so any feedback/comments on this draft idea is welcome.