Esempio n. 1
0
def save_line(lines):
    print "=== 正在保存线 ==="
    print "[线数据] {}".format(lines)

    out_path = os.path.join(dir, line_name)
    gp = arcgisscripting.create()  # GP
    spat_ref = "4326"  # 坐标系
    gp.CreateFeatureClass_management(dir, line_name, "POLYLINE", "", "", "", spat_ref)

    line = lines[0]
    for key in line.keys():
        if key is "shape":
            continue
        gp.AddField_management(out_path, key, "TEXT", field_length=250)

    cur = gp.InsertCursor(out_path)
    newRow = cur.newRow()
    for feat in lines:
        for attr in feat:
            if attr == "shape":
                shape = feat["shape"]
                xs = shape["xs"].split(",")
                ys = shape["ys"].split(",")
                XYarray = gp.CreateObject("array")
                for i in range(0, len(xs) ):
                    point = gp.CreateObject("point")
                    point.X, point.Y = coordinate_conversion.gcj02towgs84(float(xs[i]), float(ys[i]) )
                    XYarray.add(point)
                newRow.setValue("Shape", XYarray)
            else:
                newRow.setValue(attr, feat[attr])
        cur.InsertRow(newRow)
    del cur, newRow
    pass
Esempio n. 2
0
def save_pois_shp(feats):
    """ 将feats保存成shp
    :param feats: {}
    :return:
    """
    print "[Done] %d" % len(feats)
    out_path = os.path.join(out_dir, out_name)
    gp = arcgisscripting.create() #GP
    spat_ref = "4326" #坐标系
    gp.CreateFeatureClass_management(out_dir, out_name, "POLYGON", "", "", "", spat_ref)

    gp.AddField_management(out_path, "name", "TEXT", field_length=250)
    gp.AddField_management(out_path, "type", "TEXT", field_length=250)

    cur = gp.InsertCursor(out_path)
    newRow = cur.newRow()
    for feat in feats:
        for attr in feat:
            if attr=="shape":
                # array = getXYArray(parkInfo["shape"])
                XYsStr = feat["shape"]
                XYarray = gp.CreateObject("array")
                XYList = XYsStr.split(';')
                for XYstr in XYList:
                    XY = XYstr.split(',')
                    XY[0], XY[1] = float(XY[0]), float(XY[1])
                    point = gp.CreateObject("point")
                    point.X, point.Y = coordinate_conversion.gcj02towgs84(XY[0], XY[1])
                    XYarray.add(point)
                newRow.setValue("Shape",XYarray)
            else:
                newRow.setValue(attr, feat[attr] )
        cur.InsertRow(newRow)
    del cur,newRow
Esempio n. 3
0
def save_pnt(pnts):
    print "=== 正在保存点 ==="
    print "[点数据] {}".format(pnts)

    # 创建shp
    print "[step] 创建点shp"
    gp = arcgisscripting.create()
    spat_ref = "4326"
    gp.CreateFeatureClass_management(dir, pnt_name, "POINT", "", "", "", spat_ref)
    out_path = os.path.join(dir, pnt_name)

    # 创建属性
    print "[step] 创建属性"
    pnt = pnts[0]
    fields = []
    for key in pnt:
        if key is "shp":
            continue
        gp.AddField_management(out_path, key, "TEXT", field_length=250)
        fields.append(key)
    print " {}".format(fields)


    # begin
    print "[step] 开始保存POIS"
    cur = gp.InsertCursor(out_path)
    newRow = cur.newRow()

    for feature in pnts:
        print "[保存] {}".format(feature)
        for attr_name in feature.keys():
            if attr_name == "shp":
                pnt = gp.CreateObject("point")
                XY = feature[attr_name].split(";")
                pnt.X, pnt.Y = coordinate_conversion.gcj02towgs84(float(XY[0]), float(XY[1]))
                print "\t[shp] {}".format(pnt)
                newRow.Shape = pnt
                continue
            if attr_name in fields:
                print "\t{} : {}".format(attr_name, feature[attr_name])
                try:
                    newRow.setValue(attr_name,
                                    feature[attr_name]
                                    )
                except:
                    newRow.setValue(attr_name, " ")
        cur.InsertRow(newRow)

    del cur, newRow
