Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/316.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 将EPSG:3857(“web mercator”)中bokeh瓷砖供应商的投影更改为EPSG:4326中我的来源_Python_Python 3.x_Bokeh_Projection_Cartodb - Fatal编程技术网

Python 将EPSG:3857(“web mercator”)中bokeh瓷砖供应商的投影更改为EPSG:4326中我的来源

Python 将EPSG:3857(“web mercator”)中bokeh瓷砖供应商的投影更改为EPSG:4326中我的来源,python,python-3.x,bokeh,projection,cartodb,Python,Python 3.x,Bokeh,Projection,Cartodb,我能够使用Bokeh在谷歌地图上绘制geopandas数据帧中的字形 它给了我: 但是,当我使用Carto作为提供程序进行绘图时,轴中存在错误: tile_provider = get_provider(Vendors.CARTODBPOSITRON) # range bounds supplied in web mercator coordinates p = figure(x_range=(-2000000, 6000000), y_range=(-1000000,

我能够使用Bokeh在谷歌地图上绘制geopandas数据帧中的字形

它给了我:

但是,当我使用Carto作为提供程序进行绘图时,轴中存在错误:

    tile_provider = get_provider(Vendors.CARTODBPOSITRON)

    # range bounds supplied in web mercator coordinates
    p = figure(x_range=(-2000000, 6000000), y_range=(-1000000, 7000000))#, x_axis_type="mercator", y_axis_type="mercator")
    p.add_tile(tile_provider)
    p.xgrid.grid_line_color = None
    p.ygrid.grid_line_color = None#Add patch renderer to figure. 
    p.patches('xs','ys', source = src,fill_color = {'field' :'results', 'transform' : color_mapper},
              line_color = 'black', line_width = 0.25, fill_alpha = 1)#Specify figure layout.
    p.add_layout(color_bar, 'below')#Display figure inline in Jupyter Notebook.
    output_notebook()#Display figure.
    return p
因此,它在地图上的位置是错误的,人们可以看到红色圆圈:

看起来地图在EPSG:3857 web mercator中,而我的来源可能在EPSG:4326中。我如何才能正确地绘制它

以下是我的数据的前几行:

    id  parent_id common_id common_name  has_children  shape_type_id  \
64  70140      69935         3        63-3         False              4   
65  70141      69935         2        63-2         False              4   
66  70142      69935         5        63-5         False              4   
67  70143      69935         6        63-6         False              4   
68  70144      69935         8        63-8         False              4   

   shape_type_name    value color  title_location results  \
64        Precinct  No Data  None  Precinct: 63-3   65.16   
65        Precinct  No Data  None  Precinct: 63-2   57.11   
66        Precinct  No Data  None  Precinct: 63-5   54.33   
67        Precinct  No Data  None  Precinct: 63-6   59.15   
68        Precinct  No Data  None  Precinct: 63-8   61.86   

                                             turnout  \
64  {'pct': 46.38, 'count': 686.0, 'eligible': 1479}   
65   {'pct': 49.62, 'count': 394.0, 'eligible': 794}   
66  {'pct': 58.26, 'count': 624.0, 'eligible': 1071}   
67   {'pct': 57.54, 'count': 492.0, 'eligible': 855}   
68   {'pct': 50.75, 'count': 506.0, 'eligible': 997}   

                                             geometry  
