forked from mysociety/mapit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support GeoJSON/KML for multiple areas (issue mysociety#136)
- Loading branch information
chris48s
committed
May 21, 2015
1 parent
1ac8818
commit 83e67bb
Showing
4 changed files
with
105 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# OutputFormatter | ||
# class for merging kml/geojson output | ||
|
||
from django.utils.html import escape | ||
|
||
|
||
class OutputFormatter: | ||
|
||
def __init__(self): | ||
self.kml_header =\ | ||
"""<?xml version="1.0" encoding="UTF-8"?> | ||
<kml xmlns="http://www.opengis.net/kml/2.2"> | ||
<Document> | ||
<Style id="ourPolygonStyle"> | ||
<LineStyle> | ||
<color>%s</color> | ||
<width>2</width> | ||
</LineStyle> | ||
<PolyStyle> | ||
<color>%s</color> | ||
</PolyStyle> | ||
</Style>""" | ||
self.kml_placemark =\ | ||
""" | ||
<Placemark> | ||
<styleUrl>#ourPolygonStyle</styleUrl> | ||
<name>%s</name> | ||
%s | ||
</Placemark>""" | ||
self.kml_footer =\ | ||
""" | ||
</Document> | ||
</kml>""" | ||
|
||
|
||
# [(kml, name)] -> kml | ||
def merge_kml(self, kml_arr, line_colour="70ff0000", fill_colour="3dff5500"): | ||
output = self.kml_header % (line_colour, fill_colour) | ||
for kml in kml_arr: | ||
output += self.kml_placemark % (escape(kml[1]), kml[0]) | ||
output += self.kml_footer | ||
return output | ||
|
||
# [(geojson, name)] -> geojson | ||
def merge_geojson(self, geojson_arr): | ||
output = '{ "type": "FeatureCollection", "features": [' | ||
for geojson in geojson_arr: | ||
output += '{ "properties": { "name": "%s" }, "type": "Feature", "geometry": %s },'\ | ||
% (escape(geojson[1]), geojson[0]) | ||
output = output[:-1] | ||
output += "] }" | ||
return output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters