# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# JSONToSHP.py
# Created on: 2014-09-01 22:00:00.00000
#
# Description:
# --------------------------------------------------------------------------- import os
import json
import arcpy jsonFile='E:/New Text Document.txt'
arcpy.env.workspace = "E:/output"
outpath = "E:/output"
outname = os.path.split(jsonFile)[1].split('.')[0] + ".shp"
print 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 CreateFeatureclass
arcpy.CreateFeatureclass_management(outpath, outname, geometry_type)
#
featureShape = outpath + "/" + outname
fields = featureSet["fields"]
fieldValid = [] #原属性名称
fieldValidLayer = ["SHAPE@"] #新属性名称
for field in fields:
fieldName = field["name"]
fieldType = field["type"]
if fieldName.lower() != 'objectid' and fieldName.lower() != 'shape_length' 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", 50)
#
features = featureSet["features"]
cur = arcpy.da.InsertCursor(featureShape, fieldValidLayer)
for feature in features:
attributes = feature["attributes"]
geometry = feature["geometry"]
valueList = []
geojson = {}
if geometryType == "esriGeometryPolygon":
rings = geometry["rings"]
geojson = {
"type": "Polygon",
"coordinates": rings}
elif geometryType == "esriGeometryPolyline":
paths = geometry["paths"]
geojson = {
"type": "MultiLineString",
"coordinates": paths}
elif geometryType == "esriGeometryPoint":
geojson = {
"type": "Point",
"coordinates": [geometry["x"], geometry["y"]]} polygon = arcpy.AsShape(geojson)
valueList.append(polygon) # (arcpy.Polygon(rings)) for field in fieldValid:
valueList.append(attributes[field])
cur.insertRow(valueList) del cur print "finish !"

将ArcGIS Server的JSON转化为SHP文件的更多相关文章

  1. ArcGIS学习记录—KMZ KML与SHP文件互相转换

      1.在google earth中绘制边界  工具栏中选择"Add Polygon".随意绘制一个多边形.  右击添加的图层名(左侧)保存位置为,选择保存为kmz或kml文件.  ...

  2. ArcGIS 相同要素类的多Shp文件或多要素合并

  3. 【教程】发布NAServer到ArcGIS Server 10.4上[超详细]

    前阵子对ArcGIS API For JavaScript的网络分析有兴趣,但是不知道其数据是如何获取的. 查阅API知道,AJS的网络分析只有三个功能:最短路径(RouteTask).最近设施点(C ...

  4. ArcGIS Server的安装

    1.双击ArcGIS Server安装目录下的Setup.exe. 2.点击“Next”. 3.选择“I accept the license agreement”,点击“Next”. 4.点击“Ch ...

  5. ArcGIS Server 10.2 实战(一)Asp.net MVC与JSON数据妙用实现动态生成要素图层

    今年7月刚刚发布的ArcGIS 10.2为GIS的web开发带来了一个很实在的功能,JSON转要素.以往GIS图层外部数据(如文本数据,数据库数据)动态地写入地图服务中的图层是一件不可想象的事情,如今 ...

  6. ArcGIS Server,rest路径输入要素json 格式描述

    以下内容只测试了简单线, 在ArcGIS Server 的rest路径下可以对服务进行操作,如Query等,这些操作可以输入json 格式要素描述或运行得到即输出json格式要素描述. 如博客:htt ...

  7. DWG/DGN格式导入Arcgis;转化为shp格式;更改地理坐标;导入Google Earth【转】

      其实本来,我就是需要把一个autocad的dwg/dgn格式的东西导入到google earth里面:但是首先我对dwg/dgn格式的东西根本就不熟:其次我拿到的dwg/dgn格式文件是用的HK8 ...

  8. ArcGIS Server导出shp文件

    需求: 在项目中客户提出需要在Web端能够定义条件将后台的数据导出shp文件,并下载. 实现: 基于ArcGIS开发导出矢量数据的服务,用户输入导出数据类型.过滤条件.导出范围等条件,服务能够快速将相 ...

  9. arcgis server 10.1 发布动态图层展示海量及频繁更新的数据步骤

    Arcgis server  发布动态图层及调用动态图层 做这个动态图层功能的原由是 有一个30万的数据需要通过arcgis GP工具转成shp然后渲染加载进地图,原来的做法是遍历生成shp面要素,读 ...

随机推荐

  1. error: failed to push some refs to 'https://github.com/username/python.git'

    解决error: failed to push some refs to 'https://github.com/bluepen/python.git' 当我们在使用git工具上传我们自己的代码时,可 ...

  2. MySQL密码修改(四)

    一.修改破解MySQL密码 1.1:修改密码 在知道原始密码的情况下 [root@web1 ~]# mysqladmin -uroot -p -S /home/mysql/3307/mysql.soc ...

  3. POJ 1045

    #include<iostream> #include<cmath> #include<iomanip> using namespace std; int main ...

  4. 杂记---Mongo的Invalid BSON field name $gte

    1.前言 这几天使用mongo的时候遇到了一个异常:Invalid BSON field name $gte,该问题可能会有很多小伙伴会遇到,因此记录一下解决过程.起因是用JAVA翻译一个其他语言写的 ...

  5. MyEclipse:详细使用教程

    http://www.56.com/u18/v_MTQwNzY1MTU5.html?fromvsogou=1

  6. 从一个例子学习 instanceof 和 getclass 的区别

    判断两个对象是否为同一类型,时常用到getclass 和 instanceof ,而这两个函数又是时常让人混淆.下面从一个例子说明两者的区别: public class Test_drive { pu ...

  7. 【数组】Minimum Size Subarray Sum

    题目: Given an array of n positive integers and a positive integer s, find the minimal length of a sub ...

  8. 【数组】Spiral Matrix II

    题目: Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. ...

  9. 【转】JVM参数设置、分析

    原文地址:http://www.cnblogs.com/redcreen/archive/2011/05/04/2037057.html 不管是YGC还是Full GC,GC过程中都会对导致程序运行中 ...

  10. manjaro i3 sound soft

    sudo pacman -S pavucontrol sudo pacman -S pulseaudio # 为了启动 fcitx 输入法…… #exec --no-startup-id LANG=& ...