Read External Files

Read External Files as Data Source

Cesium.js has a DataSource class which can draw external data as entities.

cesiumpy currently supports following DataSource.

  • GeoJsonDataSource
  • KmlDataSource
  • CzmlDataSource


Assuming we hanve following .geojson file named “example.geojson”.

    "type": "Point",
    "coordinates": [-118.27, 34.05 ]

You can create GeoJsonDataSource instannce then add to Viewer.DataSources. markerSymbol option specifies the symbol displayed on the marker.

>>> ds = cesiumpy.GeoJsonDataSource('./example.geojson', markerSymbol='!')
>>> v = cesiumpy.Viewer()
>>> v.dataSources.add(ds)
>>> v

Or, you can use load class method to instanciate DataSource like Cesium.js.

>>> cesiumpy.GeoJsonDataSource.load('./example.geojson', markerSymbol='!')


You can use KmlDataSource to read .kml files. Assuming we have following content:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns=""> <Placemark>
 </Placemark> </kml>
>>> ds = cesiumpy.KmlDataSource('example.kml')
>>> v = cesiumpy.Viewer()
>>> v.dataSources.add(ds)
>>> v


The last example uses CzmlDataSource to read .czml file downloaded from the Cesium.js repository

ds = cesiumpy.CzmlDataSource('sample.czml')
v = cesiumpy.Viewer()

Read External Files as Entities

cesiumpy can read following file formats using io module. The results are automatically converted to cesiumpy entities and can be added to map directly.

  • GeoJSON
  • Shapefile


This example reads GeoJSON file of Japanese land area. returns a list of cesiumpy.Polygon.

The file is provided by mledoze/countries repositry.

>>> res ='jpn.geo.json')
>>> type(res)

You can add the list as entities.

>>> viewer = cesiumpy.Viewer()
>>> viewer.entities.add(res)
>>> viewer

If you want to change some properties, passing keyword arguments via entities.add methods is easy. Of cource it is also OK to change properties of each entity one by one.

>>> viewer = cesiumpy.Viewer()
>>> viewer.entities.add(res, extrudedHeight=1e6, material='aqua')
>>> viewer


This example reads Shapefile of Japanese coastal lines. returns a list of cesiumpy.Polyline.

The file is provided by 地球地図日本 website.

  • 出典 (Source):国土地理院ウェブサイト
>>> res ='coastl_jpn.shp')
>>> type(res)

Then, you can add the result to the map.

>>> viewer = cesiumpy.Viewer()
>>> viewer.entities.add(res, material='red')
>>> viewer

Bundled Data

cesiumpy bundles GeoJSON data provided by mledoze/countries repositry. You can load them via cesiumpy.countries.get method passing country code or its name.

Please refer to countries.json file to check available country codes (“cca2” or “cca3”) and names (“official name”).

>>> usa = cesiumpy.countries.get('USA')
>>> viewer = cesiumpy.Viewer()
>>> viewer.entities.add(usa, material='red')
>>> viewer

Read 3D Models

Cesium.js can handle 3D Model on the map. For Cesium.js functionality, please refer to 3D Model Tutorial.

cesiumpy allows to put 3D Model using cesiumpy.Model instance. Following example shows to draw Cesium Man used in the above tutorial.

>>> m = cesiumpy.Model(url='data/Cesium_Man.gltf',
...                    modelMatrix=(-130, 40, 0.0), scale=1000000)
>>> m

>>> viewer = cesiumpy.Viewer()
>>> viewer.scene.primitives.add(m)
>>> viewer