Developer Discussions

Discuss topics with other Hexagon Geospatial Power Portfolio developers and experts to get the most out of our products.
Showing results for 
Search instead for 
Do you mean 
Reply
Highlighted
New Contributor
Posts: 2
Registered: ‎08-10-2020

Azure CosmosDB geospatial query using MongoDB interface behave strangely

I have a collection in Azure Cosmosdb (MongoDB API), which has a bunch of documents containing geospatial data. when I am querying the database for all points in a particular polygon, using MongoDB shell returns the points properly, but using pymongo gives me nothing. More specifically:

 

in MongoDB shell

 

globaldb:PRIMARY> db.test_collection.find( { "Location" : { "$geoWithin" :  { "$geometry" : { "type" : "Polygon" ,"coordinates" :[ [ [ 0 , 0 ] , [ 41 , 0 ] , [41,6],[0,6], [0,0] ] ] }  } } } )
{ "_id" : ObjectId("5e395a9929ae6f6ec66bc97e"), "info" : "test_info", "region" : "region", "Location" : { "type" : "Point", "coordinates" : [ 40, 5 ] } }
{ "_id" : ObjectId("5e395ab895c1327b1c4568b4"), "info" : "test_info", "region" : "region", "Location" : { "type" : "Point", "coordinates" : [ 40, 5 ] } }
{ "_id" : ObjectId("5e395b6bd76420859e134e26"), "info" : "test_info", "region" : "region", "Location" : { "type" : "Point", "coordinates" : [ 40, 5 ] } }

The records are properly returned

in python (pymongo)

 

cur_collection = db.test_collection
points_in = cur_collection.find(
    { "Location" :
          { "$geoWithin" :
                { "$geometry" : { "type" : "Polygon",
                            "coordinates" :
                                [ [
                                    [ 0 , 0 ] ,
                                    [ 41 ,0 ] ,
                                    [ 41 ,6 ],
                                    [ 0,  6],
                                    [ 0,  0]
                                ] ]

                }
            }
        }
    }
)
for point in points_in:
    print(point)

gives me nothing.

 

What am I doing wrong here?

 

Please help me with this.

 

Thanks in advance.

Highlighted
Community Manager
Posts: 126
Registered: ‎04-27-2018

Re: Azure CosmosDB geospatial query using MongoDB interface behave strangely

Hi @AndrewD ,

Could you specify which Hexagon Geospatial product relates to your question?

Florent Caelen
Community Manager
Please send me a private message if you need any assistance about the Community.