Esempio n. 4
0
 def getXYArray(XYsStr):
     """ 通过coordinates解析出XY的数组
     :param XYsStr: 格式"x,y;x,y;x,y..."
     :desc: 传入为gcj02坐标系坐标,返回wgs84坐标
     :return: arr: 类型arcpy.array
     """
     XYarray = arcpy.CreateObject("array")
     XYList = XYsStr.split(';')
     for XYstr in XYList:
         XY = XYstr.split(',')
         XY[0], XY[1] = float(XY[0]), float(XY[1])
         point = arcpy.CreateObject("point")
         point.X, point.Y = coordinate_conversion.gcj02towgs84(XY[0], XY[1])
         XYarray.add(point)
     return XYarray
Esempio n. 5
0
    def save_pnt(self, pois):
        print "=== 正在保存成shp文件(点) ==="
        # 创建shp
        print "[step] 创建shp"
        gp = arcgisscripting.create()
        spat_ref = "4326"
        gp.CreateFeatureClass_management(params["out_dir"], params["out_name"], "POINT", "", "", "", spat_ref)
        out_path = os.path.join(params["out_dir"], params["out_name"])

        # 创建属性
        print "[step] 创建属性"
        fields = []
        for field in params["save_field"]:
            fields.append(field[0])
            gp.AddField_management(out_path, field[0], field[1], field_length=field[2])

        # begin
        print "[step] 开始保存POIS"
        cur = gp.InsertCursor(out_path)
        newRow = cur.newRow()

        for feature in pois:
            print "[保存] {}".format(feature)
            for attr_name in feature.keys():
                if attr_name == "location":
                    pnt = gp.CreateObject("point")
                    XY = feature[attr_name].split(",")
                    pnt.X, pnt.Y = coordinate_conversion.gcj02towgs84(float(XY[0]), float(XY[1]))
                    print "\t[location] {}".format(pnt)
                    newRow.Shape = pnt
                    continue
                if attr_name in fields:
                    print "\t{} : {}".format(attr_name, feature[attr_name])
                    try:
                        newRow.setValue(attr_name,
                                        feature[attr_name]
                                        )
                    except:
                        newRow.setValue(attr_name, " ")
            cur.InsertRow(newRow)

        del cur, newRow
Esempio n. 6
0
    def save_line(self, pois_detail):
        """ 提取出shp属性
        :param pois_detail: list
        :return:
        """
        print "=== 正在保存成shp文件(线) ==="

        # 提取feature
        feats = []
        for index, poi_detail in enumerate(pois_detail):
            # 获得坐标串
            if "spec" not in poi_detail:
                if "base" in poi_detail and "name" in poi_detail["base"]:
                    print "[error] {} 没有坐标信息".format(poi_detail["base"]["name"])
                continue
            spec = poi_detail["spec"]
            have_shp = "没有"
            for key in spec:
                feat = {}
                if key == "mining_shape":  # 有shp
                    have_shp = "有"
                    feat["shape"] = spec[key]["shape"]  # 保存shp属性
                    feat["name"] = poi_detail["base"]["name"].encode("utf8")
                    feat["type"] = poi_detail["base"]["business"].encode("utf8")
                    feats.append(feat)

                    if len(feats) % 11 == 0:
                        print "已保存{}个信息".format( len(feats) )
                    break
            print "{} :{}".format( poi_detail["base"]["name"].encode("utf8"), have_shp)
        self.save_json(feats, params["out_dir"], "feats")

        out_path = os.path.join(params["out_dir"], params["out_name"])
        gp = arcgisscripting.create()  # GP
        spat_ref = "4326"  # 坐标系
        gp.CreateFeatureClass_management(params["out_dir"], params["out_name"], "POLYLINE", "", "", "", spat_ref)

        gp.AddField_management(out_path, "name", "TEXT", field_length=250)
        gp.AddField_management(out_path, "type", "TEXT", field_length=250)

        cur = gp.InsertCursor(out_path)
        newRow = cur.newRow()
        for feat in feats:
            for attr in feat:
                if attr == "shape":
                    # array = getXYArray(parkInfo["shape"])
                    XYsStr = feat["shape"]
                    XYarray = gp.CreateObject("array")
                    XYList = XYsStr.split(';')
                    for XYstr in XYList:
                        XY = XYstr.split(',')
                        XY[0], XY[1] = float(XY[0]), float(XY[1])
                        point = gp.CreateObject("point")
                        point.X, point.Y = coordinate_conversion.gcj02towgs84(XY[0], XY[1])
                        XYarray.add(point)
                    newRow.setValue("Shape", XYarray)
                else:
                    newRow.setValue(attr, feat[attr])
            cur.InsertRow(newRow)
        del cur, newRow
        pass
