コード例 #1
0
ファイル: bundle.py プロジェクト: nmb10/ambry10-bundles
  def parse_geoid(self, row):
      from geoid.census import County, Zcta, Place, Sldl, Sldu, Cdcurr, State
      from geoid.civick import GVid
    
      if row.geotype == 'ZCTA':
           return Zcta.parse(row.geoid.zfill(5)).convert(GVid)
           
      elif row.geotype == 'COUNTIES':
           return County.parse(row.geoid.zfill(5)).convert(GVid)
           
      elif row.geotype == 'CITIES':
           return Place.parse(row.geoid.zfill(7)).convert(GVid)
           
      elif row.geotype == 'CONGRESS':
           return Cdcurr.parse(row.geoid.zfill(4)).convert(GVid)
           
      elif row.geotype == 'SENATE':
           return Sldu.parse(row.geoid.replace('SS','').zfill(5)).convert(GVid)
           
      elif row.geotype == 'ASSEMBLY':
           return Sldl.parse(row.geoid.replace('SA','').zfill(5)).convert(GVid)
           
      elif row.geotype == 'STATE':
          return State.parse('06').convert(GVid)
           
 
      return None
コード例 #2
0
    def extract_geoid(self, v, row):
        
        from geoid.census import Place, County, State, Cosub, Tract, Zcta
        from geoid.civick import GVid
        from ambry.valuetype import FailedValue, GeoAcsVT
        
        CA_STATE = 6
    
        
        if row.geotype == 'PL':
            r = Place(CA_STATE, int(row.geotypevalue)).convert(GVid)
        elif row.geotype == 'CO':
            gt = row.geotypevalue
            assert int(gt[0:2]) == CA_STATE
            r = County(CA_STATE, int(gt[2:])).convert(GVid)
        elif row.geotype == 'CA' or row.geotype == 'ST':
            r = State(CA_STATE).convert(GVid)
        elif row.geotype == 'CD':
            r = Cosub.parse(row.geotypevalue).convert(GVid)

        elif row.geotype == 'CT':
            try:
                r = Tract.parse(row.geotypevalue).convert(GVid)
            except ValueError:
                r = Tract.parse('06'+row.geotypevalue).convert(GVid)
        elif row.geotype == 'ZC':
            r = Zcta.parse(row.geotypevalue).convert(GVid)
        elif row.geotype == 'NA': # Sub-state region, not a census area
            r = None
        elif row.geotype == 'RE': # Sub-state region, not a census area
            r = None
        elif row.geotype == 'R4': # Sub-state region, not a census area
            r = None
        elif row.geotype == 'MS': # Probably an MSA or similar
            r = None
        else:
            self.error("Unknown geotype {} in row {}".format(row.geotype, row))
            r = None
    
        if r is None:
            return None

        return GeoAcsVT(r)
コード例 #3
0
ファイル: bundle.py プロジェクト: CivicSpleen/health-reporter
    def extract_geoid(self, v, row):

        from geoid.census import Place, County, State, Cosub, Tract, Zcta
        from geoid.civick import GVid
        import ambry.valuetype

        CA_STATE = 6

        if row.geotype == 'PL':
            r = Place(CA_STATE, int(row.geotypevalue)).convert(GVid)
        elif row.geotype == 'CO':
            gt = row.geotypevalue
            assert int(gt[0:2]) == CA_STATE
            r = County(CA_STATE, int(gt[2:])).convert(GVid)
        elif row.geotype == 'CA' or row.geotype == 'ST':
            r = State(CA_STATE).convert(GVid)
        elif row.geotype == 'CD':
            r = Cosub.parse(row.geotypevalue).convert(GVid)

        elif row.geotype == 'CT':
            try:
                r = Tract.parse(row.geotypevalue).convert(GVid)
            except ValueError:
                r = Tract.parse('06' + row.geotypevalue).convert(GVid)
        elif row.geotype == 'ZC':
            r = Zcta.parse(row.geotypevalue).convert(GVid)
        elif row.geotype == 'NA':  # Sub-state region, not a census area
            r = None
        elif row.geotype == 'RE':  # Sub-state region, not a census area
            r = None
        elif row.geotype == 'R4':  # Sub-state region, not a census area
            r = None
        elif row.geotype == 'MS':  # Probably an MSA or similar
            r = None
        else:
            self.error("Unknown geotype {} in row {}".format(row.geotype, row))
            r = None

        if r is None:
            return ambry.valuetype.FailedValue(None)

        return ambry.valuetype.Geoid(r)