【问题标题】:Create Map Polygons from Excel data in R从 R 中的 Excel 数据创建地图多边形
【发布时间】:2016-07-21 22:27:54
【问题描述】:

我有一个经纬度坐标列表,每个坐标都有相应的方位角(方向),例如:

    Site    | Cell        | Lat | Long | Azimuth (degrees) | Beamwidth
    CE0001  | CE0001U09A1 | X   | Y    |    0              |    65
    CE0001  | CE0001U09B1 | X   | Y    |    120            |    65
    CE0001  | CE0001U09C1 | X   | Y    |    240            |    65

对于每个唯一的单元格,我想创建一个三角形多边形,该三角形朝向相应单元格的方位角方向,宽度为 65 度,半径为 2 公里。我想生成类似于下图所示的形状。

谁能指出我如何开始编码以循环遍历文件中的每个条目以及如何生成一个包含每个条目的多边形的单个谷歌地球文件的方向?大约有 9000 个左右的单元需要一个多边形,但如果我能在一个小样本中使用它,我会非常高兴。

【问题讨论】:

  • 你正在制作的东西听起来真的很令人印象深刻!您能否解释一下您希望最终结果是什么样的?
  • 您还在为此寻找解决方案吗?我理解你是对的,你想要每个点三个多边形的结果?
  • 嗨@and,我想我用一些基本的三角法解决了这个问题,它非常粗略,但它有效。由于我有一个站点坐标、一个波束宽度、到边缘的距离以及我希望计算的点数,因此 geosphere 包中的 destPoint 函数非常有用。它计算沿多边形的端点,然后我可以将它们映射到传单中。如果您有更好的选择,我会很高兴听到的。
  • 不,我也会通过三角函数来解决这个问题......但我不太喜欢这个,所以它需要一些时间 - 我的想法是:创建一个圆圈(如果我有一个脚本或可以做到这一点的功能),然后根据角度将其切成 6 部分。

标签: excel leaflet rstudio google-earth


【解决方案1】:

