1- from utilities import listFields , getShp , getOID , statusMessage , parseProp , makeInter
1+ from utilities import listFields , getShp , getOID , statusMessage , parseProp , makeInter , getName
22from arcpy import SpatialReference , SearchCursor
33from parseGeometry import getParseFunc
44from json import dump
77wgs84 = "GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]];-400 -400 1000000000;-100000 10000;-100000 10000;8.98315284119522E-09;0.001;0.001;IsHighPrecision"
88
99class parse :
10- def __init__ (self ,outFile ,featureClass ,fileType ,includeGeometry , first = True ):
10+ def __init__ (self ,outFile ,featureClass ,fileType ,includeGeometry , first = True , outName = False ):
1111 self .outFile = outFile
1212 self .fileType = fileType
1313 #first we set put the local variables we'll need
@@ -33,6 +33,13 @@ def __init__(self,outFile,featureClass,fileType,includeGeometry, first=True):
3333 self .parse = self .parseJSON
3434 elif fileType == "sqlite" :
3535 self .parse = self .parseSqlite
36+ elif fileType == "topojson" :
37+ self .parse = self .parseTOPOJSON
38+ if outName :
39+ self .oName = outName
40+ else :
41+ self .oName = getName (featureClass )
42+ self .topo = self .outFile ['topo' ].object_factory (self .oName )
3643
3744 def cleanUp (self ,row ):
3845 del row
@@ -48,6 +55,9 @@ def parseCSV(self,row):
4855 fc ["geometry" ]= self .parseGeo (row .getValue (self .shp ))
4956 except :
5057 return
58+ for key in fc :
59+ if isinstance (fc [key ],unicode ):
60+ fc [key ] = fc [key ].encode ('utf_8' )
5161 self .outFile [0 ].writerow (fc )
5262
5363 def parseGeoJSON (self ,row ):
@@ -73,6 +83,23 @@ def parseGeoJSON(self,row):
7383 self .outFile .write ("," )
7484 dump (fc ,self .outFile )
7585
86+ def parseTOPOJSON (self ,row ):
87+ #more messages
88+ self .status .update ()
89+ fc = {"type" : "Feature" }
90+ if self .parseGeo :
91+ try :
92+ fc ["geometry" ]= self .parseGeo (row .getValue (self .shp ))
93+ except :
94+ return
95+ else :
96+ raise NameError ("we need geometry for topojson" )
97+ fc ["id" ]= row .getValue (self .oid )
98+ fc ["properties" ]= parseProp (row ,self .fields , self .shp )
99+ if fc ["geometry" ]== {}:
100+ return
101+ self .topo (fc )
102+
76103 def parseJSON (self ,row ):
77104 #more messages
78105 self .status .update ()
0 commit comments