public String outputStr(Collection<City> lc) { StringBuilder sb = new StringBuilder(); int i = 0; for (City c : lc) { if ("polygon".equalsIgnoreCase(c.getGeometryType())) { if (outputACity(c, c.getGeometry(), i, sb)) i++; } else if ("multipolygon".equalsIgnoreCase(c.getGeometryType())) { String[] ss = ToADM.splitGeometry(c.getGeometry()); for (String s : ss) { if (outputACity(c, s, i, sb)) i++; } ss = null; } } return sb.toString(); }
/** * the city's geometryType must be polygon; * * @param c * @param i * @param sb */ public boolean outputACity(City c, String geometry, int i, StringBuilder sb) { if ("multipolygon".equalsIgnoreCase(geometry)) return false; sb.append("{"); ToADM.keyValueToSbWithComma(sb, BASEID, String.valueOf(i)); ToADM.keyValueToSbWithComma(sb, STATE_FP, ToADM.mkQuote(c.getStatefp())); ToADM.keyValueToSbWithComma(sb, PLACE_FP, ToADM.mkQuote(c.getPlacefp())); ToADM.keyValueToSbWithComma(sb, PLACE_NS, ToADM.mkQuote(c.getPlacens())); ToADM.keyValueToSbWithComma(sb, AFFGEOID, ToADM.mkQuote(c.getAffgeoid())); ToADM.keyValueToSbWithComma(sb, GEOID, ToADM.mkQuote(c.getGeoid())); ToADM.keyValueToSbWithComma(sb, NAME, ToADM.mkQuote(c.getName())); ToADM.keyValueToSbWithComma(sb, LSAD, ToADM.mkQuote(c.getLsad())); ToADM.keyValueToSbWithComma(sb, ALAND, ToADM.mkDoubleConstructor(c.getAland())); ToADM.keyValueToSbWithComma(sb, AWATER, ToADM.mkDoubleConstructor(c.getAwater())); ToADM.keyValueToSb(sb, GEOMETRY, ToADM.mkGeoConstructor(geometry, "polygon")); sb.append("}\n"); return true; }