Esempio n. 7
0
if sys.getdefaultencoding() != defaultencoding:
    reload(sys)
    sys.setdefaultencoding(defaultencoding)

# 参数修改
out_dir = r"C:\Users\PasserQi\Desktop"
out_name = u"晋江市.shp"
shp_str = "118.586651;24.887213;118.589856;24.879356;118.593491;24.875708;118.599304;24.872889;118.605415;24.871446;118.624269;24.869941;118.636227;24.866015;118.643555;24.860675;118.645981;24.853015;118.651331;24.845679;118.672849;24.849566;118.683505;24.853791;118.687718;24.856569;118.691014;24.860458;118.694682;24.866351;118.695950;24.867216;118.698993;24.867843;118.702429;24.865521;118.701906;24.860221;118.698566;24.852632;118.699479;24.847657;118.705192;24.844329;118.717886;24.841981;118.729753;24.841322;118.732901;24.838998;118.734929;24.826089;118.730478;24.821229;118.721094;24.815886;118.662294;24.802783;118.654385;24.786973;118.634813;24.777266;118.633370;24.780991;118.631945;24.782315;118.626722;24.780853;118.626513;24.777269;118.630588;24.766748;118.630501;24.760373;118.629336;24.757815;118.624140;24.756222;118.620786;24.753992;118.611424;24.753472;118.601873;24.745861;118.590506;24.745574;118.589022;24.744357;118.590419;24.738893;118.587148;24.734097;118.584997;24.732579;118.584364;24.727241;118.585118;24.724764;118.594070;24.720963;118.597384;24.715788;118.598217;24.710946;118.607938;24.705602;118.614243;24.705638;118.618699;24.710424;118.627161;24.711369;118.629420;24.712478;118.636956;24.719601;118.646632;24.718483;118.649363;24.720204;118.653519;24.719240;118.654841;24.716864;118.654058;24.713976;118.654771;24.711012;118.656701;24.707392;118.662572;24.703136;118.661858;24.699239;118.659753;24.695504;118.659457;24.692357;118.661979;24.686969;118.662231;24.684593;118.670172;24.679759;118.671894;24.675294;118.677487;24.667206;118.687014;24.660570;118.694317;24.654833;118.699377;24.648414;118.696846;24.628668;118.689942;24.584811;118.670581;24.547085;118.606412;24.507367;118.565712;24.500086;118.527168;24.513751;118.486898;24.542900;118.467133;24.559559;118.463662;24.564981;118.444639;24.614950;118.439675;24.627817;118.438801;24.643452;118.448609;24.659979;118.448791;24.664517;118.446418;24.674074;118.446705;24.691943;118.449859;24.705397;118.448084;24.708736;118.446169;24.708721;118.444366;24.712447;118.445809;24.715681;118.443717;24.721596;118.440145;24.725632;118.438648;24.729647;118.435093;24.730647;118.437170;24.736516;118.437231;24.742043;118.434615;24.753379;118.432986;24.755409;118.426753;24.756416;118.424586;24.759202;118.427950;24.764948;118.433767;24.768907;118.433802;24.771921;118.431609;24.775570;118.427769;24.777823;118.420381;24.776585;118.414336;24.776898;118.412149;24.778426;118.411074;24.780699;118.414839;24.784620;118.425490;24.790356;118.430258;24.799103;118.436013;24.795953;118.437443;24.796188;118.441377;24.802283;118.442132;24.813739;118.441283;24.818974;118.441708;24.825343;118.437048;24.835288;118.442298;24.839163;118.440141;24.839870;118.436788;24.843957;118.437802;24.845896;118.437629;24.849291;118.439076;24.850142;118.441346;24.849188;118.443772;24.849774;118.444967;24.849479;118.447947;24.845168;118.452840;24.847323;118.458156;24.844471;118.460537;24.845787;118.461628;24.849809;118.467324;24.849775;118.471089;24.852175;118.477666;24.852824;118.479613;24.854082;118.481949;24.858032;118.488213;24.858919;118.488723;24.860474;118.488109;24.862494;118.480886;24.870891;118.478991;24.875961;118.478948;24.879302;118.482427;24.883961;118.482609;24.890224;118.485014;24.894003;118.483821;24.900109;118.484652;24.902581;118.494151;24.903732;118.498484;24.898901;118.498735;24.896760;118.502143;24.894579;118.503934;24.895435;118.504790;24.898209;118.505058;24.896756;118.509504;24.893287;118.515083;24.890659;118.518396;24.887982;118.522523;24.879981;118.524487;24.879354;118.530449;24.884382;118.533408;24.884942;118.540254;24.881551;118.541543;24.879434;118.541499;24.876131;118.537327;24.870327;118.537214;24.867560;118.549264;24.867025;118.551264;24.869404;118.552001;24.873515;118.561944;24.883271;118.569222;24.888781;118.578600;24.888129;118.585676;24.889032;118.586651;24.887213"