64  POLYGON ((42.18180 42.18530, 42.18135 42.18593...  
65  POLYGON ((42.20938 42.20621, 42.21156 42.20706...  
66  POLYGON ((42.08429 42.20468, 42.08489 42.20464...  
67  POLYGON ((42.16270 42.16510, 42.16661 42.16577...  
68  POLYGON ((42.16270 42.16510, 42.16315 42.16640...

您必须将数据从EPSG:4326重新投影到EPSG:3857

下面是一个包含一些GeoJSON数据的解决方案:

要求 !pip安装熊猫numpy bokeh geopandas 作为pd进口熊猫 将numpy作为np导入 def lon_至web_棱镜: k=6378137 返回长度*k*np.pi/180.0 def lat_to_web_mercatorlat: k=6378137 返回np.lognp.tan90+lat*np.pi/360.0*k def wgs84到web棱镜DF,lon=lon,lat=lat: 将十进制经度/纬度转换为Web Mercator格式 k=6378137 df[x]=df[lon]*k*np.pi/180.0 df[y]=np.lognp.tan90+df[lat]*np.pi/360.0*k 返回df BerlinWGS84=[13.08835,13.76116,52.33826,52.67551] Berlin=x_范围,y_范围=lon_至web_mercatorBerlinWGS84[0],lon_至web_mercatorBerlinWGS84[1], lat_to_web_mercatorBerlinWGS84[2],lat_to_web_mercatorBerlinWGS84[3] 策划它 从bokeh.plotting导入图形、显示、输出 从bokeh.tile\u providers导入get\u provider,供应商 输出笔记本 tile\u provider=get\u provider vendors.cartodbpositon 范围边界以web墨卡托坐标提供 p=图x\u范围=x\u范围,y\u范围=y\u范围, x轴类型=墨卡托,y轴类型=墨卡托 p、 添加\u tiletile\u提供程序 炫耀 土工画板 作为gpd导入geopandas 导入请求 def remoteGeoJSONToGDFurl,显示=False: 资料来源:https://medium.com/@maptastik/remote-geojson-to-geodataframe-19c3c1282a64 将远程GeoJSON导入到GeoDataFrame 关键字参数: url-指向web上GeoJSON资源的url 显示-加载时显示几何图形默认值:False r=requests.geturl data=r.json gdf=gpd.GeoDataFrame.from_featuresdata['features'] 如果显示: gdf图 返回gdf url='1〕https://gist.githubusercontent.com/sabman/96730f5949576e7793a3f79eb390f90c/raw/7ffcf34239175cafcc9a63382e6beacd0cab9fa9/BerlinFeatures.geojson' gdf=remoteGeoJSONToGDFurl gdf图 确保已定义初始投影 gdf.crs={'init':'epsg:4326'} gdf_webmerc=gdf.copy 责备 gdf_webmerc=gdf[‘几何’]。to_crsepsg=3857 gdf_webmerc.plot 从bokeh.models导入GeoJSONDataSource geo_source=GeoJSONDataSourcegeojson=gdf_webmerc.to_json 让我们来策划一下 p、 圆环=x',y='y',大小=15,α=0.7,震源=geo_震源 炫耀
如果CD中的坐标不是WebMercator,则必须将其转换为WebMercator,以便Bokeh在此情况下使用。我不知道这方面的任何细节,但也许像Cartopy这样的工具可以进行转换,或者可能有维基百科或其他页面描述转换。@bigreddot什么是CD?看来我的数据是在一个很好的预测,这是墨卡托。我添加了geopandas数据框架的摘录,我想我不同意。上面显示的数据只是普通的lat/lon-vaues。Web墨卡托以米的北距/东距表示,如x_范围和y_范围值。对于平铺提供商地图,仅了解web mercator,您需要将数据转换为web mercator,而不是lat/lon值。
    id  parent_id common_id common_name  has_children  shape_type_id  \
64  70140      69935         3        63-3         False              4   
65  70141      69935         2        63-2         False              4   
66  70142      69935         5        63-5         False              4   
67  70143      69935         6        63-6         False              4   
68  70144      69935         8        63-8         False              4   

   shape_type_name    value color  title_location results  \
64        Precinct  No Data  None  Precinct: 63-3   65.16   
65        Precinct  No Data  None  Precinct: 63-2   57.11   
66        Precinct  No Data  None  Precinct: 63-5   54.33   
67        Precinct  No Data  None  Precinct: 63-6   59.15   
68        Precinct  No Data  None  Precinct: 63-8   61.86   

                                             turnout  \
64  {'pct': 46.38, 'count': 686.0, 'eligible': 1479}   
65   {'pct': 49.62, 'count': 394.0, 'eligible': 794}   
66  {'pct': 58.26, 'count': 624.0, 'eligible': 1071}   
67   {'pct': 57.54, 'count': 492.0, 'eligible': 855}   
68   {'pct': 50.75, 'count': 506.0, 'eligible': 997}   

                                             geometry  
64  POLYGON ((42.18180 42.18530, 42.18135 42.18593...  
65  POLYGON ((42.20938 42.20621, 42.21156 42.20706...  
66  POLYGON ((42.08429 42.20468, 42.08489 42.20464...  
67  POLYGON ((42.16270 42.16510, 42.16661 42.16577...  
68  POLYGON ((42.16270 42.16510, 42.16315 42.16640...