Skip to content

Instantly share code, notes, and snippets.

@james-morrison-mowi
Last active February 15, 2018 12:44
Show Gist options
  • Save james-morrison-mowi/c3274ce7ba1d183d65381e8baefff417 to your computer and use it in GitHub Desktop.
Save james-morrison-mowi/c3274ce7ba1d183d65381e8baefff417 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 70,
"metadata": {},
"outputs": [],
"source": [
"gxf_file_path = '../Documents/Colonsay.039'"
]
},
{
"cell_type": "code",
"execution_count": 71,
"metadata": {},
"outputs": [],
"source": [
"gxf_layer_name, gxf_layer_id = gxf_file_path.split('/')[-1].split('.')"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"gxf_layer = open(gxf_file_path).readlines()"
]
},
{
"cell_type": "code",
"execution_count": 72,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Colonsay'"
]
},
"execution_count": 72,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"gxf_layer_name"
]
},
{
"cell_type": "code",
"execution_count": 73,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'039'"
]
},
"execution_count": 73,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"gxf_layer_id"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"internal_gxf_file_name = gxf_layer[1].split('\"')[1]"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"gxf_layer_description = gxf_layer[4].split('\"')[1]"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
"gxf_layer_limits = {'SW':list(filter(None,gxf_layer[9][:-1].split(' '))),\n",
" 'NW':list(filter(None,gxf_layer[10][:-1].split(' '))),\n",
" 'NE':list(filter(None,gxf_layer[11][:-1].split(' '))),\n",
" 'SE':list(filter(None,gxf_layer[12][:-1].split(' ')))}"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'NE': ['-6.1205887', '56.0974781'],\n",
" 'NW': ['-6.1313829', '56.0974781'],\n",
" 'SE': ['-6.1205887', '56.0914611'],\n",
" 'SW': ['-6.1313829', '56.0914611']}"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"gxf_layer_limits"
]
},
{
"cell_type": "code",
"execution_count": 66,
"metadata": {},
"outputs": [],
"source": [
"# Grab the line indexes for the marks\n",
"def get_mark_indexes(gxf_layer_lines):\n",
" mk_index = []\n",
" for index, gxf_line in enumerate(gxf_layer_lines):\n",
" if(gxf_line == '[ MK\\n'):\n",
" mk_index.append(index)\n",
" return mk_index"
]
},
{
"cell_type": "code",
"execution_count": 67,
"metadata": {},
"outputs": [],
"source": [
"def get_marks_df(gxf_layer_lines):\n",
" mk_index = get_mark_indexes(gxf_layer_lines)\n",
" mark_list = []\n",
" for mk in mk_index:\n",
" mark_dict = {}\n",
" for index in range(1,5):\n",
" mark_dict[gxf_layer[mk+index].split(' ')[0]] = gxf_layer[mk+index].split(' ')[1][:-1]\n",
" mark_dict['longitude'] = gxf_layer[mk+5].split(' ')[1]\n",
" mark_dict['latitude'] = gxf_layer[mk+5].split(' ')[2][:-1]\n",
" mark_list.append(mark_dict)\n",
" return pd.DataFrame(mark_list) "
]
},
{
"cell_type": "code",
"execution_count": 75,
"metadata": {},
"outputs": [],
"source": [
"gxf_marks_df = get_marks_df(gxf_layer)"
]
},
{
"cell_type": "code",
"execution_count": 86,
"metadata": {},
"outputs": [],
"source": [
"gxf_marks_df.to_csv(gxf_layer_name + '_' + gxf_layer_id + '_marks.csv')"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment