Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用python的azure cosmos db SQL API提供地理空间数据_Python_Geolocation_Azure Cosmosdb_Geospatial_Azure Cosmosdb Sqlapi - Fatal编程技术网

使用python的azure cosmos db SQL API提供地理空间数据

使用python的azure cosmos db SQL API提供地理空间数据,python,geolocation,azure-cosmosdb,geospatial,azure-cosmosdb-sqlapi,Python,Geolocation,Azure Cosmosdb,Geospatial,Azure Cosmosdb Sqlapi,我在azure cosmos数据库中有200万条记录 我将它与SQL API和python一起使用 我已将这些记录改编为地理空间数据,如以下示例: { " "street": "Palmdale Station", "year": "2015", "incidentid": "D01DA82AE23D128799924FCF82B72908", "id": "501", " "latitude": 34.58986, "country": "United States", "lon

我在azure cosmos数据库中有200万条记录

我将它与SQL API和python一起使用

我已将这些记录改编为地理空间数据,如以下示例:

{
"
"street": "Palmdale Station", 
"year": "2015", 
"incidentid": "D01DA82AE23D128799924FCF82B72908", 
"id": "501", 
"
"latitude": 34.58986, 

"country": "United States", 
"longitude": -89.61238680302355, 
"_attachments": "attachments/", 
"incidenttype": "Train Accident", 
"_etag": "\"0900f6f1-0000-0100-0000-5dd6cf150000\""
}
{
"_self": "dbs/QwR-AA==/colls/QwR-AIt6sYk=/docs/QwR-AIt6sYnYUx0AAAAAAA==/", 
"street": "Palmdale Station", 
"year": 2015, 
"incidentid": "D01DA82AE23D128799924FCF82B72908", 
"id": "501", 
"notifyrule": "Use Perimeter", 
"city": "Palmdale", 
"infoquality": "Media", 
"severity": "Minor", 
"incidentcategory": "Transportation", 
"location": {
"type": "Point", 
"coordinates": [
-89.61238680302355, 
29.568987477308124
]
}, 
"latitude": 29.568987477308124, 
"infosource": "Media", 
"description": "One person was struck by an Antelope Valley Line Train near the Palmdale Station, located in the area of Clock Tower Plaza Dr E and Transportation Dr. AV Line tracks between Palmdale and Lancaster remain closed. This incident is closed.", 
"_ts": 1575425976, 
"activitystatus": "CLOSED", 
"postal": "93550", 
"createddated": "2015-12-30 21:46:00 EST", 
"country": "United States", 
"longitude": -118.1194, 
"_attachments": "attachments/", 
"incidenttype": "Train Accident", 
"_etag": "\"13002b74-0000-0100-0000-5de717b80000\""
}
results_fake[0]['location'] = {'type': 'Point','coordinates':[results_fake[0]['longitude'],results_fake[0]['latitude']] }
如您所见,我创建了一个名为
location
的辅助键,我在其中编写了
类型
和坐标:经度和纬度,如microsoft azure文档中所述:

我现在尝试查询一些数据,但没有得到任何结果,我想获得多边形内的点,如下所示:

query =""" SELECT a.id FROM " + container_id + " a
WHERE ST_WITHIN(a.location, {"type": "Polygon","coordinates": [
[[-90.0280152, 30.265521],
[-90.0335083,30.26315],
[-90.0032959,29.3532687],
[-89.1930542,29.3460904],
[-89.2067871,30.267892],
[-90.0280152,30.265521]]]})"""

for item in client.client_connection.QueryItems("dbs/" + database_id + "/colls/" + container_id,
                            query,
                            {'enableCrossPartitionQuery': True}):

    print(json.dumps(item, indent=True))

但是我没有得到任何结果,我做错了什么?

您可以先在azure cosmos门户中测试sql。我测试了您的代码,请参阅我的测试:

import pydocumentdb.document_client as document_client

config = {
    'ENDPOINT': 'https://***.documents.azure.com:443/',
    'MASTERKEY': '***'
};

# Initialize the Python DocumentDB client
client = document_client.DocumentClient(config['ENDPOINT'], {'masterKey': config['MASTERKEY']})

# use a SQL based query to get a bunch of documents
query = { 'query': "SELECT a.id FROM a WHERE ST_WITHIN(a.location, {'type': 'Polygon','coordinates': [[[-90.0280152, 30.265521],[-90.0335083,30.26315],[-90.0032959,29.3532687],[-89.1930542,29.3460904],[-89.2067871,30.267892],[-90.0280152,30.265521]]]})" }

options = {}
options['enableCrossPartitionQuery'] = True

result_iterable = client.QueryDocuments('dbs/db/colls/coll', query, options)

results = list(result_iterable);

print(results)
我的示例文档:

输出: