Skip to content

Commit

Permalink
Merge pull request #54 from sinhrks/doc_update
Browse files Browse the repository at this point in the history
DOC: Update external file doc
  • Loading branch information
sinhrks committed Feb 28, 2016
2 parents 72d2567 + b1f5e2e commit 29d0167
Show file tree
Hide file tree
Showing 6 changed files with 258 additions and 76 deletions.
Binary file added doc/source/_static/3dmodel01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/source/_static/datasources03.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
65 changes: 2 additions & 63 deletions doc/source/basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -268,68 +268,6 @@ Passing ``requestWaterMask=True`` enables water effects.
.. image:: ./_static/terrain02.png


Add Data Sources
----------------

`Cesium.js <http://cesiumjs.org/>`_ has a ``DataSource`` function which
can draw external data as entities.

``cesiumpy`` currently supports following ``DataSource``.

- ``CzmlJsonDataSource``
- ``GeoJsonDataSource``
- ``KmlDataSource``

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.

.. code-block:: python
>>> ds = cesiumpy.GeoJsonDataSource('./example.geojson', markerSymbol='!')
>>> v = cesiumpy.Viewer()
>>> v.dataSources.add(ds)
>>> v
.. image:: ./_static/datasources01.png

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

.. code-block:: python
>>> 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="http://www.opengis.net/kml/2.2"> <Placemark>
<name>?</name>
<Point>
<coordinates>-118.27,34.05,0</coordinates>
</Point>
</Placemark> </kml>


.. code-block:: python
>>> ds = cesiumpy.KmlDataSource(os.path.join('data', 'example.kml'))
>>> v = cesiumpy.Viewer()
>>> v.dataSources.add(ds)
>>> v
.. image:: ./_static/datasources02.png

Geocoding
---------

Expand All @@ -349,4 +287,5 @@ You can use ``str`` specifying location where you can use coordinates as below.
>>> v.camera.flyTo('Los Angeles')
>>> v
.. image:: ./_static/geocoding01.png
.. image:: ./_static/geocoding01.png

110 changes: 108 additions & 2 deletions doc/source/io.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,88 @@
Read External Files
===================

Read External Files as Data Source
==================================

`Cesium.js <http://cesiumjs.org/>`_ has a ``DataSource`` class which
can draw external data as entities.

``cesiumpy`` currently supports following ``DataSource``.

- ``GeoJsonDataSource``
- ``KmlDataSource``
- ``CzmlDataSource``

GeoJSON
-------

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.

.. code-block:: python
>>> ds = cesiumpy.GeoJsonDataSource('./example.geojson', markerSymbol='!')
>>> v = cesiumpy.Viewer()
>>> v.dataSources.add(ds)
>>> v
.. image:: ./_static/datasources01.png

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

.. code-block:: python
>>> cesiumpy.GeoJsonDataSource.load('./example.geojson', markerSymbol='!')
KML
---

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

::

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2"> <Placemark>
<name>?</name>
<Point>
<coordinates>-118.27,34.05,0</coordinates>
</Point>
</Placemark> </kml>


.. code-block:: python
>>> ds = cesiumpy.KmlDataSource('example.kml')
>>> v = cesiumpy.Viewer()
>>> v.dataSources.add(ds)
>>> v
.. image:: ./_static/datasources02.png

CZML
----

The last example is use ``.czml`` file downloaded from the
`Cesium.js repository <https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Apps/SampleData/simple.czml>`_

.. code-block:: python
ds = cesiumpy.CzmlDataSource('sample.czml')
v = cesiumpy.Viewer()
v.dataSources.add(ds)
v
.. image:: ./_static/datasources03.png

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
Expand Down Expand Up @@ -85,3 +168,26 @@ to check available country codes ("cca2" or "cca3") and names ("official name").
.. image:: ./_static/io_bundle01.png


Read 3D Models
==============

`Cesium.js <http://cesiumjs.org/>`_ can handle 3D Model on the map.
For ``Cesium.js`` functionality, please refer to `3D Model Tutorial <https://cesiumjs.org/tutorials/3D-Models-Tutorial/>`_.

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

.. code-block:: python
>>> m = cesiumpy.Model(url='data/Cesium_Man.gltf',
... modelMatrix=(-130, 40, 0.0), scale=1000000)
>>> m
Model("data/Cesium_Man.gltf")
>>> viewer = cesiumpy.Viewer()
>>> viewer.scene.primitives.add(m)
>>> viewer
.. image:: ./_static/3dmodel01.png

