Skip to content

Instantly share code, notes, and snippets.

@epifanio
Last active August 29, 2015 14:26
Show Gist options
  • Save epifanio/0c1cbb2d4cd74aa2b6a1 to your computer and use it in GitHub Desktop.
Save epifanio/0c1cbb2d4cd74aa2b6a1 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"metadata": {
"collapsed": false,
"trusted": true
},
"cell_type": "code",
"source": "gc = [{'a12': 1.2424041724466862e-17,\n 'azi1': 24.878435238288187,\n 'azi2': 24.878435238288187,\n 'lat1': 43,\n 'lat2': 43.0,\n 'lon1': -75,\n 'lon2': -75.0,\n 's12': 0},\n {'a12': 0.899911483312531,\n 'azi1': 24.878435238288187,\n 'azi2': 25.23776315835231,\n 'lat1': 43,\n 'lat2': 43.81537441790592,\n 'lon1': -75,\n 'lon2': -74.47711680524627,\n 's12': 100000},\n {'a12': 1.7997800704227755,\n 'azi1': 24.878435238288187,\n 'azi2': 25.612497757228315,\n 'lat1': 43,\n 'lat2': 44.62817423964098,\n 'lon1': -75,\n 'lon2': -73.93983033288103,\n 's12': 200000}]",
"execution_count": 1,
"outputs": []
},
{
"metadata": {
"collapsed": false,
"trusted": true
},
"cell_type": "code",
"source": "lat = [i['lat2'] for i in gc]\nlon = [i['lon2'] for i in gc]",
"execution_count": 2,
"outputs": []
},
{
"metadata": {
"collapsed": false,
"trusted": true
},
"cell_type": "code",
"source": "lat",
"execution_count": 3,
"outputs": [
{
"data": {
"text/plain": "[43.0, 43.81537441790592, 44.62817423964098]"
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"collapsed": false,
"trusted": true
},
"cell_type": "code",
"source": "lon",
"execution_count": 4,
"outputs": [
{
"data": {
"text/plain": "[-75.0, -74.47711680524627, -73.93983033288103]"
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"collapsed": true,
"trusted": true
},
"cell_type": "code",
"source": "mp = [(item['lon2'], item['lat2']) for item in gc ] ",
"execution_count": 5,
"outputs": []
},
{
"metadata": {
"collapsed": false,
"trusted": true
},
"cell_type": "code",
"source": "mp",
"execution_count": 46,
"outputs": [
{
"data": {
"text/plain": "[(-75.0, 43.0),\n (-74.47711680524627, 43.81537441790592),\n (-73.93983033288103, 44.62817423964098)]"
},
"execution_count": 46,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"collapsed": false,
"trusted": true
},
"cell_type": "code",
"source": "a = []\nfor p in mp: a.extend([p[0],p[1],0])",
"execution_count": 6,
"outputs": []
},
{
"metadata": {
"collapsed": false,
"trusted": true
},
"cell_type": "code",
"source": "a",
"execution_count": 7,
"outputs": [
{
"data": {
"text/plain": "[-75.0,\n 43.0,\n 0,\n -74.47711680524627,\n 43.81537441790592,\n 0,\n -73.93983033288103,\n 44.62817423964098,\n 0]"
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"collapsed": false,
"trusted": true
},
"cell_type": "code",
"source": "from geojson import MultiPoint, LineString\nf = open('new.geojson','w')\nf.write(str(LineString(mp)))\nf.close()",
"execution_count": 8,
"outputs": []
},
{
"metadata": {},
"cell_type": "markdown",
"source": "##GeoJson"
},
{
"metadata": {
"collapsed": false,
"trusted": true
},
"cell_type": "code",
"source": "!/usr/local/bin/gist -p new.geojson",
"execution_count": 9,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "https://gist.github.com/062ff6c2cc8e05c7a5dd\r\n"
}
]
},
{
"metadata": {
"collapsed": false,
"trusted": true
},
"cell_type": "code",
"source": "a=[]\nfor v in mp:\n for j in v:\n a.append(j)\n a.append(0) ",
"execution_count": 10,
"outputs": []
},
{
"metadata": {
"collapsed": false,
"trusted": true
},
"cell_type": "code",
"source": "a",
"execution_count": 11,
"outputs": [
{
"data": {
"text/plain": "[-75.0,\n 43.0,\n 0,\n -74.47711680524627,\n 43.81537441790592,\n 0,\n -73.93983033288103,\n 44.62817423964098,\n 0]"
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"collapsed": false,
"trusted": true
},
"cell_type": "code",
"source": "t = [(item['lon2'], item['lat2']) for item in gc ] ",
"execution_count": 12,
"outputs": []
},
{
"metadata": {
"collapsed": true,
"trusted": true
},
"cell_type": "code",
"source": "a = []\nfor item in t:\n a.extend(item)\n a.append(0)",
"execution_count": 13,
"outputs": []
},
{
"metadata": {
"collapsed": false,
"trusted": true
},
"cell_type": "code",
"source": "a",
"execution_count": 14,
"outputs": [
{
"data": {
"text/plain": "[-75.0,\n 43.0,\n 0,\n -74.47711680524627,\n 43.81537441790592,\n 0,\n -73.93983033288103,\n 44.62817423964098,\n 0]"
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "---"
},
{
"metadata": {
"collapsed": false,
"trusted": true
},
"cell_type": "code",
"source": "from grass.pygrass.vector import VectorTopo\nfrom grass.pygrass.vector.geometry import Point",
"execution_count": 1,
"outputs": []
},
{
"metadata": {
"collapsed": true,
"trusted": true
},
"cell_type": "code",
"source": "import pyproj",
"execution_count": 2,
"outputs": []
},
{
"metadata": {
"collapsed": false,
"trusted": true
},
"cell_type": "code",
"source": "prj = !g.proj -j\nprj = ' '.join(prj)\nprj",
"execution_count": 3,
"outputs": [
{
"data": {
"text/plain": "'+proj=lcc +lat_1=36.16666666666666 +lat_2=34.33333333333334 +lat_0=33.75 +lon_0=-79 +x_0=609601.22 +y_0=0 +no_defs +a=6378137 +rf=298.257222101 +towgs84=0.000,0.000,0.000 +to_meter=1'"
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"collapsed": true,
"trusted": true
},
"cell_type": "code",
"source": "p1 = pyproj.Proj(prj)",
"execution_count": 4,
"outputs": []
},
{
"metadata": {
"collapsed": false,
"trusted": true
},
"cell_type": "code",
"source": "from czml_templates import polyline_tpl, czml_tpl\nimport numpy as np\n\ndef polyline(width=1, rgba=(0,255,255,255), coorstype=\"cartographicDegrees\", coors=[], id=\"\", description=\"\"):\n polyline = polyline_tpl % (width, rgba[0], rgba[1], rgba[2], rgba[3], coorstype, coors, id, description)\n return polyline\n\ndef czml(features):\n czml=czml_tpl % features\n return czml",
"execution_count": 5,
"outputs": []
},
{
"metadata": {
"collapsed": false,
"trusted": true
},
"cell_type": "code",
"source": "railroads = VectorTopo('railroads')",
"execution_count": 6,
"outputs": []
},
{
"metadata": {
"collapsed": false,
"trusted": true
},
"cell_type": "code",
"source": "railroads.open('r')",
"execution_count": 7,
"outputs": []
},
{
"metadata": {
"collapsed": false,
"trusted": true
},
"cell_type": "code",
"source": "dictionary = dict(zip(railroads[1].attrs.keys(), railroads[1].attrs.values()))\ndictionary",
"execution_count": 28,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": "{u'FNODE_': 1,\n u'LENGTH': 11200.273438,\n u'LPOLY_': 2,\n u'MAJOR1': 180,\n u'MINOR1': 201,\n u'OBJECTID': 1,\n u'RPOLY_': 2,\n u'RR24_100_': 1,\n u'RR24_100_I': 13,\n u'SCALE': 24000,\n u'TNODE_': 4,\n u'cat': 1}"
},
"metadata": {},
"execution_count": 28
}
]
},
{
"metadata": {
"collapsed": false,
"trusted": true
},
"cell_type": "code",
"source": "testtable=\"\"\"FNODE_: 1 \\n LENGTH: 11200.273438 \\n LPOLY_: 2 \\n MAJOR1: 180 \\n MINOR1: 201 \\n OBJECTID: 1 \\n RPOLY_: 2 \\n RR24_100_: 1 \\n RR24_100_I: 13 \\n SCALE: 24000 \\n TNODE_: 4 \\n cat: 1\"\"\"",
"execution_count": 32,
"outputs": []
},
{
"metadata": {
"collapsed": false,
"trusted": true
},
"cell_type": "code",
"source": "pl=[]\nfor i in range(railroads.n_lines):\n ls = railroads[i+1].get_wkt().replace(\"LINESTRING(\",\"\").replace(\")\",\"\").strip().split(\",\")\n a = []\n extenda = [a.extend([p1(float(p.strip().split(\" \")[0]),\n float(p.strip().split(\" \")[1]), \n inverse=True)[0],\n p1(float(p.strip().split(\" \")[0]),\n float(p.strip().split(\" \")[1]), \n inverse=True)[1],0]) \n for p in ls]\n idtest = 'test_'+str(i)\n dictionary = dict(zip(railroads[i+1].attrs.keys(), railroads[i+1].attrs.values()))\n pl.append(polyline(coors=a, id=idtest, description=dictionary))\n \n\nfeatures = ','.join(pl)\npolyline2 = czml(features)",
"execution_count": 52,
"outputs": []
},
{
"metadata": {
"collapsed": false,
"trusted": true
},
"cell_type": "code",
"source": "from CesiumWidget import CesiumWidget",
"execution_count": 53,
"outputs": []
},
{
"metadata": {
"collapsed": true,
"trusted": true
},
"cell_type": "code",
"source": "cesiumExample = CesiumWidget(width=\"100%\", czml=polyline2)",
"execution_count": 56,
"outputs": []
},
{
"metadata": {
"collapsed": true,
"trusted": true
},
"cell_type": "code",
"source": "cesiumExample",
"execution_count": 55,
"outputs": []
},
{
"metadata": {
"trusted": true,
"collapsed": true
},
"cell_type": "code",
"source": "",
"execution_count": null,
"outputs": []
}
],
"metadata": {
"kernelspec": {
"name": "python2",
"display_name": "Python 2",
"language": ""
},
"language_info": {
"name": "python",
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"version": "2.7.6",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"mimetype": "text/x-python",
"file_extension": ".py"
},
"gist_id": "0c1cbb2d4cd74aa2b6a1"
},
"nbformat": 4,
"nbformat_minor": 0
}
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment