Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions combine_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
the file pointed to with the -o flag (features.geojson by default).

Author: Xylar Asay-Davis
Last Modified: 09/10/2016
Last Modified: 09/29/2016
"""

import json
Expand Down Expand Up @@ -104,14 +104,6 @@
print " points and transects) are being cobined."
sys.exit(1)

out_file = open(out_file_name, 'w')
out_file.write('{"type": "FeatureCollection",\n')
out_file.write(' "groupName": "enterNameHere",\n')
out_file.write(' "features":\n')
out_file.write('\t[\n')
write_all_features(features, out_file, '\t\t')
out_file.write('\n')
out_file.write('\t]\n')
out_file.write('}\n')
write_all_features(features, out_file_name, indent=4)

# vim: foldmethod=marker ai ts=4 sts=4 et sw=4 ft=python
29 changes: 12 additions & 17 deletions difference_features.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/usr/bin/env python
"""
This script takes a file containing one or more feature definitions, that is
pointed to by the -f flag and a second masking feature definition, pointed
to with the -m flag. The masking features are masked out of (i.e. removed
from) the original feature definitions. The resulting features are placed
in (or appended to) the output file pointed to with the -o flag
(features.geojson by default).
pointed to by the -f flag and a second set of one or more masking feature
definition, pointed to with the -m flag. The masking features are masked out
of (i.e. removed from) the original feature definitions. The resulting
features are placed in (or appended to) the output file pointed to with the
-o flag (features.geojson by default).

Authors: Xylar Asay-Davis
Last Modified: 02/12/2016
Last Modified: 09/29/2016
"""

import json
Expand All @@ -25,10 +25,11 @@
parser = argparse.ArgumentParser(description=__doc__,
formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument("-f", "--feature_file", dest="feature_file",
help="Single feature file to be clipped", metavar="FILE1",
help="Feature file to be clipped", metavar="FILE1",
required=True)
parser.add_argument("-m", "--mask_file", dest="mask_file",
help="Single feature whose overlap with the first feature should be removed",
help="Feature file with one or more features whose overlap "
"with features in feature_file should be removed",
metavar="FILE2", required=True)
parser.add_argument("-o", "--output", dest="output_file_name",
help="Output file, e.g., features.geojson.",
Expand Down Expand Up @@ -96,6 +97,8 @@
if featureShape.is_empty :
add = False
break
else:
print "Masked feature %s with mask %s"%(name,maskFeature['properties']['name'])

if(add):
if(masked):
Expand All @@ -105,14 +108,6 @@
else:
print "%s has been removed."%name

out_file = open(out_file_name, 'w')
out_file.write('{"type": "FeatureCollection",\n')
out_file.write(' "groupName": "enterNameHere",\n')
out_file.write(' "features":\n')
out_file.write('\t[\n')
write_all_features(features, out_file, '\t\t')
out_file.write('\n')
out_file.write('\t]\n')
out_file.write('}\n')
write_all_features(features, out_file_name, indent=4)

# vim: foldmethod=marker ai ts=4 sts=4 et sw=4 ft=python
17 changes: 4 additions & 13 deletions fix_features_at_antimeridian.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
The script makes use of the shapely library.

Author: Xylar Asay-Davis
Last Modified: 1/31/2016
Last Modified: 9/29/2016

"""

Expand Down Expand Up @@ -103,6 +103,8 @@ def fromPolar(x,y):

parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument("-f", "--features_file", dest="features_file", help="File containing features to split at the antimeridian", metavar="FILE", required=True)
parser.add_argument("-o", "--output", dest="output_file_name", help="Output file, e.g., features.geojson.", metavar="PATH", default="features.geojson")


args = parser.parse_args()

Expand All @@ -122,17 +124,6 @@ def fromPolar(x,y):
if(result is not None):
feature['geometry'] = result

out_file_name = "features.geojson"

out_file = open(out_file_name, 'w')

out_file.write('{"type": "FeatureCollection",\n')
out_file.write(' "groupName": "enterNameHere",\n')
out_file.write(' "features":\n')
out_file.write('\t[\n')
write_all_features(features_file, out_file, '\t\t')
out_file.write('\n')
out_file.write('\t]\n')
out_file.write('}\n')
write_all_features(features_file, args.output_file_name, indent=4)

# vim: foldmethod=marker ai ts=4 sts=4 et sw=4 ft=python
17 changes: 4 additions & 13 deletions fix_features_at_prime_meridian.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
The script makes use of the shapely library.

Author: Xylar Asay-Davis
Last Modified: 2/27/2016
Last Modified: 9/29/2016

