geoplotlib icon indicating copy to clipboard operation
geoplotlib copied to clipboard

Modifying the projection in one layer does not trigger projecting again in the other layers

Open andrea-cuttone opened this issue 8 years ago • 0 comments

For example in https://github.com/andrea-cuttone/geoplotlib/blob/master/examples/follow_camera.py, changing the bottom part to:

otherdata = read_csv('data/taxi.csv')
geoplotlib.dot(otherdata)
geoplotlib.add_layer(TrailsLayer())
geoplotlib.show()

leads to the dot map not being displayed. This is because the following happens:

  1. dot adds a new DotDensityLayer with his own projection
  2. TrailsLayer changes the projection at every frame, but this is not propagated to the original projected points for the DotDensityLayer

in fact, invalidating the layers at every frame (for example in https://github.com/andrea-cuttone/geoplotlib/blob/master/geoplotlib/core.py#L229).

The code should be changed so that changes in the projection are propagated to all layers.

A workaround for now is to render the dots in the same method where the projection is modified, using two separate painters:

    def draw(self, proj, mouse_x, mouse_y, ui_manager): 
        df = self.data.where((self.data['timestamp'] > self.t) & (self.data['timestamp'] <= self.t + 30*60))
        proj.fit(BoundingBox.from_points(lons=df['lon'], lats=df['lat']), max_zoom=14)

        allx, ally = proj.lonlat_to_screen(self.data['lon'], self.data['lat'])
        self.painter = BatchPainter()
        self.painter.set_color([255,0,0])
        self.painter.points(allx, ally)
        self.painter.batch_draw()

        x, y = proj.lonlat_to_screen(df['lon'], df['lat'])
        self.painter = BatchPainter()
        self.painter.set_color([0,0,255])
        self.painter.linestrip(x, y, 10)

        self.t += 30
        if self.t > self.data['timestamp'].max():
            self.t = self.data['timestamp'].min()

        self.painter.batch_draw()
        ui_manager.info(epoch_to_str(self.t))

Thanks to Zhicheng Liu for reporting the issue.

andrea-cuttone avatar Jun 15 '16 09:06 andrea-cuttone