这是我在论坛上发布的用于构建六边形瓷砖的脚本的旧帖子。有些调用是针对 GIS API,但我认为您可能可以提取所需的 VBA 代码:

        .. VB script to create some hexagon tiles.
        It creates tiles of a given radius (circle around a tile), not side length. If you want side length you will need to do the math and updte the code.
        Here is the Comments from the .map file:
        Creating a drawing of hexagon tiles:
        R - radius
        Radius of circumscribed circle around tile
        a - Apothem:
        Distance from centroid perpendicular to a side
        a = R * cos(1/2 * 360/n) (n=6 for a hexagon
        A set of hexagon tiles would be a series of six sided
        "circles" centered on two point grids (1 & 2). Both grids
        would have the spacing of:
        in X --- 3R
        in Y --- 2a
        Grid 2 would be offset from grid 1 by:
        in X ---- 3R/2
        in Y ---- 2a/2
        To test script delete all objects in A then
        run the script.
        This sample was only tested with a lat/long drawing. I'm not
        sure of all the ramifications of using a projected drawing.
        To use with your data set the start point (upper left) in the script and desired radius.
        Set precision and run Normailize Topology when done to join
        the tiles.
        Code was based on the FreeStuff sample scripts ScriptRandomPoints
        and ScriptSpatialOperations.
        Please post any problems you find with this code.
        Hmmm.. the attachments option is gone? :-?
        Send me your address via email and send the .map file if you'd like.
        Here's the code:
            Sub Main
            ' test lat/long drawing
            ' ** ** delete all objects in A to test
            set drawing = Application.ActiveDocument.ComponentSet("A")
            set objects = drawing.ObjectSet
            sides = 6
            pi = 3.14159
            R = 2.5 ' radius in degrees
            interiorAngle = (360/6) * (pi / 180) ' in radians
            a = abs(R * cos(0.5 * interiorAngle)) ' apothem
            ' pick/make a start point - upper left
            Set startPoint = Application.NewPoint
            startPoint.X = -25
            startPoint.Y = 73.6602540378444
            ' grid (4x3x2)
            for i = 0 to 3
            for j = 0 to 2
            ' -- create point grid 1
            Set point = Application.NewPoint
            point.X = startPoint.X + (i * 3 * R)
            point.Y = startPoint.Y - (j * 2 * a)
            ' objects.Add Application.NewGeom(GeomPoint, point) ' centroid
            Set pointSet = Application.NewPointSet
            For k = 0 To sides -1
            Set pt = Application.NewPoint
            ' calculate angle
            angle = (k*2*Pi/sides)' - (360/sides)/2
            ' obtain point on circle
            pt.X = point.X + R*Cos(angle)
            pt.Y = point.Y + R*Sin(angle)
            pointSet.Add(pt)
            Next
            objects.Add Application.NewGeom(GeomArea, pointSet)
            ' -- create point grid 2
            Set point = Application.NewPoint
            point.X = startPoint.X + (i * 3 * R) + ((3 * R)/2)
            point.Y = startPoint.Y - (j * 2 * a) - a
            ' objects.Add Application.NewGeom(GeomPoint, point) ' centroid
            Set pointSet = Application.NewPointSet
            For k = 0 To sides -1
            Set pt = Application.NewPoint
            ' calculate angle
            angle = (k*2*Pi/sides)' - (360/sides)/2
            ' obtain point on circle
            pt.X = point.X + R*Cos(angle)
            pt.Y = point.Y + R*Sin(angle)
            pointSet.Add(pt)
            Next
            objects.Add Application.NewGeom(GeomArea, pointSet)
            next
            next
            msgbox "Done!"
            End Sub

这是一个只开发一个十六进制图块的清理版本。你应该可以修改它来做你想做的事。

        Sub xx()
            Dim startPoint As clsPoint
            Dim Point As clsPoint
            Dim pt As clsPoint
            Dim pts As Collection
            Dim s As String

            '  lat/long (western hemisphere?)

            Dim sides, i, j, k As Integer
            Dim Pi, R, interiorAngle, A, Angle As Double

            sides = 6
            Pi = 3.14159
            R = 0.25 ' radius in degrees
            interiorAngle = (360 / 6) * (Pi / 180) ' in radians
            A = Abs(R * Cos(0.5 * interiorAngle)) ' apothem

            ' pick/make a start point - upper left
            Set startPoint = New clsPoint
            startPoint.X = -121.5
            startPoint.Y = 35.5
            s = "Longitude" & vbTab & "Latitude" & vbCrLf
            s = s & startPoint.X & vbTab & startPoint.Y & vbCrLf

            Set Point = New clsPoint
            Point.X = startPoint.X '+ (i * 3 * R)
            Point.Y = startPoint.Y '- (j * 2 * A)

            Set pts = New Collection
            For k = 0 To sides - 1
                Set pt = New clsPoint
                ' calculate angle
                Angle = (k * 2 * Pi / sides) ' - (360/sides)/2
        '        Debug.Print Angle
                ' obtain point on circle
                pt.X = Point.X + R * Cos(Angle)
                pt.Y = Point.Y + R * Sin(Angle)
                pts.Add pt
            Next

            For Each pt In pts
                 s = s & pt.X & vbTab & pt.Y & vbCrLf
            Next
            Debug.Print s
            Stop
        End Sub

clsPoint 只包含:

Public X As Double
Public Y As Double

【讨论】:

  • 感谢您的回复,您能否提供输出的图片,以便我可以看到它创建的内容?我需要一些时间来解码脚本。非常感谢。
  • 输出只有六个点和一个质心。上面的脚本只是打印即时窗口中的点。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-20
  • 2017-08-27
  • 2018-05-15
  • 2018-12-13
  • 1970-01-01
  • 2015-11-02
相关资源
最近更新 更多