"""

Expand Down Expand Up @@ -65,6 +65,8 @@ def splitGeometryCrossingPrimeMeridian(geometry):

parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument("-f", "--features_file", dest="features_file", help="File containing features to split at the antimeridian", metavar="FILE", required=True)
parser.add_argument("-o", "--output", dest="output_file_name", help="Output file, e.g., features.geojson.", metavar="PATH", default="features.geojson")


args = parser.parse_args()

Expand All @@ -84,17 +86,6 @@ def splitGeometryCrossingPrimeMeridian(geometry):
if(result is not None):
feature['geometry'] = result

out_file_name = "features.geojson"

out_file = open(out_file_name, 'w')

out_file.write('{"type": "FeatureCollection",\n')
out_file.write(' "groupName": "enterNameHere",\n')
out_file.write(' "features":\n')
out_file.write('\t[\n')
write_all_features(features_file, out_file, '\t\t')
out_file.write('\n')
out_file.write('\t]\n')
out_file.write('}\n')
write_all_features(features_file, args.output_file_name, indent=4)

# vim: foldmethod=marker ai ts=4 sts=4 et sw=4 ft=python
19 changes: 5 additions & 14 deletions merge_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
features.geojson if their tags property contains all of the tags listed on the
input line.

Authors: Douglas Jacobsen
Last Modified: 02/11/2016
Authors: Douglas Jacobsen, Xylar Asay-Davis
Last Modified: 9/29/2016
"""

import sys, os, glob, shutil, numpy, fnmatch
import json
import argparse
from collections import defaultdict
from utils.feature_write_utils import *
from utils.feature_test_utils import *
from utils.feature_write_utils import write_all_features
from utils.feature_test_utils import match_tag_list, feature_already_exists

parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument("-f", "--feature_file", dest="feature_file", help="Single feature file to append to features.geojson", metavar="FILE")
Expand Down Expand Up @@ -67,8 +67,6 @@
except:
new_file = True

out_file = open(file_to_append, 'w')

if args.feature_file:
try:
with open(args.feature_file) as f:
Expand Down Expand Up @@ -103,13 +101,6 @@
print "Error parsing geojson file: %s"%(path)
del paths

out_file.write('{"type": "FeatureCollection",\n')
out_file.write(' "groupName": "enterNameHere",\n')
out_file.write(' "features":\n')
out_file.write('\t[\n')
write_all_features(all_features, out_file, '\t\t')
out_file.write('\n')
out_file.write('\t]\n')
out_file.write('}\n')
write_all_features(all_features, file_to_append, indent=4)

# vim: foldmethod=marker ai ts=4 sts=4 et sw=4 ft=python
2 changes: 1 addition & 1 deletion plot_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
'southpole', 'atlantic', 'pacific', 'americas', 'asia'

Authors: Xylar Asay-Davis, Doug Jacobsen, Phillip J. Wolfram
Last Modified: 09/14/2016
Last Modified: 09/29/2016
"""

import os.path
Expand Down
13 changes: 2 additions & 11 deletions simplify_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
file pointed to with the -o flag (features.geojson by default).

Author: Xylar Asay-Davis
Last Modified: 4/4/2016
Last Modified: 9/29/2016
"""

import json
Expand Down Expand Up @@ -78,15 +78,6 @@
feature['geometry'] = shapely.geometry.mapping(simplifiedFeature)
features['features'].append(feature)


out_file = open(out_file_name, 'w')
out_file.write('{"type": "FeatureCollection",\n')
out_file.write(' "groupName": "enterNameHere",\n')
out_file.write(' "features":\n')
out_file.write('\t[\n')
write_all_features(features, out_file, '\t\t')
out_file.write('\n')
out_file.write('\t]\n')
out_file.write('}\n')
write_all_features(features, out_file_name, indent=4)

# vim: foldmethod=marker ai ts=4 sts=4 et sw=4 ft=python
17 changes: 5 additions & 12 deletions split_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
pointed to by the -f flag. It then writes each feature defition out to it's own
independent file in an autogenerated directory tree.

Authors: Douglas Jacobsen
Last Modified: 08/27/2015
Authors: Douglas Jacobsen, Xylar Asay-Davis
Last Modified: 9/29/2016

