许可优化
许可优化
产品
产品
解决方案
解决方案
服务支持
服务支持
关于
关于
软件库
当前位置:服务支持 >  软件文章 >  将ArcGIS Server的EsriJSON转化为GDB文件(支持带弧的面和线)

将ArcGIS Server的EsriJSON转化为GDB文件(支持带弧的面和线)

阅读数 22
点赞 0
article_banner

将ArcGIS Server的EsriJSON转化为GDB文件,支持带弧的面和线

# -*- coding: utf-8 -*-# ---------------------------------------------------------------------------# JSONToGDB.py# Created on: 2022-02-12 17:00:00.00000# # Description:# ---------------------------------------------------------------------------  import osimport jsonimport arcpy  jsonFile='C:/data/queryData.txt'arcpy.env.workspace = "C:/data.gdb"outpath = "C:/data.gdb"outname = os.path.split(jsonFile)[1].split('.')[0]#arcpy.env.workspace = "C:/output"#outpath = "C:/output"#outname = os.path.split(jsonFile)[1].split('.')[0] + ".shp"arcpy.AddMessage(outname)fileObject = open(jsonFile, 'r')jsonText = fileObject.read()fileObject.close()featureSet = json.loads(jsonText)geometryType = featureSet["geometryType"] #geometry_type = "POINT"if geometryType == "esriGeometryPolygon":    geometry_type = "POLYGON"elif geometryType == "esriGeometryPolyline":    geometry_type = "POLYLINE"elif geometryType == "esriGeometryPoint":    geometry_type = "POINT"elif geometryType == "esriGeometryMultiPoint":    geometry_type = "MULTIPOINT"    # Execute CreateFeatureclassarcpy.CreateFeatureclass_management(outpath, outname, geometry_type)#featureShape = outpath + "/" + outnamefields = featureSet["fields"]fieldValid = [] #Original attribute namefieldValidLayer = ["SHAPE@"]  #New attribute namefor field in fields:    fieldName = field["name"]    fieldType = field["type"]    if fieldName.lower() != 'objectid' and fieldName.lower() != 'shape_length' and fieldName.lower() != 'shape.length' and fieldName.lower() != 'shape.len' and fieldName.lower() != 'shape_area' and fieldName.lower() != 'shape.area' and fieldName.lower() != 'fid':        fieldValid.append(fieldName)        if len(fieldName)>10:            fieldName = fieldName[0:9]        fieldValidLayer.append(fieldName)        if fieldType=="esriFieldTypeInteger":            arcpy.AddField_management(featureShape, fieldName, "LONG")        elif fieldType=="esriFieldTypeSmallInteger":            arcpy.AddField_management(featureShape, fieldName, "LONG")        elif fieldType=="esriFieldTypeDouble":            arcpy.AddField_management(featureShape, fieldName, "DOUBLE")        elif fieldType=="esriFieldTypeSingle":            arcpy.AddField_management(featureShape, fieldName, "DOUBLE")        else:            arcpy.AddField_management(featureShape, fieldName, "TEXT", field["length"])#features = featureSet["features"]cur = arcpy.da.InsertCursor(featureShape, fieldValidLayer)for feature in features:    attributes = feature["attributes"]    geometry = feature["geometry"]    valueList = []    geojson = {}    isEsriJson = False    if geometryType == "esriGeometryPolygon":        ringsName = "rings"        if 'rings' in geometry:            ringsName = "rings"            isEsriJson = False            rings = geometry[ringsName]            geojson = {                "type": "Polygon",                "coordinates": rings}        else:            ringsName = "curveRings"            isEsriJson = True            rings = geometry[ringsName]            geojson = {                "curveRings": rings,                "spatialReference": {"wkid": 0}}    elif geometryType == "esriGeometryPolyline":        pathsName = "paths"        if 'paths' in geometry:            pathsName = "paths"            isEsriJson = False            paths = geometry[pathsName]            geojson = {                "type": "MultiLineString",                "coordinates": paths}        else:            pathsName = "curvePaths"            isEsriJson = True            paths = geometry[pathsName]            geojson = {                "curvePaths": paths,                "spatialReference": {"wkid": 0}}    elif geometryType == "esriGeometryPoint":        geojson = {            "type": "Point",            "coordinates": [geometry["x"], geometry["y"]]}            polygon = arcpy.AsShape(geojson,isEsriJson)    valueList.append(polygon)  # (arcpy.Polygon(rings))            for field in fieldValid:        if attributes[field]!=None:            #arcpy.AddMessage(attributes[field])            valueList.append(attributes[field])        else:            valueList.append('')    cur.insertRow(valueList) del cur #print "finish !"arcpy.AddMessage("finish !")

如果生成带弧面或线时报return self._gp.FromEsriJson(json)  ValueError: Invalid geometry type   for method错误,如下图所示:

请用arcmap10.3及以上的版本即可 解决 ,这是arcmap10.3以下版本的Bug.

参考资料  :

将ArcGIS Server的JSON转化为SHP文件_weixin_30859423的博客-CSDN博客

Solved: Re: arcpy.Polygon Object and distanceTo() - Method... - Esri Community


免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删



相关文章
技术文档
QR Code
微信扫一扫,欢迎咨询~
customer

online

联系我们
武汉格发信息技术有限公司
湖北省武汉市经开区科技园西路6号103孵化器
电话:155-2731-8020 座机:027-59821821
邮件:tanzw@gofarlic.com
Copyright © 2023 Gofarsoft Co.,Ltd. 保留所有权利
遇到许可问题?该如何解决!?
评估许可证实际采购量? 
不清楚软件许可证使用数据? 
收到软件厂商律师函!?  
想要少购买点许可证,节省费用? 
收到软件厂商侵权通告!?  
有正版license,但许可证不够用,需要新购? 
联系方式 board-phone 155-2731-8020
close1
预留信息,一起解决您的问题
* 姓名:
* 手机:

* 公司名称:

姓名不为空

姓名不为空

姓名不为空
手机不正确

手机不正确

手机不正确
公司不为空

公司不为空

公司不为空