You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description of expected behavior and the observed behavior
In attempting to plot a geometry from a shape file from the census.gov repo, I'm experiencing errors when using the default crs argument(Plate Carree) of gv.Polygons.
The same error persists when assigning Plate Carree as the crs to use with hvplot, when changing the plotting backend from bokeh to matplotlib, and when changing the crs with geopandas(to_crs).
Other crs projections do appear to work when set in the plotting function, such as Mercator, GOOGLE_MERCATOR, and EckertII, and default hvplot method.
Complete, minimal, self-contained example code that reproduces the issue
From Notebook:
importgeopandasasgpdimportgeoviewsasgvfromcartopyimportcrsgv.extension('bokeh')
t=gpd.read_file('test_geo.json')
gv.Polygons(t) #Index Error # t.hvplot(crs=crs.PlateCarree()) #Another Index Error# gv.Polygons(t, crs=crs.Mercator()) # Works# t.hvplot() # Works
IndexError
IndexErrorTraceback (mostrecentcalllast)
File~\.conda\envs\geo\lib\site-packages\IPython\core\formatters.py:973, inMimeBundleFormatter.__call__(self, obj, include, exclude)
970method=get_real_method(obj, self.print_method)
972ifmethodisnotNone:
-->973returnmethod(include=include, exclude=exclude)
974returnNone975else:
File~\.conda\envs\geo\lib\site-packages\holoviews\core\dimension.py:1316, inDimensioned._repr_mimebundle_(self, include, exclude)
1309def_repr_mimebundle_(self, include=None, exclude=None):
1310""" 1311 Resolves the class hierarchy for the class rendering the 1312 object using any display hooks registered on Store.display 1313 hooks. The output of all registered display_hooks is then 1314 combined and returned. 1315 """->1316returnStore.render(self)
File~\.conda\envs\geo\lib\site-packages\holoviews\core\options.py:1405, inStore.render(cls, obj)
1403data, metadata= {}, {}
1404forhookinhooks:
->1405ret=hook(obj)
1406ifretisNone:
1407continueFile~\.conda\envs\geo\lib\site-packages\holoviews\ipython\display_hooks.py:282, inpprint_display(obj)
280ifnotip.display_formatter.formatters['text/plain'].pprint:
281returnNone-->282returndisplay(obj, raw_output=True)
File~\.conda\envs\geo\lib\site-packages\holoviews\ipython\display_hooks.py:252, indisplay(obj, raw_output, **kwargs)
250elifisinstance(obj, (CompositeOverlay, ViewableElement)):
251withoption_state(obj):
-->252output=element_display(obj)
253elifisinstance(obj, (Layout, NdLayout, AdjointLayout)):
254withoption_state(obj):
File~\.conda\envs\geo\lib\site-packages\holoviews\ipython\display_hooks.py:146, indisplay_hook.<locals>.wrapped(element)
144try:
145max_frames=OutputSettings.options['max_frames']
-->146mimebundle=fn(element, max_frames=max_frames)
147ifmimebundleisNone:
148return {}, {}
File~\.conda\envs\geo\lib\site-packages\holoviews\ipython\display_hooks.py:192, inelement_display(element, max_frames)
189iftype(element) notinStore.registry[backend]:
190returnNone-->192returnrender(element)
File~\.conda\envs\geo\lib\site-packages\holoviews\ipython\display_hooks.py:68, inrender(obj, **kwargs)
65ifrenderer.fig=='pdf':
66renderer=renderer.instance(fig='png')
--->68returnrenderer.components(obj, **kwargs)
File~\.conda\envs\geo\lib\site-packages\holoviews\plotting\renderer.py:410, inRenderer.components(self, obj, fmt, comm, **kwargs)
408doc=Document()
409withconfig.set(embed=embed):
-->410model=plot.layout._render_model(doc, comm)
411ifembed:
412returnrender_model(model, comm)
File~\.conda\envs\geo\lib\site-packages\panel\viewable.py:460, inRenderable._render_model(self, doc, comm)
458ifcommisNone:
459comm=state._comm_manager.get_server_comm()
-->460model=self.get_root(doc, comm)
462ifconfig.embed:
463embed_state(self, model, doc,
464json=config.embed_json,
465json_prefix=config.embed_json_prefix,
466save_path=config.embed_save_path,
467load_path=config.embed_load_path,
468progress=False)
File~\.conda\envs\geo\lib\site-packages\panel\viewable.py:518, inRenderable.get_root(self, doc, comm, preprocess)
501""" 502 Returns the root model and applies pre-processing hooks 503 (...) 515 Returns the bokeh model corresponding to this panel object 516 """517doc=init_doc(doc)
-->518root=self._get_model(doc, comm=comm)
519ifpreprocess:
520self._preprocess(root)
File~\.conda\envs\geo\lib\site-packages\panel\layout\base.py:122, inPanel._get_model(self, doc, root, parent, comm)
120ifrootisNone:
121root=model-->122objects=self._get_objects(model, [], doc, root, comm)
123props=dict(self._init_params(), objects=objects)
124model.update(**self._process_param_change(props))
File~\.conda\envs\geo\lib\site-packages\panel\layout\base.py:112, inPanel._get_objects(self, model, old_objects, doc, root, comm)
110else:
111try:
-->112child=pane._get_model(doc, root, model, comm)
113exceptRerenderError:
114returnself._get_objects(model, current_objects[:i], doc, root, comm)
File~\.conda\envs\geo\lib\site-packages\panel\pane\holoviews.py:248, inHoloViews._get_model(self, doc, root, parent, comm)
246plot=self.object247else:
-->248plot=self._render(doc, comm, root)
250plot.pane=self251backend=plot.renderer.backendFile~\.conda\envs\geo\lib\site-packages\panel\pane\holoviews.py:321, inHoloViews._render(self, doc, comm, root)
318ifcomm:
319kwargs['comm'] =comm-->321returnrenderer.get_plot(self.object, **kwargs)
File~\.conda\envs\geo\lib\site-packages\holoviews\plotting\bokeh\renderer.py:73, inBokehRenderer.get_plot(self_or_cls, obj, doc, renderer, **kwargs)
66 @bothmethod67defget_plot(self_or_cls, obj, doc=None, renderer=None, **kwargs):
68""" 69 Given a HoloViews Viewable return a corresponding plot instance. 70 Allows supplying a document attach the plot to, useful when 71 combining the bokeh model with another plot. 72 """--->73plot=super(BokehRenderer, self_or_cls).get_plot(obj, doc, renderer, **kwargs)
74ifplot.documentisNone:
75plot.document=Document() ifself_or_cls.notebook_contextelsecurdoc()
File~\.conda\envs\geo\lib\site-packages\holoviews\plotting\renderer.py:243, inRenderer.get_plot(self_or_cls, obj, doc, renderer, comm, **kwargs)
240defaults= [kd.defaultforkdinplot.dimensions]
241init_key=tuple(vifdisNoneelsedforv, din242zip(plot.keys[0], defaults))
-->243plot.update(init_key)
244else:
245plot=objFile~\.conda\envs\geo\lib\site-packages\holoviews\plotting\plot.py:991, inDimensionedPlot.update(self, key)
989defupdate(self, key):
990iflen(self) ==1and ((key==0) or (key==self.keys[0])) andnotself.drawn:
-->991returnself.initialize_plot()
992item=self.__getitem__(key)
993self.traverse(lambdax: setattr(x, '_updated', True))
File~\.conda\envs\geo\lib\site-packages\geoviews\plotting\bokeh\plot.py:111, inGeoPlot.initialize_plot(self, ranges, plot, plots, source)
109definitialize_plot(self, ranges=None, plot=None, plots=None, source=None):
110opts= {} ifisinstance(self, HvOverlayPlot) else {'source': source}
-->111fig=super(GeoPlot, self).initialize_plot(ranges, plot, plots, **opts)
112ifself.geographicandself.show_boundsandnotself.overlaid:
113from . importGeoShapePlotFile~\.conda\envs\geo\lib\site-packages\holoviews\plotting\bokeh\element.py:1409, inElementPlot.initialize_plot(self, ranges, plot, plots, source)
1407# Initialize plot, source and glyph1408ifplotisNone:
->1409plot=self._init_plot(key, style_element, ranges=ranges, plots=plots)
1410self._init_axes(plot)
1411else:
File~\.conda\envs\geo\lib\site-packages\holoviews\plotting\bokeh\element.py:496, inElementPlot._init_plot(self, key, element, plots, ranges)
489""" 490 Initializes Bokeh figure to draw Element into and sets basic 491 figure and axis attributes including axes types, labels, 492 titles and plot height and width. 493 """494subplots=list(self.subplots.values()) ifself.subplotselse []
-->496axis_types, labels, plot_ranges=self._axes_props(plots, subplots, element, ranges)
497xlabel, ylabel, _=labels498x_axis_type, y_axis_type=axis_typesFile~\.conda\envs\geo\lib\site-packages\holoviews\plotting\bokeh\element.py:407, inElementPlot._axes_props(self, plots, subplots, element, ranges)
405# Get the Element that determines the range and get_extents406range_el=elifself.batchedandnotisinstance(self, OverlayPlot) elseelement-->407l, b, r, t=self.get_extents(range_el, ranges)
408ifself.invert_axes:
409l, b, r, t=b, l, t, rFile~\.conda\envs\geo\lib\site-packages\geoviews\plotting\plot.py:73, inProjectionPlot.get_extents(self, element, ranges, range_type)
71extents=None72else:
--->73extents=project_extents(extents, element.crs, proj)
74return (np.NaN,)*4ifnotextentselseextentsFile~\.conda\envs\geo\lib\site-packages\geoviews\util.py:102, inproject_extents(extents, src_proj, dest_proj, tol)
100geom_in_src_proj=geom_clipped_to_dest_proj101try:
-->102geom_in_crs=dest_proj.project_geometry(geom_in_src_proj, src_proj)
103exceptValueError:
104src_name=type(src_proj).__name__File~\.conda\envs\geo\lib\site-packages\cartopy\crs.py:805, inProjection.project_geometry(self, geometry, src_crs)
803ifnotmethod_name:
804raiseValueError(f'Unsupported geometry type {geom_type!r}')
-->805returngetattr(self, method_name)(geometry, src_crs)
File~\.conda\envs\geo\lib\site-packages\cartopy\crs.py:941, inProjection._project_polygon(self, polygon, src_crs)
939is_ccw=True940else:
-->941is_ccw=polygon.exterior.is_ccw942# Project the polygon exterior/interior rings.943# Each source ring will result in either a ring, or one or more944# lines.945rings= []
File~\.conda\envs\geo\lib\site-packages\shapely\geometry\polygon.py:99, inLinearRing.is_ccw(self)
96 @property97defis_ccw(self):
98"""True is the ring is oriented counter clock-wise"""--->99returnbool(self.impl['is_ccw'](self))
File~\.conda\envs\geo\lib\site-packages\shapely\algorithms\cga.py:14, inis_ccw_impl.<locals>.is_ccw_op(ring)
13defis_ccw_op(ring):
--->14returnsigned_area(ring) >=0.0File~\.conda\envs\geo\lib\site-packages\shapely\algorithms\cga.py:7, insigned_area(ring)
3"""Return the signed area enclosed by a ring in linear time using the 4 algorithm at: https://web.archive.org/web/20080209143651/http://cgafaq.info:80/wiki/Polygon_Area 5 """6xs, ys=ring.coords.xy---->7xs.append(xs[1])
8ys.append(ys[1])
9returnsum(xs[i]*(ys[i+1]-ys[i-1]) foriinrange(1, len(ring.coords)))/2.0IndexError: arrayindexoutofrange
:Polygons [Longitude,Latitude] (id,name)
gv.Polygons defaults to PlateCarree, which is why both of those examples give an IndexError. hvplot without any inputs works because it only outputs an Holoviews plot. If you set geo=True it will also give an IndexError.
I think you get an IndexError because your data is projected coordinates with a geographic coordinates system.
Your solution of setting crs looks fine to me. Alternative, you can change the CRS of the GeoDataFrame with t = t.set_crs("EPSG:3857", allow_override=True).to_crs("EPSG:4326") (not sure if those are the correct CRS).
ALL software version info
python == 3.9.13
geoviews == 1.9.5
holoviews == 1.14.8
shapely == 1.8.2
cartopy == 0.20.3
bokeh == 2.4.2
matplotlib == 3.5.1
Description of expected behavior and the observed behavior
In attempting to plot a geometry from a shape file from the census.gov repo, I'm experiencing errors when using the default crs argument(Plate Carree) of gv.Polygons.
The same error persists when assigning Plate Carree as the crs to use with hvplot, when changing the plotting backend from bokeh to matplotlib, and when changing the crs with geopandas(to_crs).
Other crs projections do appear to work when set in the plotting function, such as Mercator, GOOGLE_MERCATOR, and EckertII, and default hvplot method.
Complete, minimal, self-contained example code that reproduces the issue
From Notebook:
IndexError
test_geo.zip
gv.Polygons with Mercator crs:
The text was updated successfully, but these errors were encountered: