Kml To Wkt Converter
Latitude, Longitude, Name, Description, and Icon are all that are necessary for a professional looking presentation. Advanced options allow you to elevate the icon above the earth's surface, draw a path ('connect the dots'), and control mouse-over effects. Excel To KML ignores any additional columns in your spreadsheet.
PermalinkJoin GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
On hax reloader. Even the operating systems are not available for free like windows.
Sign upBranch:master
Find file Copy path
Fetching contributors…
#Author: Jose Antonio Ciccio C. |
#Script intended to handle and convert wkt multipolygons into kml multipolygons |
#File input format: |
#Poloygon name -8-AL-PB94457 0100007 010000600303 NAME P 1.13.4 2 MULTIPOLYGON (((-86.716765469999984 34.670241110000063, ..) |
#Expecting to have a name at field 4 and to process a multypolygon |
#!/usr/bin/env python |
importsys |
importre |
importsimplekml |
importargparse |
importrandom |
importos |
importpdb |
importcopy |
defcreateKMLPolygon(lines): |
kml=simplekml.Kml() |
foridx,linenumerate(lines): |
splitted=re.findall(r'[^ ,]+', l) |
spl= [float(i) foriinsplitted] |
coords=zip(splitted[::2],splitted[1::2]) |
pol=kml.newpolygon(name='Polygon '+str(idx) ) |
pol.outerboundaryis=coords |
pol.style.polystyle.color=simplekml.Color.red |
returnkml |
defsplitArrayByPolygons(array): |
splittedArray= [] |
foriteminarray: |
splittedArray.append(splitByPolygons(item)) |
returnsplittedArray |
defsplitByPolygons(wkt): |
returnre.findall(r'(?((([^)]*)', wkt) |
defreadFile(filename): |
array= [] |
withopen(filename, 'r') asins: |
forlineinins: |
array.append(line) |
defcreateDirectory (name): |
ifnotos.path.exists(name): |
os.makedirs(name) |
defwriteFile(filename, data): |
fo=open(filename, 'wb') |
fo.write(data); |
defmain(): |
# Argument Parser |
print'Going to split wkt into files to be processed' |
parser=argparse.ArgumentParser(description='Converter of WKT's linestrings to KML') |
parser.add_argument('infile', nargs='?', type=argparse.FileType('r'),default=sys.stdin) |
args=parser.parse_args() |
content=args.infile.read().splitlines() |
lineNumber=1 |
extension='.wkt' |
kmlExtension='.kml' |
wktDirectory='wkt_splitted/' |
kmlDirectory='kml_splitted/' |
kmlDirectoryGrouped='kml_grouped/' |
content_data= {} |
#directory creation for outputs |
createDirectory(wktDirectory) |
createDirectory(kmlDirectory) |
createDirectory(kmlDirectoryGrouped) |
#processing and generating a single file per each entry |
foritemincontent: |
parts=item.split(' ') |
print'Processing line %s with name %s'% (lineNumber , parts[3]) |
filename=parts[3].replace(' ', '_').lower() |
forpartinparts: |
#print '%s n' %part |
if'MULTIPOLYGON'inpart: |
file='%s%d%s'%(filename, lineNumber, extension) |
kmlFile='%s%d%s'%(filename, lineNumber, kmlExtension) |
ifnotfilenameincontent_data: |
content_data[filename] = [] |
content_data[filename].append(part) |
print'Creating wkt file called: %s'% (file) |
writeFile(wktDirectory+file, part) |
print'Creating kml file called: %s'% (kmlFile) |
cleanInput=splitByPolygons(part) |
kmlUnit=createKMLPolygon(cleanInput) |
writeFile(kmlDirectory+kmlFile, kmlUnit.kml()) |
lineNumber=lineNumber+1 |
#grouping files per location name |
forkey, groupincontent_data.iteritems(): |
group=list(set(group)) |
print'Processing group %s'%key |
kmlGroupFile='%s%s'%(key, kmlExtension) |
print'Creating kml file called: %s'% (kmlGroupFile) |
cleanInput=splitArrayByPolygons(group) |
#we can proceed and create a kml with the consolidated school data |
flattenList=sum(cleanInput,[]) #converts array of arrays into a single array |
kmlUnit=createKMLPolygon(flattenList) |
writeFile(kmlDirectoryGrouped+kmlGroupFile, kmlUnit.kml()) |
if__name__'__main__': |
main() |
Copy lines Copy permalink
- четверг 23 января
- 71