out_path = os.path.join(out_dir, out_name)
gp = arcgisscripting.create()  #GP
spat_ref = "4326"  #坐标系
gp.CreateFeatureClass_management(out_dir, out_name, "POLYGON", "", "", "",
                                 spat_ref)

cur = gp.InsertCursor(out_path)
newRow = cur.newRow()

XYsStr = shp_str
XYarray = gp.CreateObject("array")
XYList = XYsStr.split('_')
for XYstr in XYList:
    XY = XYstr.split(',')
    XY[0], XY[1] = float(XY[0]), float(XY[1])
    point = gp.CreateObject("point")
    point.X, point.Y = coordinate_conversion.gcj02towgs84(XY[0], XY[1])
    XYarray.add(point)
newRow.setValue("Shape", XYarray)

cur.InsertRow(newRow)
del cur, newRow
Esempio n. 8
0
        gp.AddField_management(out_path,
                               field[0],
                               field[1],
                               field_length=field[2])

    # begin
    print "[step] 开始保存POIS"
    cur = gp.InsertCursor(out_path)
    newRow = cur.newRow()

    for feature in infos:
        print "[保存] %s" % str(feature)

        pnt = gp.CreateObject("point")
        XY = (feature["x_gcj02"], feature["y_gcj02"])
        pnt.X, pnt.Y = coordinate_conversion.gcj02towgs84(
            float(XY[0]), float(XY[1]))
        print "\tlocation : {}".format(pnt)
        newRow.Shape = pnt

        for attr_name in feature.keys():
            if attr_name in fields:
                print "\t{} : {}".format(attr_name, feature[attr_name])
                try:
                    newRow.setValue(attr_name, feature[attr_name])
                except:
                    newRow.setValue(attr_name, " ")
        cur.InsertRow(newRow)

    del cur, newRow

    pass