使用Arcgis生成含有多个多边形面的图层文件
背景:项目需要一个图层,图层上是两百个左右的不规则图形面(Polygon),每个图形(polygon)由128个点组成。希望将图层导出为shapefile的格式以便在geoServer发布,geoserver的发布流程见我的另一篇博客这里。
尝试:由于对Arcgis不熟悉,最初尝试将点坐标导入excel表格,再使用ArcGis的addData方式导入图层。但是发现,导入一个面可以,但是多个面的情况下无法一次性将多个坐标放在一个单元格属性里。当然可以使用python脚本遍历插入,但是没有采用。
操作:我使用了toolBox里的以Json导入的方式实现了方便快捷的一次性倒入所有的面。
1.首先编写代码将数据库里的点数据输出成指定的json文件。json的格式有如下要求:
{"displayFieldName":"",
"fieldAliases":{"FID":"FID","Name":"Name"},
"geometryType":"esriGeometryPolygon",
"spatialReference":{"wkid":4326,"latestWkid":4326},
"fields":[{"name":"FID","type":"esriFieldTypeOID","alias":"FID"},{"name":"Name","type":"esriFieldTypeString","alias":"Name","length":254}],"
features":[
{"attributes":{"FID":0,"Name":"北京/a"},"geometry":{"rings":[[[116.5116666670001,40.080000000000041],[116.51077796600009,40.088213782000025],[116.51123668200012,40.096448447000057],[116.51303611500009,40.104574083000045],[116.51614838900002,40.112462441000048],[116.52052486000002,40.11998896800003],[116.52609685400012,40.127034773000048],[116.53277672700005,40.133488515000067],[116.54045923500007,40.139248176000081],[116.54902318100005,40.144222676000027],[116.55833333300006,40.148333333000039],[116.52833333300009,40.22833333300008],[116.61333333300001,40.236666667000065],[116.61000000000001,40.153333333000035],[116.6202214330001,40.151306276000071],[116.63003867000009,40.148327451000057],[116.63930176600002,40.144442388000073],[116.64786931700007,40.13971046000006],[116.65561062800009,40.134203962000072],[116.66240771700006,40.12800700300005],[116.66815711300001,40.121214208000026],[116.67277143100011,40.113929264000035],[116.6761806830001,40.106263331000036],[116.67833333300007,40.098333333000028],[116.68500000000006,40.061666667000054],[116.68527756700007,40.053706564000038],[116.68429855500005,40.045779321000055],[116.68207785400011,40.038001627000028],[116.67864860500003,40.030487919000052],[116.67406167800004,40.02334871000005],[116.66838491100009,40.016688958000032],[116.66170208400001,40.010606542000062],[116.65411168100002,40.005190823000078],[116.64572543000008,40.000521344000049],[116.6366666670001,39.996666667000056],[116.66666666700007,39.916666667000072],[116.58166666700004,39.90833333300003],[116.58500000000004,39.991666667000061],[116.57479272500007,39.993690316000027],[116.5649869560001,39.99666581300005],[116.55573202900007,40.000547876000041],[116.54716896700006,40.00527741500008],[116.53942834000009,40.010782427000038],[116.53262828900006,40.016979076000041],[116.52687271900004,40.02377296800006],[116.52224970900011,40.031060573000047],[116.51883015400006,40.038730797000028],[116.5166666670001,40.046666667000068],[116.5116666670001,40.080000000000041]]]}},
{"attributes":{"FID":1,"Name":"北京/B"},"geometry":{"rings":[[[116.48666666700001,40.093333333000032],[116.48628232400006,40.101210841000068],[116.48713081400001,40.109066996000024],[116.48920035800006,40.116788410000026],[116.49246152800004,40.124263592000034],[116.49686764600006,40.131384567000055],[116.50235543500003,40.138048432000062],[116.50884591400006,40.144158858000026],[116.51624552900012,40.149627484000064],[116.52444749400001,40.154375207000044],[116.53333333300009,40.15833333300003],[116.50333333300011,40.243333333000066],[116.58833333300004,40.251666667000052],[116.58500000000004,40.163333333000026],[116.59522175900008,40.161305438000056],[116.60503918300003,40.158325984000044],[116.61430235300008,40.154440504000036],[116.62286989300003,40.149708364000048],[116.63061113200001,40.144201849000069],[116.63740811300011,40.13800505100005],[116.64315738900007,40.131212575000063],[116.64777159000005,40.123928082000077],[116.65118074700001,40.116262703000075],[116.65333333300009,40.108333333000076],[116.65500000000009,40.080000000000041],[116.65490324900009,40.072462181000049],[116.65368210600002,40.064982690000079],[116.65135308200001,40.05766017600007],[116.64794727500009,40.050591180000026],[116.6435099360001,40.043868864000046],[116.63809985800003,40.037581790000047],[116.63178858600008,40.031812757000068],[116.62465946900011,40.026637716000039],[116.61680655100008,40.022124781000059],[116.60833333300002,40.018333333000044],[116.63833333300011,39.935000000000059],[116.55333333300007,39.926666667000063],[116.55666666700006,40.010000000000048],[116.54667104100008,40.012547450000056],[116.53715853900007,40.016021289000037],[116.52827369200008,40.020368781000059],[116.52015158100005,40.025523920000069],[116.51291578700011,40.031408414000055],[116.50667652400011,40.037932870000077],[116.50152895300005,40.044998138000039],[116.49755172400012,40.052496814000051],[116.49480576600001,40.060314860000062],[116.49333333300001,40.068333333000055],[116.48666666700001,40.093333333000032]]]}}}
名词解释:
displayFieldName:当前shape的描述。
fieldAliases:shape文件的表格属性。
geometryType:shape里面类型。
spatialReference:坐标系 4326是1984。
fields:是表格里的列名以及列里面的数据类型。
features:数据的详细内容。
*基本上除了数据的内容头部坐标系和表的列可以微调,其他可以通用,直接拷贝。
2.导入之前,如果你的arcgis是10.5之前,需要将json文件的编码方式改为ansi,10.5及之后的版本可以直接导入utf-8的json了。使用arcgis的json方式导入,如果导入失败说明json格式有问题。如果导入成功,就离完成不远了。
3.最后将图层以shape的文件格式导出,结束。欢迎留言。
转载自:https://blog.csdn.net/u013821237/article/details/81015568