Giter VIP home page Giter VIP logo

czml's Introduction

Introduction

This is an open source python library to read and write CZML files for Cesium, the WebGL Earth modeling engine.

Requirements

Tests

To run the tests (in the czml directory):

> python setup.py test

czml is continually tested with Travis CI

https://api.travis-ci.org/cleder/czml.png https://coveralls.io/repos/cleder/czml/badge.png?branch=master

Usage and Examples

Reading CZML

Reading a CZML file into a mutable document object can be done by initializing a CZML document and then reading the file's contents into the loads() method on the document, like so:

# Import the library
from czml import czml

# Read an existing CZML file
filename = 'example.czml'
with open(filename, 'r') as example:
    doc = czml.CZML()
    doc.loads(example.read())

Writing CZML

The general approach to writing CZML with this python library is to define a document object, define packets and append them to the document, and then write the document to a file using the write() method:

# Import the library
from czml import czml

# Initialize a document
doc = czml.CZML()

# Create and append the document packet
packet1 = czml.CZMLPacket(id='document',version='1.0')
doc.packets.append(packet1)

# Create and append a billboard packet
packet2 = czml.CZMLPacket(id='billboard')
bb = czml.Billboard(scale=0.7, show=True)
bb.image = 'http://localhost/img.png'
bb.color = {'rgba': [0, 255, 127, 55]}
packet2.billboard = bb
doc.packets.append(packet2)

# Write the CZML document to a file
filename = "example.czml"
doc.write(filename)

Supported CZML Components

The components in this library are developed to follow the CZML Content documentation. Supported components and subcomponents are listed in docs/COMPONENTS.md.

czml's People

Contributors

alexsnipes avatar bkuster avatar cleder avatar frencil avatar ianlee1521 avatar osh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

czml's Issues

Use of Clock is not documented

  1. czml.czml.Clock is not exported, i.e. it's not available as czml.Clock as other primitives are (but czml.CZMLPacket accepts dict of properties for Clock).

  2. currentTime, multiplier, range and step attributes have no defaults, so they must be specified.

Example of how I use Clock in my code:

        packet = czml.CZMLPacket(
            id='document',
            version='1.0',
            clock=czml.czml.Clock(
                currentTime=datetime.datetime.now().isoformat(),
                multiplier=1.0,
                range='CLAMPED',
                step='SYSTEM_CLOCK_MULTIPLIER',
            )
        )

Bug in czml.py

There appears to be a copy-n-paste type error in czml.py, line 1514 (version 0.3.2):

p.load(point)

should be

p.load(orientation)

Example in README does not work

Hi I'm not getting the example in README.rst to work, using python 2.7.

Added an import of json, and changed to capitals on doc = czml.CZML() and moved bb.show = True from initialization to script.

Import the library

from czml import czml
import json

Initialize a document

doc = czml.CZML()

Create and append the document packet

packet1 = czml.CZMLPacket(id='document',version='1.0')
doc.packets.append(packet1)

Create and append a billboard packet

packet2 = czml.CZMLPacket(id='billboard')
bb = czml.Billboard(scale=0.7) #, show=True
bb.show = True
bb.image = 'http://localhost/img.png'
bb.color = {'rgba': [0, 255, 127, 55]}
packet2.billboard = bb
doc.packets.append(packet2)

Write the CZML document to a file

filename = "example.czml"
with open(filename, 'w') as file:
json.dump(doc.data(), file)