"""

import os
import json
import argparse
from utils.feature_write_utils import write_single_feature
from utils.feature_write_utils import write_all_features

parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument("-f", "--features_file", dest="features_file", help="File containing features to split up", metavar="FILE", required=True)
Expand All @@ -39,15 +39,8 @@
if not os.path.exists('%s/%s/%s'%(component, object_type, dir_name)):
os.makedirs('%s/%s/%s'%(component, object_type, dir_name))

out_file = open('%s/%s/%s/%s.geojson'%(component, object_type, dir_name, object_type), 'w')
out_file_name = '%s/%s/%s/%s.geojson'%(component, object_type, dir_name, object_type)

out_file.write('{"type": "FeatureCollection",\n')
out_file.write(' "features":\n')
out_file.write('\t[\n')
write_single_feature(feature, out_file, '\t\t')
out_file.write('\n')
out_file.write('\t]\n')
out_file.write('}\n')
out_file.close()
write_all_features({'features':[feature]}, out_file_name, indent=4)

# vim: foldmethod=marker ai ts=4 sts=4 et sw=4 ft=python
85 changes: 44 additions & 41 deletions tag_features.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#!/usr/bin/env python

"""
This script takes a file containing a collection of one or more feature
definitions, that is pointed to by the -f flag and a tag name pointed to by
the -t flag. The tag is added to each feature (if that feature does not
already have that tag. Results are written back to the same feature file.
This script takes a file containing a collection of one or more feature
definitions, that is pointed to by the -f flag and a tag name pointed to by
the -t flag. The tag is added to each feature (if that feature does not
already have that tag. Results are written to the file pointed to with
the -o flag (features.geojson by default).

Author: Xylar Asay-Davis
Last Modified: 2/11/2016
Last Modified: 9/29/2016
"""

import os.path
Expand All @@ -17,60 +18,62 @@
from utils.feature_write_utils import write_all_features


parser = argparse.ArgumentParser(description=__doc__,
parser = argparse.ArgumentParser(description=__doc__,
formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument("-f", "--feature_file", dest="feature_file",
parser.add_argument("-f", "--feature_file", dest="feature_file",
help="Features collection file to be tagged", metavar="FILE",
required=True)
parser.add_argument("-t", "--tag", dest="tag", help="Tag to add to all features",
parser.add_argument("-t", "--tag", dest="tag", help="Tag to add to all features",
metavar="TAG", required=True)
parser.add_argument("-r", "--remove", dest="remove", action='store_true',
help="Use this flag to signal removing a tag instead of adding")
parser.add_argument("-o", "--output", dest="output_file_name",
help="Output file, e.g., features.geojson.", metavar="PATH",
default="features.geojson")

args = parser.parse_args()


out_file_name = args.feature_file
out_file_name = args.output_file_name

all_features = defaultdict(list)

if os.path.exists(out_file_name):
with open(out_file_name) as f:
appended_file = json.load(f)
for feature in appended_file['features']:
try:
try:
with open(out_file_name) as f:
appended_file = json.load(f)
for feature in appended_file['features']:
all_features['features'].append(feature)
del appended_file
except:
pass

try:
filePointer = open(args.feature_file, 'r')
except IOError:
print "Error: file %s does not exist"%(args.feature_file)
raise

appended_file = json.load(filePointer)
for feature in appended_file['features']:
try:
feature_tags = feature['properties']['tags']
except:
except KeyError:
feature_tags = ''
feature_tag_list = feature_tags.split(';')
if args.remove:
feature_tag_list = feature_tags.split(';')
if args.remove:
if args.tag in feature_tag_list:
feature_tag_list.remove(args.tag)
if(len(feature_tag_list) == 0):
feature['properties']['tags'] = ''
else:
feature_tags = feature_tag_list[0]
for tag in feature_tag_list[1:len(feature_tag_list)]:
feature_tags = '%s;%s'%(feature_tags,tag)
feature['properties']['tags'] = feature_tags
else:
feature_tag_list.remove(args.tag)
feature['properties']['tags'] = ';'.join(feature_tag_list)
else:
if args.tag not in feature_tag_list:
if(feature_tags == ''):
feature['properties']['tags'] = args.tag
else:
feature['properties']['tags'] = '%s;%s'%(feature_tags,args.tag)

all_features['features'].append(feature)
del appended_file
if(feature_tags == ''):
feature['properties']['tags'] = args.tag
else:
feature['properties']['tags'] = '%s;%s'%(feature_tags,args.tag)

out_file = open(out_file_name, 'w')
all_features['features'].append(feature)

out_file.write('{"type": "FeatureCollection",\n')
out_file.write(' "groupName": "enterNameHere",\n')
out_file.write(' "features":\n')
out_file.write('\t[\n')
write_all_features(all_features, out_file, '\t\t')
out_file.write('\n')
out_file.write('\t]\n')
out_file.write('}\n')
write_all_features(all_features, out_file_name, indent=4)

# vim: foldmethod=marker ai ts=4 sts=4 et sw=4 ft=python
Loading