<s> from csv import DictWriter <EOL> from utilities import listFields , getShp , parseFieldType <EOL> from sqlite3 import Connection <EOL> from os . path import splitext , split <EOL> from topojson import Topology <EOL> def prepareCSV ( outJSON , featureClass , fileType , includeGeometry ) : <EOL> shp = getShp ( featureClass ) [ <NUM_LIT:0> ] <EOL> fields = listFields ( featureClass ) <EOL> fieldNames = [ ] <EOL> out = open ( outJSON , "<STR_LIT:wb>" ) <EOL> for field in fields : <EOL> if ( fields [ field ] != u'<STR_LIT>' ) and field . lower ( ) != shp . lower ( ) : <EOL> fieldNames . append ( field ) <EOL> if includeGeometry != "<STR_LIT:none>" : <EOL> fieldNames . append ( "<STR_LIT>" ) <EOL> outCSV = DictWriter ( out , fieldNames , extrasaction = '<STR_LIT:ignore>' ) <EOL> fieldObject = { } <EOL> for fieldName in fieldNames : <EOL> fieldObject [ fieldName ] = fieldName <EOL> outCSV . writerow ( fieldObject ) <EOL> return [ outCSV , out ] <EOL> def prepareSqlite ( out , featureClass , fileType , includeGeometry ) : <EOL> [ shp , shpType ] = getShp ( featureClass ) <EOL> if shpType == "<STR_LIT>" : <EOL> gType = <NUM_LIT:1> <EOL> elif shpType == "<STR_LIT>" : <EOL> gType = <NUM_LIT:4> <EOL> elif shpType == "<STR_LIT>" : <EOL> gType = <NUM_LIT:5> <EOL> elif shpType == "<STR_LIT>" : <EOL> gType = <NUM_LIT:6> <EOL> fields = listFields ( featureClass ) <EOL> fieldNames = [ ] <EOL> fieldNames . append ( "<STR_LIT>" ) <EOL> if includeGeometry : <EOL> fieldNames . append ( "<STR_LIT>" ) <EOL> for field in fields : <EOL> if ( fields [ field ] != u'<STR_LIT>' ) and field . lower ( ) != shp . lower ( ) : <EOL> fieldNames . append ( parseFieldType ( field , fields [ field ] ) ) <EOL> conn = Connection ( out ) <EOL> c = conn . cursor ( ) <EOL> name = splitext ( split ( out ) [ <NUM_LIT:1> ] ) [ <NUM_LIT:0> ] <EOL> c . execute ( """<STR_LIT>""" ) <EOL> c . execute ( """<STR_LIT>""" , ( name , "<STR_LIT>" , gType , <NUM_LIT:2> , <NUM_LIT> , "<STR_LIT>" ) ) <EOL> c . execute ( """<STR_LIT>""" ) <EOL> c . execute ( "<STR_LIT>" , ( <NUM_LIT> , u'<STR_LIT>' , <NUM_LIT> , u'<STR_LIT>' ) ) <EOL> c . execute ( "<STR_LIT>" . format ( name , "<STR_LIT:U+002CU+0020>" . join ( fieldNames ) ) ) <EOL> return [ name , c , conn ] <EOL> def prepareGeoJSON ( outJSON , * args ) : <EOL> out = open ( outJSON , "<STR_LIT:wb>" ) <EOL> out . write ( """<STR_LIT>""" ) <EOL> return out <EOL> def prepareJSON ( outJSON , * args ) : <EOL> out = open ( outJSON , "<STR_LIT:wb>" ) <EOL> out . write ( """<STR_LIT>""" ) <EOL> return out <EOL> def prepareTOPO ( outJSON , * args ) : <EOL> topo = Topology ( ) <EOL> return { "<STR_LIT>" : topo , '<STR_LIT>' : outJSON } <EOL> def prepareFile ( outJSON , featureClass , fileType , includeGeometry ) : <EOL> if fileType == "<STR_LIT>" : <EOL> return prepareGeoJSON ( outJSON , featureClass , fileType , includeGeometry ) <EOL> elif fileType == "<STR_LIT>" : <EOL> return prepareCSV ( outJSON , featureClass , fileType , includeGeometry ) <EOL> elif fileType == "<STR_LIT>" : <EOL> return prepareJSON ( outJSON , featureClass , fileType , includeGeometry ) <EOL> elif fileType == "<STR_LIT>" : <EOL> return prepareSqlite ( outJSON , featureClass , fileType , includeGeometry ) <EOL> elif fileType == "<STR_LIT>" : <EOL> return prepareTOPO ( outJSON , featureClass , fileType , includeGeometry ) <EOL> else : <EOL> return False </s>
