我想使用Overpy返回OSM数据的Geo Dataframe 。这很容易使用override和shapely在API中使用verbosity = 'geom'来完成,但override不允许您使用关系(据我所知)
因此,我使用overpy进行以下查询:
import overpy
import requests
import json
import geojson
overpass_url = "http://overpass-api.de/api/interpreter"
overpass_query = """
[out:json];
area["ISO3166-1"="IS"][admin_level=2];
(
way["natural"="glacier"](area);
rel["natural"="glacier"](area);
);
out geom;
"""
response = requests.get(overpass_url,
params={'data': overpass_query})
response.raise_for_status()
data = response.json()
这将返回一个dict(下面粘贴的片段)......我想将其转换为geodaframe或geojson格式:
{'version': 0.6,
'generator': 'Overpass API 0.7.56.8 7d656e78',
'osm3s': {'timestamp_osm_base': '2021-02-15T15:22:03Z',
'timestamp_areas_base': '2021-02-15T15:11:02Z',
'copyright': 'The data included in this document is from www.openstreetmap.org. The data is made available under ODbL.'},
'elements': [{'type': 'way',
'id': 25572229,
'bounds': {'minlat': 64.7317767,
'minlon': -19.7595973,
'maxlat': 64.7600927,
'maxlon': -19.6928364},
'nodes': [278755095,
4988895563,
4988895561,
4988895562,
278755096,
4988895559,
278755097,
4988895560,
4988895557,
4988895558,
4988895556,
278755098,
4988895555,
4988895554,
4988895553,
278755099,
278755100,
278755101,
278755102,
278755103,
5986523217,
5986523216,
278755104,
278755105,
5986523215,
5986523214,
5986523212,
5986523213,
278755106,
278755107,
278755108,
278755109,
278755110,
278755111,
278755112,
278755113,
278755114,
278755115,
278755116,
278755117,
278755118,
278755119,
278755120,
278755124,
278755125,
278755126,
278755130,
278755131,
278755132,
278755133,
278755134,
278755135,
278755136,
278755137,
4988895564,
4988895566,
4988895565,
4988895568,
4988895567,
4988895569,
278755095],
'geometry': [{'lat': 64.7332811, 'lon': -19.7278524},
{'lat': 64.7329093, 'lon': -19.7341986},
{'lat': 64.7334309, 'lon': -19.7383334},
{'lat': 64.7342309, 'lon': -19.7400297},
{'lat': 64.7345084, 'lon': -19.7429107},
{'lat': 64.7358988, 'lon': -19.7458491},
{'lat': 64.7356206, 'lon': -19.7496168},
{'lat': 64.7360086, 'lon': -19.7512644},
{'lat': 64.7357056, 'lon': -19.7537414},
{'lat': 64.7381456, 'lon': -19.7541846},
{'lat': 64.7385295, 'lon': -19.7531667},
{'lat': 64.7394417, 'lon': -19.7538338},
{'lat': 64.7407874, 'lon': -19.7544468},
{'lat': 64.741594, 'lon': -19.7539147},
{'lat': 64.7429881, 'lon': -19.7545682},
{'lat': 64.744698, 'lon': -19.7551248},
{'lat': 64.7508682, 'lon': -19.7575374},
{'lat': 64.7555541, 'lon': -19.7595973},
{'lat': 64.7598548, 'lon': -19.7564644},
{'lat': 64.7600927, 'lon': -19.7548981},
{'lat': 64.7583663, 'lon': -19.7500575},
{'lat': 64.7597724, 'lon': -19.7487397},
{'lat': 64.7573843, 'lon': -19.7443194},
{'lat': 64.7569176, 'lon': -19.7436757},
{'lat': 64.7538784, 'lon': -19.7439045},
{'lat': 64.7508483, 'lon': -19.737696},
{'lat': 64.7489433, 'lon': -19.7360508},
{'lat': 64.7488348, 'lon': -19.7349065},
{'lat': 64.7502824, 'lon': -19.7324748},
{'lat': 64.7551148, 'lon': -19.724235},
{'lat': 64.7589216, 'lon': -19.7129054},
{'lat': 64.7568718, 'lon': -19.7125621},
{'lat': 64.7518933, 'lon': -19.7225184},
{'lat': 64.7489644, 'lon': -19.7218318},
{'lat': 64.7470604, 'lon': -19.7232051},
{'lat': 64.7448633, 'lon': -19.7225184},
{'lat': 64.7488179, 'lon': -19.7170253},
{'lat': 64.7521862, 'lon': -19.7129054},
{'lat': 64.7545291, 'lon': -19.7074122},
{'lat': 64.752772, 'lon': -19.7022624},
{'lat': 64.7468923, 'lon': -19.7110574},
{'lat': 64.7471989, 'lon': -19.7043811},
{'lat': 64.746467, 'lon': -19.7010805},
{'lat': 64.7449527, 'lon': -19.7017042},
{'lat': 64.7428125, 'lon': -19.7032924},
{'lat': 64.7410546, 'lon': -19.7101588},
{'lat': 64.7377485, 'lon': -19.7079655},
{'lat': 64.7356578, 'lon': -19.6992603},
{'lat': 64.7362158, 'lon': -19.694227},
{'lat': 64.7356134, 'lon': -19.6928364},
{'lat': 64.7351069, 'lon': -19.6939175},
{'lat': 64.7337628, 'lon': -19.6957344},
{'lat': 64.7317767, 'lon': -19.6957953},
{'lat': 64.7329861, 'lon': -19.703479},
{'lat': 64.736968, 'lon': -19.7112033},
{'lat': 64.7357176, 'lon': -19.7191862},
{'lat': 64.7358998, 'lon': -19.7209692},
{'lat': 64.7344614, 'lon': -19.7209821},
{'lat': 64.7335286, 'lon': -19.7222981},
{'lat': 64.732916, 'lon': -19.7276224},
{'lat': 64.7332811, 'lon': -19.7278524}],
'tags': {'alt_name': 'Regnbúðajökull',
'name': 'Hrútfellsjökull',
'natural': 'glacier'}},
{'type': 'way',
'id': 250745561,
'bounds': {'minlat': 64.7129996,
'minlon': -17.9851867,
'maxlat': 64.7859787,
'maxlon': -17.8182245},
'nodes': [8117616831,
8117616832,
8117616833,
8117616834,
8117616835,
8117616836,
8117616837,
8117616838,
8117616839,
8117616840,
8117616841,
8117616842,
8117616843,
8117616844,
8117616845,
8117616846,
8117616847,
8117616848,
8117616849,
8117616850,
8117616851,
8117616852,
8117616853,
8117616854,
8117616855,
8117616856,
8117616857,
8117616858,
8117616859,
8117616860,
8117616861,
8117616862,
8117616863,
8117616864,
8117616865,
8117616866,
8117616867,
8117616868,
8117616869,
8117616870,
8117616871,
8117616872,
8117616873,
8117616874,
8117616875,
8117616876,
2571248283,
2571248282,
2571248279,
2571248278,
2571248280,
2571248277,
2571248275,
2571248273,
2571248272,
2571248271,
2571248270,
2571248268,
2571248263,
2571248254,
2571248250,
2571248248,
2571248249,
2571248252,
2571248253,
2571248251,
2571248246,
2571248244,
2571248241,
2571248240,
2571248242,
2571248243,
2571248245,
2571248247,
2571248261,
2571248265,
2571248269,
2571248274,
2571248276,
2571248281,
2571248284,
2571248285,
2571248287,
2571248291,
2571248292,
2571248293,
2571248295,
2571248296,
2571248298,
2571248300,
2571248304,
2571248302,
2571248299,
2571248301,
2571248305,
2571248308,
2571248316,
2571248313,
3682713435,
2571248309,
2571248307,
2571248315,
2571248322,
2571248323,
2571248324,
3682713436,
2571248325,
2571248327,
2571248328,
2571248330,
2571248332,
2571248333,
2571248335,
2571248336,
2571248338,
2571248342,
2571248345,
2571248347,
2571248350,
2571248352,
2571248361,
2571248365,
2571248354,
2571248351,
2571248353,
2571248362,
2571248369,
2571248372,
2571248376,
2571248379,
308853335,
308853337,
308853338,
2571248363,
2571248355,
2571248358,
2571248367,
2571248366,
2571248359,
2571248349,
2571248344,
2571248340,
2571248339,
2571248346,
2571248364,
2571248374,
2571248378,
308853340,
308853342,
2571248389,
308853344,
308853346,
2571248388,
308853347,
308853349,
308853351,
308853353,
308853355,
308853357,
2571248384,
2571248382,
2571248380,
2571248370,
2571248360,
2571248357,
2571248371,
2571248375,
2571248381,
2571248385,
2571248387,
2571248386,
2571248383,
2571248377,
2571248373,
2571248368,
2571248356,
2571248348,
2571248343,
2571248341,
2571248337,
2571248334,
2571248331,
2571248329,
2571248326,
2571248319,
2571248318,
2571248312,
2571248311,
2571248317,
2571248321,
2571248320,
2571248314,
2571248310,
2571248306,
2571248303,
2571248297,
2571248294,
8117616831],
'geometry': [{'lat': 64.7401232, 'lon': -17.8838301},
{'lat': 64.7392308, 'lon': -17.8813838},
{'lat': 64.7386814, 'lon': -17.8779721},
{'lat': 64.738425, 'lon': -17.8746032},
{'lat': 64.7377931, 'lon': -17.8736591},
{'lat': 64.7368224, 'lon': -17.8739595},
{'lat': 64.7361997, 'lon': -17.8749251},
{'lat': 64.7355678, 'lon': -17.8799462},
{'lat': 64.7360074, 'lon': -17.8840875},
{'lat': 64.7357784, 'lon': -17.8851818},
{'lat': 64.7353846, 'lon': -17.8852677},
{'lat': 64.734771, 'lon': -17.8850745},
{'lat': 64.7344047, 'lon': -17.8851818},
{'lat': 64.7343131, 'lon': -17.8857827},
{'lat': 64.7343314, 'lon': -17.8867697},
{'lat': 64.7345329, 'lon': -17.8877997},
{'lat': 64.7350183, 'lon': -17.8887438},
{'lat': 64.7350549, 'lon': -17.8896236},
{'lat': 64.7348993, 'lon': -17.8906321},
{'lat': 64.7349725, 'lon': -17.892456},
{'lat': 64.7348993, 'lon': -17.8928422},
{'lat': 64.7341025, 'lon': -17.893486},
{'lat': 64.7340842, 'lon': -17.8941726},
{'lat': 64.7343955, 'lon': -17.89649},
{'lat': 64.7349084, 'lon': -17.8969192},
{'lat': 64.7352289, 'lon': -17.8966188},
{'lat': 64.7349908, 'lon': -17.8953099},
{'lat': 64.7350641, 'lon': -17.8950309},
{'lat': 64.7352289, 'lon': -17.8949022},
{'lat': 64.7353846, 'lon': -17.8948807},
{'lat': 64.7354487, 'lon': -17.8945374},
{'lat': 64.7355312, 'lon': -17.8946018},
{'lat': 64.735577, 'lon': -17.8952455},
{'lat': 64.7357326, 'lon': -17.8955888},
{'lat': 64.735696, 'lon': -17.8958678},
{'lat': 64.7355037, 'lon': -17.8957176},
{'lat': 64.7353388, 'lon': -17.89649},
{'lat': 64.735348, 'lon': -17.8981423},
{'lat': 64.7351465, 'lon': -17.8990435},
{'lat': 64.735174, 'lon': -17.900288},
{'lat': 64.7349084, 'lon': -17.9009318},
{'lat': 64.7346245, 'lon': -17.902348},
{'lat': 64.7347069, 'lon': -17.9035925},
{'lat': 64.7350458, 'lon': -17.9045796},
{'lat': 64.7350916, 'lon': -17.9063176},
{'lat': 64.7344597, 'lon': -17.9077124},
{'lat': 64.733053, 'lon': -17.910492},
{'lat': 64.7322122, 'lon': -17.9145087},
{'lat': 64.731355, 'lon': -17.9174054},
{'lat': 64.7312725, 'lon': -17.9140839},
{'lat': 64.7314868, 'lon': -17.9094879},
{'lat': 64.7302998, 'lon': -17.9078271},
{'lat': 64.7291622, 'lon': -17.9114962},
{'lat': 64.7272331, 'lon': -17.9150494},
{'lat': 64.7270517, 'lon': -17.9189116},
{'lat': 64.7265405, 'lon': -17.9256704},
{'lat': 64.7261613, 'lon': -17.9287216},
{'lat': 64.7253533, 'lon': -17.9327382},
{'lat': 64.7232095, 'lon': -17.9360983},
{'lat': 64.7215109, 'lon': -17.9417371},
{'lat': 64.7207192, 'lon': -17.9475304},
{'lat': 64.720241, 'lon': -17.9532078},
{'lat': 64.7206698, 'lon': -17.9567996},
{'lat': 64.7213625, 'lon': -17.9596963},
{'lat': 64.7214284, 'lon': -17.9635198},
{'lat': 64.7207522, 'lon': -17.9679227},
{'lat': 64.7195482, 'lon': -17.9693903},
{'lat': 64.7163648, 'lon': -17.9710511},
{'lat': 64.7138244, 'lon': -17.9694676},
{'lat': 64.7129996, 'lon': -17.969931},
{'lat': 64.7145668, 'lon': -17.9714759},
{'lat': 64.7163483, 'lon': -17.9731753},
{'lat': 64.7185751, 'lon': -17.9742567},
{'lat': 64.7201255, 'lon': -17.9746815},
{'lat': 64.722319, 'lon': -17.9763036},
{'lat': 64.7243309, 'lon': -17.9801272},
{'lat': 64.7257985, 'lon': -17.9799341},
{'lat': 64.7284532, 'lon': -17.9794706},
{'lat': 64.7299701, 'lon': -17.9799341},
{'lat': 64.7316022, 'lon': -17.9786982},
{'lat': 64.7339267, 'lon': -17.9808224},
{'lat': 64.7354762, 'lon': -17.9829466},
{'lat': 64.7364322, 'lon': -17.9823287},
{'lat': 64.7375201, 'lon': -17.9840666},
{'lat': 64.7392672, 'lon': -17.9839894},
{'lat': 64.7401077, 'lon': -17.9789686},
{'lat': 64.7416569, 'lon': -17.9761878},
{'lat': 64.7428764, 'lon': -17.9747588},
{'lat': 64.7454141, 'lon': -17.9707807},
{'lat': 64.7466499, 'lon': -17.9663392},
{'lat': 64.7482316, 'lon': -17.9666482},
{'lat': 64.7476055, 'lon': -17.9703945},
{'lat': 64.7462544, 'lon': -17.9758402},
{'lat': 64.7466499, 'lon': -17.9805134},
{'lat': 64.7487259, 'lon': -17.984028},
{'lat': 64.7518066, 'lon': -17.9851867},
{'lat': 64.7542282, 'lon': -17.9786982},
{'lat': 64.7537669, 'lon': -17.9734843},
{'lat': 64.7535401, 'lon': -17.9713788},
{'lat': 64.7519878, 'lon': -17.9696221},
2条答案
按热度按时间7uhlpewt1#
如果你知道返回的所有元素都是多边形(在你的例子中似乎是这样),你可以编写一个函数,将立交桥API返回的每个元素转换为GeoJSON Feature,以便将所有这些特征收集在一个列表中。然后很容易为这个特征列表创建一个GeoDataFrame:
pcrecxhr2#
我知道这是一个古老的故事,但仍然:你可以这样使用osm2geojson。