- 积分
- 55950
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2011-6-21
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2012-10-3 14:15:22
|
显示全部楼层
haobang008 发表于 2012-10-3 09:44
这次真心麻烦你了,呵呵
写了一个脚本将你提供的coastline数据生成一个线图层,基本可以肯定coastline数据不适合做mask,线条很零碎(见下图中的彩色线,每条零碎的线用不同颜色显示),想要形成封闭的区域几乎不可能。不知道你为什么这么执着要用coastline数据?我之前说过,MeteoInfo带的110m-land.shp很适合做海陆mask,你如果愿意的话可以试试。
具体代码:
- #--------------------------------------------------------
- # Author: Yaqiang Wang
- # Date: 2012-10-3
- # Purpose: Read and plot coastline data
- # Note: Sample
- #-----------------------------------------------------------
- #---- Import clr and classes
- import clr
- clr.AddReferenceByPartialName("System")
- clr.AddReferenceByPartialName("System.Drawing")
- from System import *
- from System.Drawing import *
- from System.Collections.Generic import *
- clr.AddReference("MeteoInfoC.dll")
- from MeteoInfoC import *
- from MeteoInfoC.Data.MapData import *
- from MeteoInfoC.Geoprocess import *
- from MeteoInfoC.Layer import *
- from MeteoInfoC.Shape import *
- from MeteoInfoC.Legend import *
- from MeteoInfoC.Drawing import *
- import os.path
- #---- Create a line layer
- print 'Create polyline layer...'
- lLayer = VectorLayer(ShapeTypes.Polyline)
- lLayer.LayerName = "Coast_Line"
- lLayer.Visible = True
- lLayer.EditAddField("ID", String)
- #---- Read data file
- print 'Read data file...'
- fn = "D:\\Temp\\ascii\\data_1_bad.dat"
- tf = open(fn)
- plist = List[PointD]()
- tf.readline()
- i = 0
- for aline in tf:
- if aline.strip()[0:3] == 'nan':
- aPolyline = PolylineShape()
- aPolyline.Points = plist
- shapeNum = lLayer.ShapeNum
- if lLayer.EditInsertShape(aPolyline, shapeNum):
- lLayer.EditCellValue("ID", shapeNum, shapeNum)
- plist = List[PointD]()
- print "Line %i" % (shapeNum)
- else:
- datalist = aline.split()
- lat = float(datalist[1])
- lon = float(datalist[0])
- aPoint = PointD(lon, lat)
- plist.Add(aPoint)
-
- lLayer.UpdateLegendScheme(LegendType.SingleSymbol, "ID")
- mipy.MapDocument.ActiveMapFrame.AddLayer(lLayer)
- print 'Finished!'
复制代码
|
|