def _geojs_filename_changed(self, name):
        data = file(name).read()
        polys = process_raw(data.replace('\r\n', ''))
        # Generate compiled path from the polygons
        paths = []
        for poly in polys:
            path = CompiledPath()
            for p in poly:
                path.lines(p)
            paths.append(path)
        self._paths = paths

        red = np.array([202, 0, 32])/255.
        blue = np.array([5, 113, 176])/255.
        colors = red * np.random.random_integers(0,1,len(paths)).reshape(-1,1)
        colors[np.sum(colors,axis=-1)==0] = blue
        self._colors = colors

        # Store the polygons just in case we need to regenerate the path
        self._polys = polys
        self.request_redraw()
    def _geojs_filename_changed(self, name):
        data = file(name).read()
        polys = process_raw(data.replace('\r\n', ''))
        # Generate compiled path from the polygons
        paths = []
        for poly in polys:
            path = CompiledPath()
            for p in poly:
                path.lines(p)
            paths.append(path)
        self._paths = paths

        red = np.array([202, 0, 32]) / 255.
        blue = np.array([5, 113, 176]) / 255.
        colors = red * np.random.random_integers(0, 1, len(paths)).reshape(
            -1, 1)
        colors[np.sum(colors, axis=-1) == 0] = blue
        self._colors = colors

        # Store the polygons just in case we need to regenerate the path
        self._polys = polys
        self.request_redraw()
Exemple #3
0
    def _data_columns_default(self):
        return list(self.dataframe.columns[1:][::-1])


if __name__ == "__main__":
    populations = pandas.read_csv('state_populations.csv')

    from mapping.enable.geojson_overlay import process_raw
    polys = process_raw(file("states.geojs").read().replace('\r\n', ''))
    # generate compiled paths from polys
    paths = []
    coords = numpy.zeros((len(polys), 2))
    for poly, coord in zip(polys, coords):
        path = CompiledPath()
        total = numpy.sum((numpy.sum(p, axis=0) for p in poly), axis=0)
        coord[:] = total / sum(map(len, poly))
        for p in poly:
            path.lines(p - coord)  # recenter on origin
        paths.append(path)

    with enaml.imports():
        from choropleth_view import MapView

    view = MapView(model=Demo(title="State population from 1900 to 2010",
                              index_ds=ArrayDataSource(coords[:, 0]),
                              value_ds=ArrayDataSource(coords[:, 1]),
                              paths=paths,
                              dataframe=populations), )

    view.show()
   

if __name__ == "__main__":
    populations = pandas.read_csv('example/state_populations.csv')

    from mapping.enable.geojson_overlay import process_raw
    polys = process_raw(file("example/states.geojs").read().replace('\r\n',''))
    # generate compiled paths from polys
    paths = []
    coords = numpy.zeros((len(polys), 2))
    for poly, coord in zip(polys, coords):
        path = CompiledPath()
        total = numpy.sum((numpy.sum(p, axis=0) for p in poly), axis=0)
        coord[:] = total/sum(map(len,poly))
        for p in poly:
            path.lines(p - coord) # recenter on origin
        paths.append(path)

    with enaml.imports():
        from choropleth_view import MapView
        
    view = MapView(
        model = Demo(title = "State population from 1900 to 2010",
                     index_ds = ArrayDataSource(coords[:,0]),
                     value_ds = ArrayDataSource(coords[:,1]),
                     paths = paths,
                     dataframe = populations),
    )

    view.show()