I however get an error on last line:
182
183 """
--> 184 raise TypeError(repr(o) + " is not JSON serializable")
185
186 def encode(self, o):

TypeError: <generator object data at 0x0000000004792CA8> is not JSON serializable

Best way to write fields of vectors in CZML?

@cleder, as described TerriaJS/terriajs#1063 we are trying to figure out how to get vector fields into TerriaJS, like this one:
2015-11-11_9-41-48
(See the full Jupyter notebook in case you are interested in how this was generated)

It has been suggested to use CZML, and I'm wondering whether it's best to take the approach suggested to use billboards (scaled/rotated icons), or whether we could use the agi_vector described here: https://github.com/AnalyticalGraphicsInc/cesium/wiki/CZML-Content#agi_vector

Do you have a suggestion of which approach to take?
Could I use your czml python package to write either of these?

key error on loads()

I am trying to read a simple czml file (see below)

trying as per the readme

doc = czml.CZML()
with open(fpath, 'r') as f:
doc.loads(f.read())

fails with a ValueError on bb.load(billboard) in czml.pyc

Any suggestions?

Many thanks


simple.czml

(from https://github.com/AnalyticalGraphicsInc/cesium/wiki/CZML-in-Cesium)

[
{
"id":"Headquarters",
"availability":"2012-06-20T16:00:00Z/2012-06-20T16:02:00Z",
"position":{
"cartesian":[
1216469.9357990976,-4736121.71856379,4081386.8856866374
]
},
"billboard":{
"color":{
"rgba":[
0,255,255,255
]
},
"horizontalOrigin":"CENTER",
"image":"http://cesiumjs.org/images/Cesium_Logo.png",
"scale":1.0,
"show":[
{
"interval":"2012-06-20T16:00:00Z/2012-06-20T16:02:00Z",
"boolean":true
}
],
"verticalOrigin":"CENTER"
}
}
]

More complex examples?

It would be cool to have some more complex examples. Is there a discussion group where we could ask for contributions?

Remove Python 2.6 support?

The Problem

This is really a question for @cleder. On Build #40 I learned why there are so many tests shaped like this:

with self.assertRaises(Exception):
    foo = czml.Object(args...)

That are commented out. In Python 2.6 and below unittest.assertRaises() expects three arguments, where 2.7 and up are okay with the single argument. As a result it's impossible (or I don't know how) to build unit tests confirming exceptions and type errors are raised with invalid object creation, as in the example above.

Specifically in d6df512 I added a test for setting version on a CZMLPacket as it's instantiated where the documentation is clear that this is only valid on the document object. From personal experience with CZML I've found that setting version on other objects will result in invalid CZML, so it's an important test to have in place:

# Test that version can only be added to the document object (id='document')
with self.assertRaises(Exception):
    doc = czml.CZMLPacket(id='foo', version='1.0')

(this was commented in cd50ef3)

There are a handful of other such unit tests built within a context manager like this currently commented out in test_DateTimeAware, testCone, and testEllipsoid. Presumably they work in 2.7 and up, and presumably they're good tests to have in the suite.

Potential Solutions

  1. Only build unit tests that work on all supported versions of Python (e.g. don't use a context manager with unittest.assertRaises())
  2. Wrap unit tests that error on Python 2.6 in a version check so they never fire on 2.6 and below
  3. Remove Python 2.6 support altogether

We're effectively doing solution 1 right now but it's limiting. I lean toward solution 3 for its simplicity, but I don't know how critical support of 2.6 is among users of this module.

Demo broken in Python 3.6. czml.CZML().load() is not working

This is the code

# Import the library
from czml import czml
if __name__ == "__main__":
    # Read an existing CZML file
    filename = 'data/simple.czml'
    with open(filename, 'r') as example:
        doc = czml.CZML()
        doc.loads(example.read())

    print(doc)
    pass

Its failing on isinstance(description, Description) on line 1393 in czml.py.
It apparently a unicode string is not an instance of Description.

Errors here:
  File "C:\Users\...\venv\lib\site-packages\czml\czml.py", line 1402, in description
    raise TypeError
TypeError

Here is the CZML file (super_simple.czml).

[
  {
    "id":"document",
    "name":"simple",
    "version":"1.0",
    "clock":{
      "interval":"2012-03-15T10:00:00Z/2012-03-16T10:00:00Z",
      "currentTime":"2012-03-15T10:00:00Z",
      "multiplier":60,
      "range":"LOOP_STOP",
      "step":"SYSTEM_CLOCK_MULTIPLIER"
    }
  },
  {
    "id":"0653255a-81a7-4c2c-b154-f987e54767ac",
    "name":"Accesses",
    "description":"<p>List of Accesses</p>"
  }
 ]

Add LICENSE file to Github repository

The setup.py file calls out the license as LGPL. Please add a LICENSE file to the Github repository so that Github properly shows the license information.

how to add a description element?

I'm writing a script to convert bird migration data in CSV files to CZML. It's working well so far, but I'd like to add a description element as per this suggestion from Kevin Ring:
TerriaJS/terriajs#1275 (comment)

When I try to add this to my script here:
https://gist.github.com/rsignell-usgs/d0b1fd95f79204a50814#file-bird2czml-py-L110
I get no errors, but the output CZML file doesn't contain the description.

I looked at the code and it seems like there is some description stuff in there:
https://github.com/cleder/czml/blob/master/czml/test_main.py#L1015-L1017
but I couldn't figure out how to use it.

Is the description element actually implemented?
If so, how do I use it?

Add interval support

In beginning to use this library for automating the generation of CZML documents I've traditionally built by hand I've noticed that the interval attribute, commonly used on many different elements, has not been built out.

I intend to try to build this out against my fork and commit it upstream, but am filing this issue for documentation and discussion. I'm somewhat new to both Python and CZML.

For starters, I assume _interval should be defined within the DateTimeAware class. It's similar to epoch though it has two datetime values instead of one but is still ultimately represented as a string. Is trying to represent both start and stop datetimes of an interval value too complicated, since intrevals in CZML are strings? Example from the CZML Documentation on Intervals:

{
    "id": "myObject",
    "someProperty": [
        {
            "interval": "2012-04-30T12:00:00Z/13:00:00Z",
            "number": 5
        },
        {
            "interval": "2012-04-30T13:00:00Z/14:00:00Z",
            "number": 6
        },
    ]
}

This documentation also shows how intervals can be used generally by taking a given attribute of an object (e.g. a scalar value) and optionally expanding it to be an object with two attributes: an interval and the original value. I'm not entirely sure how best to build this out since it is so generally applicable. Any input would be very helpful!

Note: specifically I have a use case for using this library to generate CZML documents that utilize the clock and loop over a given interval. That's where the Clock pull request originated. Without interval support looping clocks (using LOOP_STOP as the range value) are not possible. Clock support and Interval support were distinct enough that it made sense to split them into two branches.

Advantages?

Is there any advantage to using this over straight JSON besides data validation? I noticed that it makes sure properties are set that are required in some cases, however I also noticed that it completely ignores properties it's not aware of and only supports a very small subset of the current CZML spec.

as_shape no longer exported from pygeotif.geometry

from pygeoif.geometry import as_shape as asShape

Line 46 of czml.py attempts to import as_shape from pygeoif.geometry. Since the 1.0 release this isn't exported anymore leading to an import error when loading the package.

A quick solution would be to peg pygeoif to version 0.6.
I'm so far unsure what can be used in it's place, but updating the usage would be better in the long term.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.