56 changes: 45 additions & 11 deletions examples/05_datasources.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
"collapsed": false
},
"outputs": [],
"source": [
Expand All @@ -23,16 +23,16 @@
"data": {
"text/html": [
"<script src=\"https://cesiumjs.org/Cesium/Build/Cesium/Cesium.js\"></script>\n",
"<link rel=\"stylesheet\" href=\"http://cesiumjs.org/Cesium/Build/CesiumUnminified/Widgets/widgets.css\" type=\"text/css\">\n",
"<div id=\"container-4344949456\" style=\"width:100%; height:100%;\"><div>\n",
"<link rel=\"stylesheet\" href=\"http://cesiumjs.org/Cesium/Build/Cesium/Widgets/widgets.css\" type=\"text/css\">\n",
"<div id=\"container-4347283856\" style=\"width:100%; height:100%;\"><div>\n",
"<script type=\"text/javascript\">\n",
" var widget = new Cesium.Viewer(\"container-4344949456\");\n",
" var widget = new Cesium.Viewer(\"container-4347283856\");\n",
" widget.dataSources.add(Cesium.GeoJsonDataSource.load(\"data/example.geojson\", {markerSymbol : \"!\"}));\n",
" widget.camera.flyTo({destination : Cesium.Cartesian3.fromDegrees(-118.27, 34.05, 10000)});\n",
" widget.camera.flyTo({destination : Cesium.Cartesian3.fromDegrees(-118.27, 34.05, 10000.0)});\n",
"</script>"
],
"text/plain": [
"<cesiumpy.viewer.Viewer at 0x102faaad0>"
"<cesiumpy.viewer.Viewer at 0x1031e4990>"
]
},
"execution_count": 2,
Expand Down Expand Up @@ -103,16 +103,16 @@
"data": {
"text/html": [
"<script src=\"https://cesiumjs.org/Cesium/Build/Cesium/Cesium.js\"></script>\n",
"<link rel=\"stylesheet\" href=\"http://cesiumjs.org/Cesium/Build/CesiumUnminified/Widgets/widgets.css\" type=\"text/css\">\n",
"<div id=\"container-4360476880\" style=\"width:100%; height:100%;\"><div>\n",
"<link rel=\"stylesheet\" href=\"http://cesiumjs.org/Cesium/Build/Cesium/Widgets/widgets.css\" type=\"text/css\">\n",
"<div id=\"container-4342069840\" style=\"width:100%; height:100%;\"><div>\n",
"<script type=\"text/javascript\">\n",
" var widget = new Cesium.Viewer(\"container-4360476880\");\n",
" var widget = new Cesium.Viewer(\"container-4342069840\");\n",
" widget.dataSources.add(Cesium.KmlDataSource.load(\"data/example.kml\"));\n",
" widget.camera.flyTo({destination : Cesium.Cartesian3.fromDegrees(-118.27, 34.05, 10000)});\n",
" widget.camera.flyTo({destination : Cesium.Cartesian3.fromDegrees(-118.27, 34.05, 10000.0)});\n",
"</script>"
],
"text/plain": [
"<cesiumpy.viewer.Viewer at 0x103e798d0>"
"<cesiumpy.viewer.Viewer at 0x102ceba50>"
]
},
"execution_count": 5,
Expand All @@ -128,6 +128,40 @@
"v"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<script src=\"https://cesiumjs.org/Cesium/Build/Cesium/Cesium.js\"></script>\n",
"<link rel=\"stylesheet\" href=\"http://cesiumjs.org/Cesium/Build/Cesium/Widgets/widgets.css\" type=\"text/css\">\n",
"<div id=\"container-4347281552\" style=\"width:100%; height:100%;\"><div>\n",
"<script type=\"text/javascript\">\n",
" var widget = new Cesium.Viewer(\"container-4347281552\");\n",
" widget.dataSources.add(Cesium.CzmlDataSource.load(\"data/example.czml\"));\n",
"</script>"
],
"text/plain": [
"<cesiumpy.viewer.Viewer at 0x1031e4090>"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ds = cesiumpy.CzmlDataSource(os.path.join('data', 'example.czml'))\n",
"v = cesiumpy.Viewer()\n",
"v.dataSources.add(ds)\n",
"v"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
103 changes: 103 additions & 0 deletions examples/08_3D_Model.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import cesiumpy"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"Model(\"data/Cesium_Man.gltf\")"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"m = cesiumpy.Model(url='data/Cesium_Man.gltf',\n",
" modelMatrix=(-130, 40, 0.0), scale=1000000)\n",
"m"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false,
"scrolled": true
},
"outputs": [
{
"data": {
"text/html": [
"<script src=\"https://cesiumjs.org/Cesium/Build/Cesium/Cesium.js\"></script>\n",
"<link rel=\"stylesheet\" href=\"http://cesiumjs.org/Cesium/Build/Cesium/Widgets/widgets.css\" type=\"text/css\">\n",
"<div id=\"viewertest\" style=\"width:100%; height:100%;\"><div>\n",
"<script type=\"text/javascript\">\n",
" var widget = new Cesium.Viewer(\"viewertest\");\n",
" widget.scene.primitives.add(Cesium.Model.fromGltf({url : \"data/Cesium_Man.gltf\", modelMatrix : Cesium.Transforms.eastNorthUpToFixedFrame(Cesium.Cartesian3.fromDegrees(-130.0, 40.0, 0.0)), scale : 1000000.0}));\n",
"</script>"
],
"text/plain": [
"<cesiumpy.viewer.Viewer at 0x1031fa150>"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"viewer = cesiumpy.Viewer(divid=\"viewertest\")\n",
"viewer.scene.primitives.add(m)\n",
"viewer"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

0 comments on commit 29d0167

Please sign in to comment.