參考資料:html
1. 關於座標轉換計算: 在另外一篇文章中有參考資料 http://www.cnblogs.com/beautifulplanet/p/4309222.htmlpython
2. 如何用arcpy進行處理呢,先找到這個連接web
http://gis.stackexchange.com/questions/17096/edit-end-points-in-polyline-python-arcmap10,json
從def offsetFirstPointInLine(line_geom,X_distance,Y_distance)函數
中找到如何提取每一條線記錄的每一個點座標:函數
geom = r.getValue("SHAPE") array = geom.getPart(0)
那array 是什麼呢?測試
3. 上面那個例子只處理了每條線的一個點,而我須要對每一個點進行處理,那怎麼構成其中的new line呢?又去找ArcGIS的幫助,找到PolyLine類大數據
http://help.arcgis.com/zh-cn/arcgisdesktop/10.0/help/index.html#/na/000v000000n2000000/ui
看看其中polyline是如何由點組裝起來的。spa
解決方案:code
通過上面三步梳理,整理代碼以下
>>> import arcpy,math ... pi = 3.14159265358979324 ... a = 6378245.0 ... ee = 0.00669342162296594323 ... def transformLat(x,y): ... ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * math.sqrt(abs(x)) ... ret += (20.0 * math.sin(6.0 * x * pi) + 20.0 * math.sin(2.0 * x * pi)) * 2.0 / 3.0 ... ret += (20.0 * math.sin(y * pi) + 40.0 * math.sin(y / 3.0 * pi)) * 2.0 / 3.0 ... ret += (160.0 * math.sin(y / 12.0 * pi) + 320 * math.sin(y * pi / 30.0)) * 2.0 / 3.0 ... return ret ... def transformLon(x,y): ... ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * math.sqrt(abs(x)) ... ret += (20.0 * math.sin(6.0 * x * pi) + 20.0 * math.sin(2.0 * x * pi)) * 2.0 / 3.0 ... ret += (20.0 * math.sin(x * pi) + 40.0 * math.sin(x / 3.0 * pi)) * 2.0 / 3.0 ... ret += (150.0 * math.sin(x / 12.0 * pi) + 300.0 * math.sin(x / 30.0 * pi)) * 2.0 / 3.0 ... return ret ... def offsetPoint(wgLat,wgLon): ... dLat = transformLat(wgLon - 105.0, wgLat - 35.0) ... dLon = transformLon(wgLon - 105.0, wgLat - 35.0) ... radLat = wgLat / 180.0 * pi ... magic = math.sin(radLat) ... magic = 1 - ee * magic * magic ... sqrtMagic = math.sqrt(magic); ... dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi) ... dLon = (dLon * 180.0) / (a / sqrtMagic * math.cos(radLat) * pi) ... new_point = arcpy.Point(wgLon+dLon, wgLat+dLat) ... return new_point ... def offsetFirstPointInLine(line_geom): ... new_point = arcpy.Point() ... new_array = arcpy.Array() ... array = line_geom.getPart(0) ... for x in range(0,array.count): ... old_point = array[x] ... new_point = offsetPoint(old_point.Y,old_point.X) ... new_array.add(new_point) ... new_line = arcpy.Polyline(new_array,SR) ... new_array.removeAll() ... return new_line ... fc = r"E:\movedata-lonlat\guodao.shp" ... cur= arcpy.UpdateCursor(fc) ... SR= arcpy.Describe(fc).spatialReference ... print SR ... for r in cur: ... geom = r.getValue("SHAPE") ... r.setValue("SHAPE",offsetFirstPointInLine(geom)) ... cur.updateRow(r) ... del r,cur
將處理後的數據再進行Project : WGS 1984 Web Mercator.prj,與谷歌地圖進行疊加顯示位置一致。
有幾句代碼標紅,是遇到數據缺失的問題後修改的,過程以下:
遇到的問題:
可是...後來放大數據,才發現有缺失,如圖(紫色是原始數據,紅色是處理後獲得的數據)
new_array.add(new_point)
new_line = arcpy.Polyline(new_array)
打印new_array也是38個點,可是打印new_line.pointCount就只有3個點了。
從新分析測試數據(WGS-84 地理座標系/經緯度 下進行),啓用編輯狀態,原始的線要素上點比較密集
用 Arcpy Polyline lose points 去谷歌 搜到 http://stackoverflow.com/questions/14248618/shape-information-lost-when-using-arcpy-polyline-object-as-dictionary-value
好像是要添加座標系,另外又進行了實驗:
給這條線加上幾個點,其中有幾個點距離比較近:
再次處理,線變成了:
推測是否是在構成線的時候有什麼距離限制?
用ArcPy Polyline accuracy、 ArcPy Polyline tolerance 谷歌,搜到了http://gis.stackexchange.com/questions/86728/minimum-shapelength-using-arcpy-polyline
其中關鍵的一句 「 I recommend setting the Geometry's Spatial Reference before inputting the coordinates. The SR has its own XYTolerance and XYResolution」
所以對上面的程序進行修改,增長紅色部分。